blob: 0cb148dcc4e2c7af58c111798e6d4ed3e9f06895 [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"
Kishore Darapuaaf9c102020-05-04 13:06:57 +053026 "strconv"
David K. Bainbridge794735f2020-02-11 21:01:37 -080027 "sync"
28 "time"
Abhilash S.L765ad002019-04-24 16:40:57 +053029)
30
Naga Manjunath7615e552019-10-11 22:35:47 +053031var mutex = &sync.Mutex{}
32
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070033// PonPort representation
Abhilash S.L765ad002019-04-24 16:40:57 +053034type PonPort struct {
35 /*
36 This is a highly reduced version taken from the adtran pon_port.
37 TODO: Extend for use in the openolt adapter set.
38 */
39 /* MAX_ONUS_SUPPORTED = 256
40 DEFAULT_ENABLED = False
41 MAX_DEPLOYMENT_RANGE = 25000 # Meters (OLT-PB maximum)
42
43 _MCAST_ONU_ID = 253
44 _MCAST_ALLOC_BASE = 0x500
45
46 _SUPPORTED_ACTIVATION_METHODS = ['autodiscovery'] # , 'autoactivate']
47 _SUPPORTED_AUTHENTICATION_METHODS = ['serial-number']
48 */
49 PONID uint32
50 DeviceID string
51 IntfID uint32
52 PortNum uint32
53 PortID uint32
54 Label string
55 ONUs map[uint32]interface{}
56 ONUsByID map[uint32]interface{}
57
58 RxBytes uint64
59 RxPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000060 RxUcastPackets uint64
Abhilash S.L765ad002019-04-24 16:40:57 +053061 RxMcastPackets uint64
62 RxBcastPackets uint64
63 RxErrorPackets uint64
64 TxBytes uint64
65 TxPackets uint64
66 TxUcastPackets uint64
67 TxMcastPackets uint64
68 TxBcastPackets uint64
69 TxErrorPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000070 RxCrcErrors uint64
71 BipErrors uint64
Abhilash S.L765ad002019-04-24 16:40:57 +053072}
73
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070074// NewPONPort returns a new instance of PonPort initialized with given PONID, DeviceID, IntfID and PortNum
Abhilash S.L765ad002019-04-24 16:40:57 +053075func NewPONPort(PONID uint32, DeviceID string, IntfID uint32, PortNum uint32) *PonPort {
76
77 var PON PonPort
78
79 PON.PONID = PONID
80 PON.DeviceID = DeviceID
81 PON.IntfID = IntfID
82 PON.PortNum = PortNum
83 PON.PortID = 0
Naga Manjunath7615e552019-10-11 22:35:47 +053084 PON.Label = fmt.Sprintf("%s%d", "pon-", PONID)
Abhilash S.L765ad002019-04-24 16:40:57 +053085
86 PON.ONUs = make(map[uint32]interface{})
87 PON.ONUsByID = make(map[uint32]interface{})
88
89 /*
90 Statistics taken from nni_port
91 self.intf_id = 0 #handled by getter
92 self.port_no = 0 #handled by getter
93 self.port_id = 0 #handled by getter
94
95 Note: In the current implementation of the kpis coming from the BAL the stats are the
96 samne model for NNI and PON.
97
98 TODO: Integrate additional kpis for the PON and other southbound port objecgts.
99
100 */
101
102 PON.RxBytes = 0
103 PON.RxPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000104 PON.RxUcastPackets = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530105 PON.RxMcastPackets = 0
106 PON.RxBcastPackets = 0
107 PON.RxErrorPackets = 0
108 PON.TxBytes = 0
109 PON.TxPackets = 0
110 PON.TxUcastPackets = 0
111 PON.TxMcastPackets = 0
112 PON.TxBcastPackets = 0
113 PON.TxErrorPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000114 PON.RxCrcErrors = 0
115 PON.BipErrors = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530116
117 /* def __str__(self):
118 return "PonPort-{}: Admin: {}, Oper: {}, OLT: {}".format(self._label,
119 self._admin_state,
120 self._oper_status,
121 self.olt)
122 */
123 return &PON
124}
125
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700126// NniPort representation
Abhilash S.L765ad002019-04-24 16:40:57 +0530127type NniPort struct {
128 /*
129 Northbound network port, often Ethernet-based
130
131 This is a highly reduced version taken from the adtran nni_port code set
132 TODO: add functions to allow for port specific values and operations
133 */
134 PortNum uint32
135 Name string
136 LogicalPort uint32
137 IntfID uint32
138
139 RxBytes uint64
140 RxPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000141 RxUcastPackets uint64
Abhilash S.L765ad002019-04-24 16:40:57 +0530142 RxMcastPackets uint64
143 RxBcastPackets uint64
144 RxErrorPackets uint64
145 TxBytes uint64
146 TxPackets uint64
147 TxUcastPackets uint64
148 TxMcastPackets uint64
149 TxBcastPackets uint64
150 TxErrorPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000151 RxCrcErrors uint64
152 BipErrors uint64
Abhilash S.L765ad002019-04-24 16:40:57 +0530153}
154
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700155// NewNniPort returns a new instance of NniPort initialized with the given PortNum and IntfID
Abhilash S.L765ad002019-04-24 16:40:57 +0530156func NewNniPort(PortNum uint32, IntfID uint32) *NniPort {
157
158 var NNI NniPort
159
160 NNI.PortNum = PortNum
Naga Manjunath7615e552019-10-11 22:35:47 +0530161 NNI.Name = fmt.Sprintf("%s%d", "nni-", PortNum)
Abhilash S.L765ad002019-04-24 16:40:57 +0530162 NNI.IntfID = IntfID
163
164 NNI.RxBytes = 0
165 NNI.RxPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000166 NNI.RxUcastPackets = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530167 NNI.RxMcastPackets = 0
168 NNI.RxBcastPackets = 0
169 NNI.RxErrorPackets = 0
170 NNI.TxBytes = 0
171 NNI.TxPackets = 0
172 NNI.TxUcastPackets = 0
173 NNI.TxMcastPackets = 0
174 NNI.TxBcastPackets = 0
175 NNI.TxErrorPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000176 NNI.RxCrcErrors = 0
177 NNI.BipErrors = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530178
179 return &NNI
180}
181
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700182// OpenOltStatisticsMgr structure
Abhilash S.L765ad002019-04-24 16:40:57 +0530183type OpenOltStatisticsMgr struct {
184 Device *DeviceHandler
Naga Manjunath7615e552019-10-11 22:35:47 +0530185 NorthBoundPort map[uint32]*NniPort
186 SouthBoundPort map[uint32]*PonPort
Abhilash S.L765ad002019-04-24 16:40:57 +0530187 // TODO PMMetrics Metrics
188}
189
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700190// NewOpenOltStatsMgr returns a new instance of the OpenOltStatisticsMgr
Abhilash S.L765ad002019-04-24 16:40:57 +0530191func NewOpenOltStatsMgr(Dev *DeviceHandler) *OpenOltStatisticsMgr {
192
193 var StatMgr OpenOltStatisticsMgr
194
195 StatMgr.Device = Dev
196 // TODO call metric PMMetric =
197 // Northbound and Southbound ports
198 // added to initialize the pm_metrics
199 var Ports interface{}
Thomas Lee S985938d2020-05-04 11:40:41 +0530200 Ports, _ = InitPorts("nni", Dev.device.Id, 1)
Naga Manjunath7615e552019-10-11 22:35:47 +0530201 StatMgr.NorthBoundPort, _ = Ports.(map[uint32]*NniPort)
202 NumPonPorts := Dev.resourceMgr.DevInfo.GetPonPorts()
Thomas Lee S985938d2020-05-04 11:40:41 +0530203 Ports, _ = InitPorts("pon", Dev.device.Id, NumPonPorts)
Naga Manjunath7615e552019-10-11 22:35:47 +0530204 StatMgr.SouthBoundPort, _ = Ports.(map[uint32]*PonPort)
Abhilash S.L765ad002019-04-24 16:40:57 +0530205 return &StatMgr
206}
207
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700208// 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 +0530209func InitPorts(Intftype string, DeviceID string, numOfPorts uint32) (interface{}, error) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530210 /*
211 This method collects the port objects: nni and pon that are updated with the
212 current data from the OLT
213
214 Both the northbound (nni) and southbound ports are indexed by the interface id (intf_id)
215 and NOT the port number. When the port object is instantiated it will contain the intf_id and
216 port_no values
217
218 :param type:
219 :return:
220 */
221 var i uint32
222 if Intftype == "nni" {
Naga Manjunath7615e552019-10-11 22:35:47 +0530223 NniPorts := make(map[uint32]*NniPort)
224 for i = 0; i < numOfPorts; i++ {
kdarapu768708d2019-09-16 23:19:15 +0530225 Port := BuildPortObject(i, "nni", DeviceID).(*NniPort)
Naga Manjunath7615e552019-10-11 22:35:47 +0530226 NniPorts[Port.IntfID] = Port
Abhilash S.L765ad002019-04-24 16:40:57 +0530227 }
228 return NniPorts, nil
229 } else if Intftype == "pon" {
Naga Manjunath7615e552019-10-11 22:35:47 +0530230 PONPorts := make(map[uint32]*PonPort)
231 for i = 0; i < numOfPorts; i++ {
kdarapu768708d2019-09-16 23:19:15 +0530232 PONPort := BuildPortObject(i, "pon", DeviceID).(*PonPort)
Naga Manjunath7615e552019-10-11 22:35:47 +0530233 PONPorts[PortNoToIntfID(PONPort.IntfID, voltha.Port_PON_OLT)] = PONPort
Abhilash S.L765ad002019-04-24 16:40:57 +0530234 }
235 return PONPorts, nil
236 } else {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000237 logger.Errorf("Invalid type of interface %s", Intftype)
Thomas Lee S94109f12020-03-03 16:39:29 +0530238 return nil, olterrors.NewErrInvalidValue(log.Fields{"interface-type": Intftype}, nil)
Abhilash S.L765ad002019-04-24 16:40:57 +0530239 }
240}
241
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700242// BuildPortObject allows for updating north and southbound ports, newly discovered ports, and devices
Abhilash S.L765ad002019-04-24 16:40:57 +0530243func BuildPortObject(PortNum uint32, IntfType string, DeviceID string) interface{} {
244 /*
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700245 Separate method to allow for updating north and southbound ports
Abhilash S.L765ad002019-04-24 16:40:57 +0530246 newly discovered ports and devices
247
248 :param port_num:
249 :param type:
250 :return:
251 */
252
253 //This builds a port object which is added to the
254 //appropriate northbound or southbound values
255 if IntfType == "nni" {
Naga Manjunath7615e552019-10-11 22:35:47 +0530256 IntfID := IntfIDToPortNo(PortNum, voltha.Port_ETHERNET_NNI)
257 nniID := PortNoToIntfID(IntfID, voltha.Port_ETHERNET_NNI)
Girish Kumar2ad402b2020-03-20 19:45:12 +0000258 logger.Debugf("NniID %v", nniID)
Naga Manjunath7615e552019-10-11 22:35:47 +0530259 return NewNniPort(PortNum, nniID)
Abhilash S.L765ad002019-04-24 16:40:57 +0530260 } else if IntfType == "pon" {
261 // PON ports require a different configuration
262 // intf_id and pon_id are currently equal.
Naga Manjunath7615e552019-10-11 22:35:47 +0530263 IntfID := IntfIDToPortNo(PortNum, voltha.Port_PON_OLT)
264 PONID := PortNoToIntfID(IntfID, voltha.Port_PON_OLT)
Girish Kumar2ad402b2020-03-20 19:45:12 +0000265 logger.Debugf("PonID %v", PONID)
Abhilash S.L765ad002019-04-24 16:40:57 +0530266 return NewPONPort(PONID, DeviceID, IntfID, PortNum)
267 } else {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000268 logger.Errorf("Invalid type of interface %s", IntfType)
Abhilash S.L765ad002019-04-24 16:40:57 +0530269 return nil
270 }
271}
272
Naga Manjunath7615e552019-10-11 22:35:47 +0530273// collectNNIMetrics will collect the nni port metrics
274func (StatMgr *OpenOltStatisticsMgr) collectNNIMetrics(nniID uint32) map[string]float32 {
275
276 nnival := make(map[string]float32)
277 mutex.Lock()
278 cm := StatMgr.Device.portStats.NorthBoundPort[nniID]
279 mutex.Unlock()
280 metricName := StatMgr.Device.metrics.GetSubscriberMetrics()
281
282 if metricName != nil && len(metricName) > 0 {
283 for mName := range metricName {
284 switch mName {
285 case "rx_bytes":
286 nnival["RxBytes"] = float32(cm.RxBytes)
287 case "rx_packets":
288 nnival["RxPackets"] = float32(cm.RxPackets)
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000289 case "rx_ucast_packets":
290 nnival["RxUcastPackets"] = float32(cm.RxUcastPackets)
Naga Manjunath7615e552019-10-11 22:35:47 +0530291 case "rx_mcast_packets":
292 nnival["RxMcastPackets"] = float32(cm.RxMcastPackets)
293 case "rx_bcast_packets":
294 nnival["RxBcastPackets"] = float32(cm.RxBcastPackets)
295 case "tx_bytes":
296 nnival["TxBytes"] = float32(cm.TxBytes)
297 case "tx_packets":
298 nnival["TxPackets"] = float32(cm.TxPackets)
299 case "tx_mcast_packets":
300 nnival["TxMcastPackets"] = float32(cm.TxMcastPackets)
301 case "tx_bcast_packets":
302 nnival["TxBcastPackets"] = float32(cm.TxBcastPackets)
303 }
304 }
305 }
306 return nnival
307}
308
309// collectPONMetrics will collect the pon port metrics
310func (StatMgr *OpenOltStatisticsMgr) collectPONMetrics(pID uint32) map[string]float32 {
311
312 ponval := make(map[string]float32)
313 mutex.Lock()
314 cm := StatMgr.Device.portStats.SouthBoundPort[pID]
315 mutex.Unlock()
316 metricName := StatMgr.Device.metrics.GetSubscriberMetrics()
317
318 if metricName != nil && len(metricName) > 0 {
319 for mName := range metricName {
320 switch mName {
321 case "rx_bytes":
322 ponval["RxBytes"] = float32(cm.RxBytes)
323 case "rx_packets":
324 ponval["RxPackets"] = float32(cm.RxPackets)
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000325 // these are not supported in OpenOlt Agent now
326 // will return zero until supported
327 case "rx_ucast_packets":
328 ponval["RxUcastPackets"] = float32(cm.RxUcastPackets)
Naga Manjunath7615e552019-10-11 22:35:47 +0530329 case "rx_mcast_packets":
330 ponval["RxMcastPackets"] = float32(cm.RxMcastPackets)
331 case "rx_bcast_packets":
332 ponval["RxBcastPackets"] = float32(cm.RxBcastPackets)
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000333 // End will return zero until supported
Naga Manjunath7615e552019-10-11 22:35:47 +0530334 case "tx_bytes":
335 ponval["TxBytes"] = float32(cm.TxBytes)
336 case "tx_packets":
337 ponval["TxPackets"] = float32(cm.TxPackets)
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000338 // these are not supported in OpenOlt Agent now
339 // will return zero until supported
340 case "tx_ucast_packets":
341 ponval["TxUcastPackets"] = float32(cm.TxUcastPackets)
Naga Manjunath7615e552019-10-11 22:35:47 +0530342 case "tx_mcast_packets":
343 ponval["TxMcastPackets"] = float32(cm.TxMcastPackets)
344 case "tx_bcast_packets":
345 ponval["TxBcastPackets"] = float32(cm.TxBcastPackets)
346 }
347 }
348 }
349 return ponval
350}
351
352// publishMatrics will publish the pon port metrics
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530353func (StatMgr OpenOltStatisticsMgr) publishMetrics(val map[string]float32,
Girish Gowdra34815db2020-05-11 17:18:04 -0700354 port *voltha.Port, devID string, devType string) {
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530355 logger.Debugw("publish-metrics", log.Fields{"port": port.Label, "metrics": val})
Naga Manjunath7615e552019-10-11 22:35:47 +0530356
357 var metricInfo voltha.MetricInformation
358 var ke voltha.KpiEvent2
Esin Karamanccb714b2019-11-29 15:02:06 +0000359 var volthaEventSubCatgry voltha.EventSubCategory_Types
Girish Gowdra34815db2020-05-11 17:18:04 -0700360 metricsContext := make(map[string]string)
361 metricsContext["oltid"] = devID
362 metricsContext["devicetype"] = devType
363 metricsContext["portlabel"] = port.Label
364 metricsContext["portno"] = strconv.Itoa(int(port.PortNo))
Naga Manjunath7615e552019-10-11 22:35:47 +0530365
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530366 if port.Type == voltha.Port_ETHERNET_NNI {
Naga Manjunath7615e552019-10-11 22:35:47 +0530367 volthaEventSubCatgry = voltha.EventSubCategory_NNI
368 } else {
369 volthaEventSubCatgry = voltha.EventSubCategory_PON
370 }
371
372 raisedTs := time.Now().UnixNano()
373 mmd := voltha.MetricMetaData{
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530374 Title: port.Type.String(),
Naga Manjunath7615e552019-10-11 22:35:47 +0530375 Ts: float64(raisedTs),
Girish Gowdra34815db2020-05-11 17:18:04 -0700376 Context: metricsContext,
Naga Manjunath7615e552019-10-11 22:35:47 +0530377 DeviceId: devID,
378 }
379
380 metricInfo.Metadata = &mmd
381 metricInfo.Metrics = val
382
383 ke.SliceData = []*voltha.MetricInformation{&metricInfo}
384 ke.Type = voltha.KpiEventType_slice
385 ke.Ts = float64(time.Now().UnixNano())
386
387 if err := StatMgr.Device.EventProxy.SendKpiEvent("STATS_EVENT", &ke, voltha.EventCategory_EQUIPMENT, volthaEventSubCatgry, raisedTs); err != nil {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000388 logger.Errorw("Failed to send Pon stats", log.Fields{"err": err})
Naga Manjunath7615e552019-10-11 22:35:47 +0530389 }
Naga Manjunath7615e552019-10-11 22:35:47 +0530390}
391
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700392// PortStatisticsIndication handles the port statistics indication
Naga Manjunath7615e552019-10-11 22:35:47 +0530393func (StatMgr *OpenOltStatisticsMgr) PortStatisticsIndication(PortStats *openolt.PortStatistics, NumPonPorts uint32) {
Naga Manjunath7615e552019-10-11 22:35:47 +0530394 StatMgr.PortsStatisticsKpis(PortStats, NumPonPorts)
Andrea Campanella9931ad62020-04-28 15:11:06 +0200395 logger.Debugw("Received port stats indication", log.Fields{"PortStats": PortStats})
Abhilash S.L765ad002019-04-24 16:40:57 +0530396 // TODO send stats to core topic to the voltha kafka or a different kafka ?
397}
398
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700399// FlowStatisticsIndication to be implemented
Abhilash S.L765ad002019-04-24 16:40:57 +0530400func FlowStatisticsIndication(self, FlowStats *openolt.FlowStatistics) {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000401 logger.Debugf("flow-stats-collected %v", FlowStats)
Abhilash S.L765ad002019-04-24 16:40:57 +0530402 //TODO send to kafka ?
403}
404
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700405// PortsStatisticsKpis map the port stats values into a dictionary, creates the kpiEvent and then publish to Kafka
Naga Manjunath7615e552019-10-11 22:35:47 +0530406func (StatMgr *OpenOltStatisticsMgr) PortsStatisticsKpis(PortStats *openolt.PortStatistics, NumPonPorts uint32) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530407
408 /*map the port stats values into a dictionary
409 Create a kpoEvent and publish to Kafka
410
411 :param port_stats:
412 :return:
413 */
414 //var err error
415 IntfID := PortStats.IntfId
416
Naga Manjunath7615e552019-10-11 22:35:47 +0530417 if (IntfIDToPortNo(1, voltha.Port_ETHERNET_NNI) < IntfID) &&
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700418 (IntfID < IntfIDToPortNo(4, voltha.Port_ETHERNET_NNI)) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530419 /*
420 for this release we are only interested in the first NNI for
421 Northbound.
422 we are not using the other 3
423 */
424 return
Naga Manjunath7615e552019-10-11 22:35:47 +0530425 } else if IntfIDToPortNo(0, voltha.Port_ETHERNET_NNI) == IntfID {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700426
Naga Manjunath7615e552019-10-11 22:35:47 +0530427 var portNNIStat NniPort
428 portNNIStat.IntfID = IntfID
429 portNNIStat.PortNum = uint32(0)
430 portNNIStat.RxBytes = PortStats.RxBytes
431 portNNIStat.RxPackets = PortStats.RxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000432 portNNIStat.RxUcastPackets = PortStats.RxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530433 portNNIStat.RxMcastPackets = PortStats.RxMcastPackets
434 portNNIStat.RxBcastPackets = PortStats.RxBcastPackets
435 portNNIStat.TxBytes = PortStats.TxBytes
436 portNNIStat.TxPackets = PortStats.TxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000437 portNNIStat.TxUcastPackets = PortStats.TxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530438 portNNIStat.TxMcastPackets = PortStats.TxMcastPackets
439 portNNIStat.TxBcastPackets = PortStats.TxBcastPackets
440 mutex.Lock()
441 StatMgr.NorthBoundPort[0] = &portNNIStat
442 mutex.Unlock()
Girish Kumar2ad402b2020-03-20 19:45:12 +0000443 logger.Debugf("Received-NNI-Stats: %v", StatMgr.NorthBoundPort)
Naga Manjunath7615e552019-10-11 22:35:47 +0530444 }
445 for i := uint32(0); i < NumPonPorts; i++ {
446
447 if IntfIDToPortNo(i, voltha.Port_PON_OLT) == IntfID {
448 var portPonStat PonPort
449 portPonStat.IntfID = IntfID
450 portPonStat.PortNum = i
451 portPonStat.PONID = i
452 portPonStat.RxBytes = PortStats.RxBytes
453 portPonStat.RxPackets = PortStats.RxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000454 portPonStat.RxUcastPackets = PortStats.RxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530455 portPonStat.RxMcastPackets = PortStats.RxMcastPackets
456 portPonStat.RxBcastPackets = PortStats.RxBcastPackets
457 portPonStat.TxBytes = PortStats.TxBytes
458 portPonStat.TxPackets = PortStats.TxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000459 portPonStat.TxUcastPackets = PortStats.TxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530460 portPonStat.TxMcastPackets = PortStats.TxMcastPackets
461 portPonStat.TxBcastPackets = PortStats.TxBcastPackets
462 mutex.Lock()
463 StatMgr.SouthBoundPort[i] = &portPonStat
464 mutex.Unlock()
Girish Gowdra868131c2020-03-30 08:13:33 -0700465 logger.Debugf("Received-PON-Stats-for-Port %v : %v", i, portPonStat)
Naga Manjunath7615e552019-10-11 22:35:47 +0530466 }
467 }
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700468
469 /*
470 Based upon the intf_id map to an nni port or a pon port
471 the intf_id is the key to the north or south bound collections
472
473 Based upon the intf_id the port object (nni_port or pon_port) will
474 have its data attr. updated by the current dataset collected.
475
476 For prefixing the rule is currently to use the port number and not the intf_id
477 */
478 //FIXME : Just use first NNI for now
479 /* TODO should the data be marshaled before sending it ?
480 if IntfID == IntfIdToPortNo(0, voltha.Port_ETHERNET_NNI) {
481 //NNI port (just the first one)
482 err = UpdatePortObjectKpiData(StatMgr.NorthBoundPorts[PortStats.IntfID], PMData)
483 } else {
484 //PON ports
485 err = UpdatePortObjectKpiData(SouthboundPorts[PortStats.IntfID], PMData)
486 }
487 if (err != nil) {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000488 logger.Error("Error publishing statistics data")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700489 }
490 */
491
Abhilash S.L765ad002019-04-24 16:40:57 +0530492}