blob: 6427a0c25833a58a03505fb1a384877e52bbd2c0 [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
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
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
291
292 if metricNames != nil && len(metricNames) > 0 {
293 for metric := range metricNames {
294 if metricNames[metric].Enabled {
295 metrics = append(metrics, metric)
Naga Manjunath7615e552019-10-11 22:35:47 +0530296 }
297 }
298 }
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000299
300 for _, mName := range metrics {
301 switch mName {
302 case "rx_bytes":
303 nnival["RxBytes"] = float32(cm.RxBytes)
304 case "rx_packets":
305 nnival["RxPackets"] = float32(cm.RxPackets)
306 case "rx_ucast_packets":
307 nnival["RxUcastPackets"] = float32(cm.RxUcastPackets)
308 case "rx_mcast_packets":
309 nnival["RxMcastPackets"] = float32(cm.RxMcastPackets)
310 case "rx_bcast_packets":
311 nnival["RxBcastPackets"] = float32(cm.RxBcastPackets)
312 case "tx_bytes":
313 nnival["TxBytes"] = float32(cm.TxBytes)
314 case "tx_packets":
315 nnival["TxPackets"] = float32(cm.TxPackets)
316 case "tx_mcast_packets":
317 nnival["TxMcastPackets"] = float32(cm.TxMcastPackets)
318 case "tx_bcast_packets":
319 nnival["TxBcastPackets"] = float32(cm.TxBcastPackets)
320 }
321 }
Naga Manjunath7615e552019-10-11 22:35:47 +0530322 return nnival
323}
324
325// collectPONMetrics will collect the pon port metrics
326func (StatMgr *OpenOltStatisticsMgr) collectPONMetrics(pID uint32) map[string]float32 {
327
328 ponval := make(map[string]float32)
329 mutex.Lock()
330 cm := StatMgr.Device.portStats.SouthBoundPort[pID]
331 mutex.Unlock()
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000332 metricNames := StatMgr.Device.metrics.GetSubscriberMetrics()
Naga Manjunath7615e552019-10-11 22:35:47 +0530333
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000334 var metrics []string
335
336 if metricNames != nil && len(metricNames) > 0 {
337 for metric := range metricNames {
338 if metricNames[metric].Enabled {
339 metrics = append(metrics, metric)
Naga Manjunath7615e552019-10-11 22:35:47 +0530340 }
341 }
342 }
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000343
344 for _, mName := range metrics {
345 switch mName {
346 case "rx_bytes":
347 ponval["RxBytes"] = float32(cm.RxBytes)
348 case "rx_packets":
349 ponval["RxPackets"] = float32(cm.RxPackets)
350 case "rx_ucast_packets":
351 ponval["RxUcastPackets"] = float32(cm.RxUcastPackets)
352 case "rx_mcast_packets":
353 ponval["RxMcastPackets"] = float32(cm.RxMcastPackets)
354 case "rx_bcast_packets":
355 ponval["RxBcastPackets"] = float32(cm.RxBcastPackets)
356 case "tx_bytes":
357 ponval["TxBytes"] = float32(cm.TxBytes)
358 case "tx_packets":
359 ponval["TxPackets"] = float32(cm.TxPackets)
360 case "tx_mcast_packets":
361 ponval["TxMcastPackets"] = float32(cm.TxMcastPackets)
362 case "tx_bcast_packets":
363 ponval["TxBcastPackets"] = float32(cm.TxBcastPackets)
364 }
365 }
366
Naga Manjunath7615e552019-10-11 22:35:47 +0530367 return ponval
368}
369
370// publishMatrics will publish the pon port metrics
Neha Sharma96b7bf22020-06-15 10:37:32 +0000371func (StatMgr OpenOltStatisticsMgr) publishMetrics(ctx context.Context, val map[string]float32,
Girish Gowdra34815db2020-05-11 17:18:04 -0700372 port *voltha.Port, devID string, devType string) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000373 logger.Debugw(ctx, "publish-metrics",
Shrey Baid26912972020-04-16 21:02:31 +0530374 log.Fields{
375 "port": port.Label,
376 "metrics": val})
Naga Manjunath7615e552019-10-11 22:35:47 +0530377
378 var metricInfo voltha.MetricInformation
379 var ke voltha.KpiEvent2
Esin Karamanccb714b2019-11-29 15:02:06 +0000380 var volthaEventSubCatgry voltha.EventSubCategory_Types
Girish Gowdra34815db2020-05-11 17:18:04 -0700381 metricsContext := make(map[string]string)
382 metricsContext["oltid"] = devID
383 metricsContext["devicetype"] = devType
384 metricsContext["portlabel"] = port.Label
385 metricsContext["portno"] = strconv.Itoa(int(port.PortNo))
Naga Manjunath7615e552019-10-11 22:35:47 +0530386
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530387 if port.Type == voltha.Port_ETHERNET_NNI {
Naga Manjunath7615e552019-10-11 22:35:47 +0530388 volthaEventSubCatgry = voltha.EventSubCategory_NNI
389 } else {
390 volthaEventSubCatgry = voltha.EventSubCategory_PON
391 }
392
393 raisedTs := time.Now().UnixNano()
394 mmd := voltha.MetricMetaData{
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530395 Title: port.Type.String(),
Naga Manjunath7615e552019-10-11 22:35:47 +0530396 Ts: float64(raisedTs),
Girish Gowdra34815db2020-05-11 17:18:04 -0700397 Context: metricsContext,
Naga Manjunath7615e552019-10-11 22:35:47 +0530398 DeviceId: devID,
399 }
400
401 metricInfo.Metadata = &mmd
402 metricInfo.Metrics = val
403
404 ke.SliceData = []*voltha.MetricInformation{&metricInfo}
405 ke.Type = voltha.KpiEventType_slice
406 ke.Ts = float64(time.Now().UnixNano())
407
Neha Sharma96b7bf22020-06-15 10:37:32 +0000408 if err := StatMgr.Device.EventProxy.SendKpiEvent(ctx, "STATS_EVENT", &ke, voltha.EventCategory_EQUIPMENT, volthaEventSubCatgry, raisedTs); err != nil {
409 logger.Errorw(ctx, "failed-to-send-pon-stats", log.Fields{"err": err})
Naga Manjunath7615e552019-10-11 22:35:47 +0530410 }
Naga Manjunath7615e552019-10-11 22:35:47 +0530411}
412
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700413// PortStatisticsIndication handles the port statistics indication
Neha Sharma96b7bf22020-06-15 10:37:32 +0000414func (StatMgr *OpenOltStatisticsMgr) PortStatisticsIndication(ctx context.Context, PortStats *openolt.PortStatistics, NumPonPorts uint32) {
415 StatMgr.PortsStatisticsKpis(ctx, PortStats, NumPonPorts)
416 logger.Debugw(ctx, "received-port-stats-indication", log.Fields{"port-stats": PortStats})
Abhilash S.L765ad002019-04-24 16:40:57 +0530417 // TODO send stats to core topic to the voltha kafka or a different kafka ?
418}
419
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700420// FlowStatisticsIndication to be implemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000421func FlowStatisticsIndication(ctx context.Context, self, FlowStats *openolt.FlowStatistics) {
422 logger.Debugw(ctx, "flow-stats-collected", log.Fields{"flow-stats": FlowStats})
Abhilash S.L765ad002019-04-24 16:40:57 +0530423 //TODO send to kafka ?
424}
425
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700426// PortsStatisticsKpis map the port stats values into a dictionary, creates the kpiEvent and then publish to Kafka
Neha Sharma96b7bf22020-06-15 10:37:32 +0000427func (StatMgr *OpenOltStatisticsMgr) PortsStatisticsKpis(ctx context.Context, PortStats *openolt.PortStatistics, NumPonPorts uint32) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530428
429 /*map the port stats values into a dictionary
430 Create a kpoEvent and publish to Kafka
431
432 :param port_stats:
433 :return:
434 */
435 //var err error
436 IntfID := PortStats.IntfId
437
Naga Manjunath7615e552019-10-11 22:35:47 +0530438 if (IntfIDToPortNo(1, voltha.Port_ETHERNET_NNI) < IntfID) &&
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700439 (IntfID < IntfIDToPortNo(4, voltha.Port_ETHERNET_NNI)) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530440 /*
441 for this release we are only interested in the first NNI for
442 Northbound.
443 we are not using the other 3
444 */
445 return
Naga Manjunath7615e552019-10-11 22:35:47 +0530446 } else if IntfIDToPortNo(0, voltha.Port_ETHERNET_NNI) == IntfID {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700447
Naga Manjunath7615e552019-10-11 22:35:47 +0530448 var portNNIStat NniPort
449 portNNIStat.IntfID = IntfID
450 portNNIStat.PortNum = uint32(0)
451 portNNIStat.RxBytes = PortStats.RxBytes
452 portNNIStat.RxPackets = PortStats.RxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000453 portNNIStat.RxUcastPackets = PortStats.RxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530454 portNNIStat.RxMcastPackets = PortStats.RxMcastPackets
455 portNNIStat.RxBcastPackets = PortStats.RxBcastPackets
456 portNNIStat.TxBytes = PortStats.TxBytes
457 portNNIStat.TxPackets = PortStats.TxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000458 portNNIStat.TxUcastPackets = PortStats.TxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530459 portNNIStat.TxMcastPackets = PortStats.TxMcastPackets
460 portNNIStat.TxBcastPackets = PortStats.TxBcastPackets
461 mutex.Lock()
462 StatMgr.NorthBoundPort[0] = &portNNIStat
463 mutex.Unlock()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000464 logger.Debugw(ctx, "received-nni-stats", log.Fields{"nni-stats": StatMgr.NorthBoundPort})
Naga Manjunath7615e552019-10-11 22:35:47 +0530465 }
466 for i := uint32(0); i < NumPonPorts; i++ {
467
468 if IntfIDToPortNo(i, voltha.Port_PON_OLT) == IntfID {
469 var portPonStat PonPort
470 portPonStat.IntfID = IntfID
471 portPonStat.PortNum = i
472 portPonStat.PONID = i
473 portPonStat.RxBytes = PortStats.RxBytes
474 portPonStat.RxPackets = PortStats.RxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000475 portPonStat.RxUcastPackets = PortStats.RxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530476 portPonStat.RxMcastPackets = PortStats.RxMcastPackets
477 portPonStat.RxBcastPackets = PortStats.RxBcastPackets
478 portPonStat.TxBytes = PortStats.TxBytes
479 portPonStat.TxPackets = PortStats.TxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000480 portPonStat.TxUcastPackets = PortStats.TxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530481 portPonStat.TxMcastPackets = PortStats.TxMcastPackets
482 portPonStat.TxBcastPackets = PortStats.TxBcastPackets
483 mutex.Lock()
484 StatMgr.SouthBoundPort[i] = &portPonStat
485 mutex.Unlock()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000486 logger.Debugw(ctx, "received-pon-stats-for-port", log.Fields{"port-pon-stats": portPonStat})
Naga Manjunath7615e552019-10-11 22:35:47 +0530487 }
488 }
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700489
490 /*
491 Based upon the intf_id map to an nni port or a pon port
492 the intf_id is the key to the north or south bound collections
493
494 Based upon the intf_id the port object (nni_port or pon_port) will
495 have its data attr. updated by the current dataset collected.
496
497 For prefixing the rule is currently to use the port number and not the intf_id
498 */
499 //FIXME : Just use first NNI for now
500 /* TODO should the data be marshaled before sending it ?
501 if IntfID == IntfIdToPortNo(0, voltha.Port_ETHERNET_NNI) {
502 //NNI port (just the first one)
503 err = UpdatePortObjectKpiData(StatMgr.NorthBoundPorts[PortStats.IntfID], PMData)
504 } else {
505 //PON ports
506 err = UpdatePortObjectKpiData(SouthboundPorts[PortStats.IntfID], PMData)
507 }
508 if (err != nil) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000509 logger.Error(ctx, "Error publishing statistics data")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700510 }
511 */
512
Abhilash S.L765ad002019-04-24 16:40:57 +0530513}