blob: cf6af123b33496cc964c79807b5d68ccea2ffcc0 [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 (
Neha Sharma96b7bf22020-06-15 10:37:32 +000021 "context"
Abhilash S.L765ad002019-04-24 16:40:57 +053022 "fmt"
Neha Sharma96b7bf22020-06-15 10:37:32 +000023 "strconv"
Shrey Baid26912972020-04-16 21:02:31 +053024 "sync"
25 "time"
26
Girish Gowdraa09aeab2020-09-14 16:30:52 -070027 "github.com/opencord/voltha-lib-go/v4/pkg/log"
Thomas Lee S94109f12020-03-03 16:39:29 +053028 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070029 "github.com/opencord/voltha-protos/v4/go/openolt"
30 "github.com/opencord/voltha-protos/v4/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
Neha Sharma96b7bf22020-06-15 10:37:32 +0000193func NewOpenOltStatsMgr(ctx context.Context, Dev *DeviceHandler) *OpenOltStatisticsMgr {
Abhilash S.L765ad002019-04-24 16:40:57 +0530194
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{}
Neha Sharma96b7bf22020-06-15 10:37:32 +0000202 Ports, _ = InitPorts(ctx, "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()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000205 Ports, _ = InitPorts(ctx, "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
Neha Sharma96b7bf22020-06-15 10:37:32 +0000211func InitPorts(ctx context.Context, 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++ {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000227 Port := BuildPortObject(ctx, 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++ {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000234 PONPort := BuildPortObject(ctx, 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 {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000239 logger.Errorw(ctx, "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
Neha Sharma96b7bf22020-06-15 10:37:32 +0000245func BuildPortObject(ctx context.Context, PortNum uint32, IntfType string, DeviceID string) interface{} {
Abhilash S.L765ad002019-04-24 16:40:57 +0530246 /*
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)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000260 logger.Debugw(ctx, "interface-type-nni",
Shrey Baid26912972020-04-16 21:02:31 +0530261 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)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000270 logger.Debugw(ctx, "interface-type-pon",
Shrey Baid26912972020-04-16 21:02:31 +0530271 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 {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000276 logger.Errorw(ctx, "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()
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000288 metricNames := StatMgr.Device.metrics.GetSubscriberMetrics()
Naga Manjunath7615e552019-10-11 22:35:47 +0530289
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000290 var metrics []string
Kent Hagermane6ff1012020-07-14 15:07:53 -0400291 for metric := range metricNames {
292 if metricNames[metric].Enabled {
293 metrics = append(metrics, metric)
Naga Manjunath7615e552019-10-11 22:35:47 +0530294 }
295 }
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000296
297 for _, mName := range metrics {
298 switch mName {
299 case "rx_bytes":
300 nnival["RxBytes"] = float32(cm.RxBytes)
301 case "rx_packets":
302 nnival["RxPackets"] = float32(cm.RxPackets)
303 case "rx_ucast_packets":
304 nnival["RxUcastPackets"] = float32(cm.RxUcastPackets)
305 case "rx_mcast_packets":
306 nnival["RxMcastPackets"] = float32(cm.RxMcastPackets)
307 case "rx_bcast_packets":
308 nnival["RxBcastPackets"] = float32(cm.RxBcastPackets)
309 case "tx_bytes":
310 nnival["TxBytes"] = float32(cm.TxBytes)
311 case "tx_packets":
312 nnival["TxPackets"] = float32(cm.TxPackets)
313 case "tx_mcast_packets":
314 nnival["TxMcastPackets"] = float32(cm.TxMcastPackets)
315 case "tx_bcast_packets":
316 nnival["TxBcastPackets"] = float32(cm.TxBcastPackets)
317 }
318 }
Naga Manjunath7615e552019-10-11 22:35:47 +0530319 return nnival
320}
321
322// collectPONMetrics will collect the pon port metrics
323func (StatMgr *OpenOltStatisticsMgr) collectPONMetrics(pID uint32) map[string]float32 {
324
325 ponval := make(map[string]float32)
326 mutex.Lock()
327 cm := StatMgr.Device.portStats.SouthBoundPort[pID]
328 mutex.Unlock()
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000329 metricNames := StatMgr.Device.metrics.GetSubscriberMetrics()
Naga Manjunath7615e552019-10-11 22:35:47 +0530330
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000331 var metrics []string
Kent Hagermane6ff1012020-07-14 15:07:53 -0400332 for metric := range metricNames {
333 if metricNames[metric].Enabled {
334 metrics = append(metrics, metric)
Naga Manjunath7615e552019-10-11 22:35:47 +0530335 }
336 }
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000337
338 for _, mName := range metrics {
339 switch mName {
340 case "rx_bytes":
341 ponval["RxBytes"] = float32(cm.RxBytes)
342 case "rx_packets":
343 ponval["RxPackets"] = float32(cm.RxPackets)
344 case "rx_ucast_packets":
345 ponval["RxUcastPackets"] = float32(cm.RxUcastPackets)
346 case "rx_mcast_packets":
347 ponval["RxMcastPackets"] = float32(cm.RxMcastPackets)
348 case "rx_bcast_packets":
349 ponval["RxBcastPackets"] = float32(cm.RxBcastPackets)
350 case "tx_bytes":
351 ponval["TxBytes"] = float32(cm.TxBytes)
352 case "tx_packets":
353 ponval["TxPackets"] = float32(cm.TxPackets)
354 case "tx_mcast_packets":
355 ponval["TxMcastPackets"] = float32(cm.TxMcastPackets)
356 case "tx_bcast_packets":
357 ponval["TxBcastPackets"] = float32(cm.TxBcastPackets)
358 }
359 }
360
Naga Manjunath7615e552019-10-11 22:35:47 +0530361 return ponval
362}
363
364// publishMatrics will publish the pon port metrics
Neha Sharma96b7bf22020-06-15 10:37:32 +0000365func (StatMgr OpenOltStatisticsMgr) publishMetrics(ctx context.Context, val map[string]float32,
Girish Gowdra34815db2020-05-11 17:18:04 -0700366 port *voltha.Port, devID string, devType string) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000367 logger.Debugw(ctx, "publish-metrics",
Shrey Baid26912972020-04-16 21:02:31 +0530368 log.Fields{
369 "port": port.Label,
370 "metrics": val})
Naga Manjunath7615e552019-10-11 22:35:47 +0530371
372 var metricInfo voltha.MetricInformation
373 var ke voltha.KpiEvent2
Esin Karamanccb714b2019-11-29 15:02:06 +0000374 var volthaEventSubCatgry voltha.EventSubCategory_Types
Girish Gowdra34815db2020-05-11 17:18:04 -0700375 metricsContext := make(map[string]string)
376 metricsContext["oltid"] = devID
377 metricsContext["devicetype"] = devType
378 metricsContext["portlabel"] = port.Label
379 metricsContext["portno"] = strconv.Itoa(int(port.PortNo))
Naga Manjunath7615e552019-10-11 22:35:47 +0530380
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530381 if port.Type == voltha.Port_ETHERNET_NNI {
Naga Manjunath7615e552019-10-11 22:35:47 +0530382 volthaEventSubCatgry = voltha.EventSubCategory_NNI
383 } else {
384 volthaEventSubCatgry = voltha.EventSubCategory_PON
385 }
386
387 raisedTs := time.Now().UnixNano()
388 mmd := voltha.MetricMetaData{
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530389 Title: port.Type.String(),
Naga Manjunath7615e552019-10-11 22:35:47 +0530390 Ts: float64(raisedTs),
Girish Gowdra34815db2020-05-11 17:18:04 -0700391 Context: metricsContext,
Naga Manjunath7615e552019-10-11 22:35:47 +0530392 DeviceId: devID,
393 }
394
395 metricInfo.Metadata = &mmd
396 metricInfo.Metrics = val
397
398 ke.SliceData = []*voltha.MetricInformation{&metricInfo}
399 ke.Type = voltha.KpiEventType_slice
400 ke.Ts = float64(time.Now().UnixNano())
401
Neha Sharma96b7bf22020-06-15 10:37:32 +0000402 if err := StatMgr.Device.EventProxy.SendKpiEvent(ctx, "STATS_EVENT", &ke, voltha.EventCategory_EQUIPMENT, volthaEventSubCatgry, raisedTs); err != nil {
403 logger.Errorw(ctx, "failed-to-send-pon-stats", log.Fields{"err": err})
Naga Manjunath7615e552019-10-11 22:35:47 +0530404 }
Naga Manjunath7615e552019-10-11 22:35:47 +0530405}
406
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700407// PortStatisticsIndication handles the port statistics indication
Neha Sharma96b7bf22020-06-15 10:37:32 +0000408func (StatMgr *OpenOltStatisticsMgr) PortStatisticsIndication(ctx context.Context, PortStats *openolt.PortStatistics, NumPonPorts uint32) {
409 StatMgr.PortsStatisticsKpis(ctx, PortStats, NumPonPorts)
410 logger.Debugw(ctx, "received-port-stats-indication", log.Fields{"port-stats": PortStats})
Abhilash S.L765ad002019-04-24 16:40:57 +0530411 // TODO send stats to core topic to the voltha kafka or a different kafka ?
412}
413
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700414// FlowStatisticsIndication to be implemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000415func FlowStatisticsIndication(ctx context.Context, self, FlowStats *openolt.FlowStatistics) {
416 logger.Debugw(ctx, "flow-stats-collected", log.Fields{"flow-stats": FlowStats})
Abhilash S.L765ad002019-04-24 16:40:57 +0530417 //TODO send to kafka ?
418}
419
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700420// PortsStatisticsKpis map the port stats values into a dictionary, creates the kpiEvent and then publish to Kafka
Neha Sharma96b7bf22020-06-15 10:37:32 +0000421func (StatMgr *OpenOltStatisticsMgr) PortsStatisticsKpis(ctx context.Context, PortStats *openolt.PortStatistics, NumPonPorts uint32) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530422
423 /*map the port stats values into a dictionary
424 Create a kpoEvent and publish to Kafka
425
426 :param port_stats:
427 :return:
428 */
429 //var err error
430 IntfID := PortStats.IntfId
431
Naga Manjunath7615e552019-10-11 22:35:47 +0530432 if (IntfIDToPortNo(1, voltha.Port_ETHERNET_NNI) < IntfID) &&
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700433 (IntfID < IntfIDToPortNo(4, voltha.Port_ETHERNET_NNI)) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530434 /*
435 for this release we are only interested in the first NNI for
436 Northbound.
437 we are not using the other 3
438 */
439 return
Naga Manjunath7615e552019-10-11 22:35:47 +0530440 } else if IntfIDToPortNo(0, voltha.Port_ETHERNET_NNI) == IntfID {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700441
Naga Manjunath7615e552019-10-11 22:35:47 +0530442 var portNNIStat NniPort
443 portNNIStat.IntfID = IntfID
444 portNNIStat.PortNum = uint32(0)
445 portNNIStat.RxBytes = PortStats.RxBytes
446 portNNIStat.RxPackets = PortStats.RxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000447 portNNIStat.RxUcastPackets = PortStats.RxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530448 portNNIStat.RxMcastPackets = PortStats.RxMcastPackets
449 portNNIStat.RxBcastPackets = PortStats.RxBcastPackets
450 portNNIStat.TxBytes = PortStats.TxBytes
451 portNNIStat.TxPackets = PortStats.TxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000452 portNNIStat.TxUcastPackets = PortStats.TxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530453 portNNIStat.TxMcastPackets = PortStats.TxMcastPackets
454 portNNIStat.TxBcastPackets = PortStats.TxBcastPackets
455 mutex.Lock()
456 StatMgr.NorthBoundPort[0] = &portNNIStat
457 mutex.Unlock()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000458 logger.Debugw(ctx, "received-nni-stats", log.Fields{"nni-stats": StatMgr.NorthBoundPort})
Naga Manjunath7615e552019-10-11 22:35:47 +0530459 }
460 for i := uint32(0); i < NumPonPorts; i++ {
461
462 if IntfIDToPortNo(i, voltha.Port_PON_OLT) == IntfID {
463 var portPonStat PonPort
464 portPonStat.IntfID = IntfID
465 portPonStat.PortNum = i
466 portPonStat.PONID = i
467 portPonStat.RxBytes = PortStats.RxBytes
468 portPonStat.RxPackets = PortStats.RxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000469 portPonStat.RxUcastPackets = PortStats.RxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530470 portPonStat.RxMcastPackets = PortStats.RxMcastPackets
471 portPonStat.RxBcastPackets = PortStats.RxBcastPackets
472 portPonStat.TxBytes = PortStats.TxBytes
473 portPonStat.TxPackets = PortStats.TxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000474 portPonStat.TxUcastPackets = PortStats.TxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530475 portPonStat.TxMcastPackets = PortStats.TxMcastPackets
476 portPonStat.TxBcastPackets = PortStats.TxBcastPackets
477 mutex.Lock()
478 StatMgr.SouthBoundPort[i] = &portPonStat
479 mutex.Unlock()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000480 logger.Debugw(ctx, "received-pon-stats-for-port", log.Fields{"port-pon-stats": portPonStat})
Naga Manjunath7615e552019-10-11 22:35:47 +0530481 }
482 }
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700483
484 /*
485 Based upon the intf_id map to an nni port or a pon port
486 the intf_id is the key to the north or south bound collections
487
488 Based upon the intf_id the port object (nni_port or pon_port) will
489 have its data attr. updated by the current dataset collected.
490
491 For prefixing the rule is currently to use the port number and not the intf_id
492 */
493 //FIXME : Just use first NNI for now
494 /* TODO should the data be marshaled before sending it ?
495 if IntfID == IntfIdToPortNo(0, voltha.Port_ETHERNET_NNI) {
496 //NNI port (just the first one)
497 err = UpdatePortObjectKpiData(StatMgr.NorthBoundPorts[PortStats.IntfID], PMData)
498 } else {
499 //PON ports
500 err = UpdatePortObjectKpiData(SouthboundPorts[PortStats.IntfID], PMData)
501 }
502 if (err != nil) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000503 logger.Error(ctx, "Error publishing statistics data")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700504 }
505 */
506
Abhilash S.L765ad002019-04-24 16:40:57 +0530507}