Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 1 | /* |
| 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 Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 16 | |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 17 | //Package core provides the utility for olt devices, flows and statistics |
| 18 | package core |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 21 | "container/list" |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 22 | "context" |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 23 | "fmt" |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 24 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 25 | "sync" |
| 26 | "time" |
| 27 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 28 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 29 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 30 | "github.com/opencord/voltha-protos/v4/go/extension" |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 31 | "github.com/opencord/voltha-protos/v4/go/openolt" |
| 32 | "github.com/opencord/voltha-protos/v4/go/voltha" |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 33 | ) |
| 34 | |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 35 | const ( |
| 36 | //NNIStats statType constant |
| 37 | NNIStats = "NNIStats" |
| 38 | //PONStats statType constant |
| 39 | PONStats = "PONStats" |
| 40 | //ONUStats statType constant |
| 41 | ONUStats = "ONUStats" |
| 42 | //GEMStats statType constant |
| 43 | GEMStats = "GEMStats" |
| 44 | |
| 45 | //RxBytes constant |
| 46 | RxBytes = "RxBytes" |
| 47 | //RxPackets constant |
| 48 | RxPackets = "RxPackets" |
| 49 | //TxBytes constant |
| 50 | TxBytes = "TxBytes" |
| 51 | //TxPackets constant |
| 52 | TxPackets = "TxPackets" |
| 53 | //FecCodewords constant |
| 54 | FecCodewords = "FecCodewords" |
| 55 | //BipUnits constant |
| 56 | BipUnits = "BipUnits" |
| 57 | //BipErrors constant |
| 58 | BipErrors = "BipErrors" |
| 59 | //RxPloamsNonIdle constant |
| 60 | RxPloamsNonIdle = "RxPloamsNonIdle" |
| 61 | //RxPloamsError constant |
| 62 | RxPloamsError = "RxPloamsError" |
| 63 | //RxOmci constant |
| 64 | RxOmci = "RxOmci" |
| 65 | //RxOmciPacketsCrcError constant |
| 66 | RxOmciPacketsCrcError = "RxOmciPacketsCrcError" |
| 67 | //PositiveDrift constant |
| 68 | PositiveDrift = "PositiveDrift" |
| 69 | //NegativeDrift constant |
| 70 | NegativeDrift = "NegativeDrift" |
| 71 | //DelimiterMissDetection constant |
| 72 | DelimiterMissDetection = "DelimiterMissDetection" |
| 73 | //FecCorrectedSymbols constant |
| 74 | FecCorrectedSymbols = "FecCorrectedSymbols" |
| 75 | //FecCodewordsCorrected constant |
| 76 | FecCodewordsCorrected = "FecCodewordsCorrected" |
| 77 | //fecCodewordsUncorrectable constant |
| 78 | fecCodewordsUncorrectable = "fec_codewords_uncorrectable" |
| 79 | //FecCorrectedUnits constant |
| 80 | FecCorrectedUnits = "FecCorrectedUnits" |
| 81 | //XGEMKeyErrors constant |
| 82 | XGEMKeyErrors = "XGEMKeyErrors" |
| 83 | //XGEMLoss constant |
| 84 | XGEMLoss = "XGEMLOSS" |
| 85 | //BerReported constant |
| 86 | BerReported = "BerReported" |
| 87 | //LcdgErrors constant |
| 88 | LcdgErrors = "LcdgErrors" |
| 89 | //RdiErrors constant |
| 90 | RdiErrors = "RdiErrors" |
| 91 | ) |
| 92 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 93 | var mutex = &sync.Mutex{} |
| 94 | |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 95 | var onuStats = make(chan *openolt.OnuStatistics, 100) |
| 96 | var gemStats = make(chan *openolt.GemPortStatistics, 100) |
| 97 | |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 98 | //statRegInfo is used to register for notifications |
| 99 | //on receiving port stats and flow stats indication |
| 100 | type statRegInfo struct { |
| 101 | chn chan bool |
| 102 | portNo uint32 |
| 103 | portType extension.GetOltPortCounters_PortType |
| 104 | } |
| 105 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 106 | // PonPort representation |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 107 | type PonPort struct { |
| 108 | /* |
| 109 | This is a highly reduced version taken from the adtran pon_port. |
| 110 | TODO: Extend for use in the openolt adapter set. |
| 111 | */ |
| 112 | /* MAX_ONUS_SUPPORTED = 256 |
| 113 | DEFAULT_ENABLED = False |
| 114 | MAX_DEPLOYMENT_RANGE = 25000 # Meters (OLT-PB maximum) |
| 115 | |
| 116 | _MCAST_ONU_ID = 253 |
| 117 | _MCAST_ALLOC_BASE = 0x500 |
| 118 | |
| 119 | _SUPPORTED_ACTIVATION_METHODS = ['autodiscovery'] # , 'autoactivate'] |
| 120 | _SUPPORTED_AUTHENTICATION_METHODS = ['serial-number'] |
| 121 | */ |
| 122 | PONID uint32 |
| 123 | DeviceID string |
| 124 | IntfID uint32 |
| 125 | PortNum uint32 |
| 126 | PortID uint32 |
| 127 | Label string |
| 128 | ONUs map[uint32]interface{} |
| 129 | ONUsByID map[uint32]interface{} |
| 130 | |
| 131 | RxBytes uint64 |
| 132 | RxPackets uint64 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 133 | RxUcastPackets uint64 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 134 | RxMcastPackets uint64 |
| 135 | RxBcastPackets uint64 |
| 136 | RxErrorPackets uint64 |
| 137 | TxBytes uint64 |
| 138 | TxPackets uint64 |
| 139 | TxUcastPackets uint64 |
| 140 | TxMcastPackets uint64 |
| 141 | TxBcastPackets uint64 |
| 142 | TxErrorPackets uint64 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 143 | RxCrcErrors uint64 |
| 144 | BipErrors uint64 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 145 | } |
| 146 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 147 | // NewPONPort returns a new instance of PonPort initialized with given PONID, DeviceID, IntfID and PortNum |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 148 | func NewPONPort(PONID uint32, DeviceID string, IntfID uint32, PortNum uint32) *PonPort { |
| 149 | |
| 150 | var PON PonPort |
| 151 | |
| 152 | PON.PONID = PONID |
| 153 | PON.DeviceID = DeviceID |
| 154 | PON.IntfID = IntfID |
| 155 | PON.PortNum = PortNum |
| 156 | PON.PortID = 0 |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 157 | PON.Label = fmt.Sprintf("%s%d", "pon-", PONID) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 158 | |
| 159 | PON.ONUs = make(map[uint32]interface{}) |
| 160 | PON.ONUsByID = make(map[uint32]interface{}) |
| 161 | |
| 162 | /* |
| 163 | Statistics taken from nni_port |
| 164 | self.intf_id = 0 #handled by getter |
| 165 | self.port_no = 0 #handled by getter |
| 166 | self.port_id = 0 #handled by getter |
| 167 | |
| 168 | Note: In the current implementation of the kpis coming from the BAL the stats are the |
| 169 | samne model for NNI and PON. |
| 170 | |
| 171 | TODO: Integrate additional kpis for the PON and other southbound port objecgts. |
| 172 | |
| 173 | */ |
| 174 | |
| 175 | PON.RxBytes = 0 |
| 176 | PON.RxPackets = 0 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 177 | PON.RxUcastPackets = 0 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 178 | PON.RxMcastPackets = 0 |
| 179 | PON.RxBcastPackets = 0 |
| 180 | PON.RxErrorPackets = 0 |
| 181 | PON.TxBytes = 0 |
| 182 | PON.TxPackets = 0 |
| 183 | PON.TxUcastPackets = 0 |
| 184 | PON.TxMcastPackets = 0 |
| 185 | PON.TxBcastPackets = 0 |
| 186 | PON.TxErrorPackets = 0 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 187 | PON.RxCrcErrors = 0 |
| 188 | PON.BipErrors = 0 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 189 | |
| 190 | /* def __str__(self): |
| 191 | return "PonPort-{}: Admin: {}, Oper: {}, OLT: {}".format(self._label, |
| 192 | self._admin_state, |
| 193 | self._oper_status, |
| 194 | self.olt) |
| 195 | */ |
| 196 | return &PON |
| 197 | } |
| 198 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 199 | // NniPort representation |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 200 | type NniPort struct { |
| 201 | /* |
| 202 | Northbound network port, often Ethernet-based |
| 203 | |
| 204 | This is a highly reduced version taken from the adtran nni_port code set |
| 205 | TODO: add functions to allow for port specific values and operations |
| 206 | */ |
| 207 | PortNum uint32 |
| 208 | Name string |
| 209 | LogicalPort uint32 |
| 210 | IntfID uint32 |
| 211 | |
| 212 | RxBytes uint64 |
| 213 | RxPackets uint64 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 214 | RxUcastPackets uint64 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 215 | RxMcastPackets uint64 |
| 216 | RxBcastPackets uint64 |
| 217 | RxErrorPackets uint64 |
| 218 | TxBytes uint64 |
| 219 | TxPackets uint64 |
| 220 | TxUcastPackets uint64 |
| 221 | TxMcastPackets uint64 |
| 222 | TxBcastPackets uint64 |
| 223 | TxErrorPackets uint64 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 224 | RxCrcErrors uint64 |
| 225 | BipErrors uint64 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 226 | } |
| 227 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 228 | // NewNniPort returns a new instance of NniPort initialized with the given PortNum and IntfID |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 229 | func NewNniPort(PortNum uint32, IntfID uint32) *NniPort { |
| 230 | |
| 231 | var NNI NniPort |
| 232 | |
| 233 | NNI.PortNum = PortNum |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 234 | NNI.Name = fmt.Sprintf("%s%d", "nni-", PortNum) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 235 | NNI.IntfID = IntfID |
| 236 | |
| 237 | NNI.RxBytes = 0 |
| 238 | NNI.RxPackets = 0 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 239 | NNI.RxUcastPackets = 0 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 240 | NNI.RxMcastPackets = 0 |
| 241 | NNI.RxBcastPackets = 0 |
| 242 | NNI.RxErrorPackets = 0 |
| 243 | NNI.TxBytes = 0 |
| 244 | NNI.TxPackets = 0 |
| 245 | NNI.TxUcastPackets = 0 |
| 246 | NNI.TxMcastPackets = 0 |
| 247 | NNI.TxBcastPackets = 0 |
| 248 | NNI.TxErrorPackets = 0 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 249 | NNI.RxCrcErrors = 0 |
| 250 | NNI.BipErrors = 0 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 251 | |
| 252 | return &NNI |
| 253 | } |
| 254 | |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 255 | //StatType defines portStatsType and flowStatsType types |
| 256 | type StatType int |
| 257 | |
| 258 | const ( |
| 259 | portStatsType StatType = iota |
| 260 | flowStatsType |
| 261 | ) |
| 262 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 263 | // OpenOltStatisticsMgr structure |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 264 | type OpenOltStatisticsMgr struct { |
| 265 | Device *DeviceHandler |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 266 | NorthBoundPort map[uint32]*NniPort |
| 267 | SouthBoundPort map[uint32]*PonPort |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 268 | // TODO PMMetrics Metrics |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 269 | //statIndListners is the list of requests to be notified when port and flow stats indication is received |
| 270 | statIndListnerMu sync.Mutex |
| 271 | statIndListners map[StatType]*list.List |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 272 | } |
| 273 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 274 | // NewOpenOltStatsMgr returns a new instance of the OpenOltStatisticsMgr |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 275 | func NewOpenOltStatsMgr(ctx context.Context, Dev *DeviceHandler) *OpenOltStatisticsMgr { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 276 | |
| 277 | var StatMgr OpenOltStatisticsMgr |
| 278 | |
| 279 | StatMgr.Device = Dev |
| 280 | // TODO call metric PMMetric = |
| 281 | // Northbound and Southbound ports |
| 282 | // added to initialize the pm_metrics |
| 283 | var Ports interface{} |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 284 | Ports, _ = InitPorts(ctx, "nni", Dev.device.Id, 1) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 285 | StatMgr.NorthBoundPort, _ = Ports.(map[uint32]*NniPort) |
| 286 | NumPonPorts := Dev.resourceMgr.DevInfo.GetPonPorts() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 287 | Ports, _ = InitPorts(ctx, "pon", Dev.device.Id, NumPonPorts) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 288 | StatMgr.SouthBoundPort, _ = Ports.(map[uint32]*PonPort) |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 289 | if StatMgr.Device.openOLT.enableONUStats { |
| 290 | go StatMgr.publishOnuStats() |
| 291 | } |
| 292 | if StatMgr.Device.openOLT.enableGemStats { |
| 293 | go StatMgr.publishGemStats() |
| 294 | } |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 295 | StatMgr.statIndListners = make(map[StatType]*list.List) |
| 296 | StatMgr.statIndListners[portStatsType] = list.New() |
| 297 | StatMgr.statIndListners[flowStatsType] = list.New() |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 298 | return &StatMgr |
| 299 | } |
| 300 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 301 | // InitPorts collects the port objects: nni and pon that are updated with the current data from the OLT |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 302 | func InitPorts(ctx context.Context, Intftype string, DeviceID string, numOfPorts uint32) (interface{}, error) { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 303 | /* |
| 304 | This method collects the port objects: nni and pon that are updated with the |
| 305 | current data from the OLT |
| 306 | |
| 307 | Both the northbound (nni) and southbound ports are indexed by the interface id (intf_id) |
| 308 | and NOT the port number. When the port object is instantiated it will contain the intf_id and |
| 309 | port_no values |
| 310 | |
| 311 | :param type: |
| 312 | :return: |
| 313 | */ |
| 314 | var i uint32 |
| 315 | if Intftype == "nni" { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 316 | NniPorts := make(map[uint32]*NniPort) |
| 317 | for i = 0; i < numOfPorts; i++ { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 318 | Port := BuildPortObject(ctx, i, "nni", DeviceID).(*NniPort) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 319 | NniPorts[Port.IntfID] = Port |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 320 | } |
| 321 | return NniPorts, nil |
| 322 | } else if Intftype == "pon" { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 323 | PONPorts := make(map[uint32]*PonPort) |
| 324 | for i = 0; i < numOfPorts; i++ { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 325 | PONPort := BuildPortObject(ctx, i, "pon", DeviceID).(*PonPort) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 326 | PONPorts[PortNoToIntfID(PONPort.IntfID, voltha.Port_PON_OLT)] = PONPort |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 327 | } |
| 328 | return PONPorts, nil |
| 329 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 330 | logger.Errorw(ctx, "invalid-type-of-interface", log.Fields{"interface-type": Intftype}) |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 331 | return nil, olterrors.NewErrInvalidValue(log.Fields{"interface-type": Intftype}, nil) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 335 | // BuildPortObject allows for updating north and southbound ports, newly discovered ports, and devices |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 336 | func BuildPortObject(ctx context.Context, PortNum uint32, IntfType string, DeviceID string) interface{} { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 337 | /* |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 338 | Separate method to allow for updating north and southbound ports |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 339 | newly discovered ports and devices |
| 340 | |
| 341 | :param port_num: |
| 342 | :param type: |
| 343 | :return: |
| 344 | */ |
| 345 | |
| 346 | //This builds a port object which is added to the |
| 347 | //appropriate northbound or southbound values |
| 348 | if IntfType == "nni" { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 349 | IntfID := IntfIDToPortNo(PortNum, voltha.Port_ETHERNET_NNI) |
| 350 | nniID := PortNoToIntfID(IntfID, voltha.Port_ETHERNET_NNI) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 351 | logger.Debugw(ctx, "interface-type-nni", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 352 | log.Fields{ |
| 353 | "nni-id": nniID, |
| 354 | "intf-type": IntfType}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 355 | return NewNniPort(PortNum, nniID) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 356 | } else if IntfType == "pon" { |
| 357 | // PON ports require a different configuration |
| 358 | // intf_id and pon_id are currently equal. |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 359 | IntfID := IntfIDToPortNo(PortNum, voltha.Port_PON_OLT) |
| 360 | PONID := PortNoToIntfID(IntfID, voltha.Port_PON_OLT) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 361 | logger.Debugw(ctx, "interface-type-pon", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 362 | log.Fields{ |
| 363 | "pon-id": PONID, |
| 364 | "intf-type": IntfType}) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 365 | return NewPONPort(PONID, DeviceID, IntfID, PortNum) |
| 366 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 367 | logger.Errorw(ctx, "invalid-type-of-interface", log.Fields{"intf-type": IntfType}) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 368 | return nil |
| 369 | } |
| 370 | } |
| 371 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 372 | // collectNNIMetrics will collect the nni port metrics |
| 373 | func (StatMgr *OpenOltStatisticsMgr) collectNNIMetrics(nniID uint32) map[string]float32 { |
| 374 | |
| 375 | nnival := make(map[string]float32) |
| 376 | mutex.Lock() |
| 377 | cm := StatMgr.Device.portStats.NorthBoundPort[nniID] |
| 378 | mutex.Unlock() |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 379 | metricNames := StatMgr.Device.metrics.GetSubscriberMetrics() |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 380 | |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 381 | var metrics []string |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 382 | for metric := range metricNames { |
| 383 | if metricNames[metric].Enabled { |
| 384 | metrics = append(metrics, metric) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 385 | } |
| 386 | } |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 387 | |
| 388 | for _, mName := range metrics { |
| 389 | switch mName { |
| 390 | case "rx_bytes": |
| 391 | nnival["RxBytes"] = float32(cm.RxBytes) |
| 392 | case "rx_packets": |
| 393 | nnival["RxPackets"] = float32(cm.RxPackets) |
| 394 | case "rx_ucast_packets": |
| 395 | nnival["RxUcastPackets"] = float32(cm.RxUcastPackets) |
| 396 | case "rx_mcast_packets": |
| 397 | nnival["RxMcastPackets"] = float32(cm.RxMcastPackets) |
| 398 | case "rx_bcast_packets": |
| 399 | nnival["RxBcastPackets"] = float32(cm.RxBcastPackets) |
| 400 | case "tx_bytes": |
| 401 | nnival["TxBytes"] = float32(cm.TxBytes) |
| 402 | case "tx_packets": |
| 403 | nnival["TxPackets"] = float32(cm.TxPackets) |
| 404 | case "tx_mcast_packets": |
| 405 | nnival["TxMcastPackets"] = float32(cm.TxMcastPackets) |
| 406 | case "tx_bcast_packets": |
| 407 | nnival["TxBcastPackets"] = float32(cm.TxBcastPackets) |
| 408 | } |
| 409 | } |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 410 | return nnival |
| 411 | } |
| 412 | |
| 413 | // collectPONMetrics will collect the pon port metrics |
| 414 | func (StatMgr *OpenOltStatisticsMgr) collectPONMetrics(pID uint32) map[string]float32 { |
| 415 | |
| 416 | ponval := make(map[string]float32) |
| 417 | mutex.Lock() |
| 418 | cm := StatMgr.Device.portStats.SouthBoundPort[pID] |
| 419 | mutex.Unlock() |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 420 | metricNames := StatMgr.Device.metrics.GetSubscriberMetrics() |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 421 | |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 422 | var metrics []string |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 423 | for metric := range metricNames { |
| 424 | if metricNames[metric].Enabled { |
| 425 | metrics = append(metrics, metric) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 426 | } |
| 427 | } |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 428 | |
| 429 | for _, mName := range metrics { |
| 430 | switch mName { |
| 431 | case "rx_bytes": |
| 432 | ponval["RxBytes"] = float32(cm.RxBytes) |
| 433 | case "rx_packets": |
| 434 | ponval["RxPackets"] = float32(cm.RxPackets) |
| 435 | case "rx_ucast_packets": |
| 436 | ponval["RxUcastPackets"] = float32(cm.RxUcastPackets) |
| 437 | case "rx_mcast_packets": |
| 438 | ponval["RxMcastPackets"] = float32(cm.RxMcastPackets) |
| 439 | case "rx_bcast_packets": |
| 440 | ponval["RxBcastPackets"] = float32(cm.RxBcastPackets) |
| 441 | case "tx_bytes": |
| 442 | ponval["TxBytes"] = float32(cm.TxBytes) |
| 443 | case "tx_packets": |
| 444 | ponval["TxPackets"] = float32(cm.TxPackets) |
| 445 | case "tx_mcast_packets": |
| 446 | ponval["TxMcastPackets"] = float32(cm.TxMcastPackets) |
| 447 | case "tx_bcast_packets": |
| 448 | ponval["TxBcastPackets"] = float32(cm.TxBcastPackets) |
| 449 | } |
| 450 | } |
| 451 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 452 | return ponval |
| 453 | } |
| 454 | |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 455 | // converGemStats will convert gem stats response to kpi context |
| 456 | func (StatMgr *OpenOltStatisticsMgr) convertGemStats(gemStats *openolt.GemPortStatistics) map[string]float32 { |
| 457 | gemStatsVal := make(map[string]float32) |
| 458 | gemStatsVal[IntfID] = float32(gemStats.IntfId) |
| 459 | gemStatsVal[GemID] = float32(gemStats.GemportId) |
| 460 | gemStatsVal[RxPackets] = float32(gemStats.RxPackets) |
| 461 | gemStatsVal[RxBytes] = float32(gemStats.RxBytes) |
| 462 | gemStatsVal[TxPackets] = float32(gemStats.TxPackets) |
| 463 | gemStatsVal[TxBytes] = float32(gemStats.TxBytes) |
| 464 | return gemStatsVal |
| 465 | } |
| 466 | |
| 467 | // convertONUStats will convert onu stats response to kpi context |
| 468 | func (StatMgr *OpenOltStatisticsMgr) convertONUStats(onuStats *openolt.OnuStatistics) map[string]float32 { |
| 469 | onuStatsVal := make(map[string]float32) |
| 470 | onuStatsVal[IntfID] = float32(onuStats.IntfId) |
| 471 | onuStatsVal[OnuID] = float32(onuStats.OnuId) |
| 472 | onuStatsVal[PositiveDrift] = float32(onuStats.PositiveDrift) |
| 473 | onuStatsVal[NegativeDrift] = float32(onuStats.NegativeDrift) |
| 474 | onuStatsVal[DelimiterMissDetection] = float32(onuStats.DelimiterMissDetection) |
| 475 | onuStatsVal[BipErrors] = float32(onuStats.BipErrors) |
| 476 | onuStatsVal[BipUnits] = float32(onuStats.BipUnits) |
| 477 | onuStatsVal[FecCorrectedSymbols] = float32(onuStats.FecCorrectedSymbols) |
| 478 | onuStatsVal[FecCodewordsCorrected] = float32(onuStats.FecCodewordsCorrected) |
| 479 | onuStatsVal[fecCodewordsUncorrectable] = float32(onuStats.FecCodewordsUncorrectable) |
| 480 | onuStatsVal[FecCodewords] = float32(onuStats.FecCodewords) |
| 481 | onuStatsVal[FecCorrectedUnits] = float32(onuStats.FecCorrectedUnits) |
| 482 | onuStatsVal[XGEMKeyErrors] = float32(onuStats.XgemKeyErrors) |
| 483 | onuStatsVal[XGEMLoss] = float32(onuStats.XgemLoss) |
| 484 | onuStatsVal[RxPloamsError] = float32(onuStats.RxPloamsError) |
| 485 | onuStatsVal[RxPloamsNonIdle] = float32(onuStats.RxPloamsNonIdle) |
| 486 | onuStatsVal[RxOmci] = float32(onuStats.RxOmci) |
| 487 | onuStatsVal[RxOmciPacketsCrcError] = float32(onuStats.RxOmciPacketsCrcError) |
| 488 | onuStatsVal[RxBytes] = float32(onuStats.RxBytes) |
| 489 | onuStatsVal[RxPackets] = float32(onuStats.RxPackets) |
| 490 | onuStatsVal[TxBytes] = float32(onuStats.TxBytes) |
| 491 | onuStatsVal[TxPackets] = float32(onuStats.TxPackets) |
| 492 | onuStatsVal[BerReported] = float32(onuStats.BerReported) |
| 493 | onuStatsVal[LcdgErrors] = float32(onuStats.LcdgErrors) |
| 494 | onuStatsVal[RdiErrors] = float32(onuStats.RdiErrors) |
| 495 | return onuStatsVal |
| 496 | } |
| 497 | |
| 498 | // collectOnuStats will collect the onu metrics |
| 499 | func (StatMgr *OpenOltStatisticsMgr) collectOnuStats(ctx context.Context, onuGemInfo rsrcMgr.OnuGemInfo) { |
| 500 | onu := &openolt.Onu{IntfId: onuGemInfo.IntfID, OnuId: onuGemInfo.OnuID} |
| 501 | logger.Debugw(ctx, "pulling-onu-stats", log.Fields{"IntfID": onuGemInfo.IntfID, "OnuID": onuGemInfo.OnuID}) |
| 502 | if stats, err := StatMgr.Device.Client.GetOnuStatistics(context.Background(), onu); err == nil { |
| 503 | onuStats <- stats |
| 504 | } else { |
| 505 | logger.Errorw(ctx, "error-while-getting-onu-stats-for-onu", log.Fields{"IntfID": onuGemInfo.IntfID, "OnuID": onuGemInfo.OnuID, "err": err}) |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | // collectOnuAndGemStats will collect both onu and gem metrics |
| 510 | func (StatMgr *OpenOltStatisticsMgr) collectOnuAndGemStats(ctx context.Context, onuGemInfo []rsrcMgr.OnuGemInfo) { |
| 511 | if !StatMgr.Device.openOLT.enableONUStats && !StatMgr.Device.openOLT.enableGemStats { |
| 512 | return |
| 513 | } |
| 514 | |
| 515 | for _, onuInfo := range onuGemInfo { |
| 516 | if StatMgr.Device.openOLT.enableONUStats { |
| 517 | go StatMgr.collectOnuStats(ctx, onuInfo) |
| 518 | } |
| 519 | if StatMgr.Device.openOLT.enableGemStats { |
| 520 | go StatMgr.collectGemStats(ctx, onuInfo) |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | // collectGemStats will collect gem metrics |
| 526 | func (StatMgr *OpenOltStatisticsMgr) collectGemStats(ctx context.Context, onuGemInfo rsrcMgr.OnuGemInfo) { |
| 527 | for _, gem := range onuGemInfo.GemPorts { |
| 528 | logger.Debugw(ctx, "pulling-gem-stats", log.Fields{"IntfID": onuGemInfo.IntfID, "OnuID": onuGemInfo.OnuID, "GemID": gem}) |
| 529 | onuPacket := &openolt.OnuPacket{IntfId: onuGemInfo.IntfID, OnuId: onuGemInfo.OnuID, GemportId: gem} |
| 530 | if stats, err := StatMgr.Device.Client.GetGemPortStatistics(context.Background(), onuPacket); err == nil { |
| 531 | gemStats <- stats |
| 532 | } else { |
| 533 | logger.Errorw(ctx, "error-while-getting-gem-stats-for-onu", |
| 534 | log.Fields{"IntfID": onuGemInfo.IntfID, "OnuID": onuGemInfo.OnuID, "GemID": gem, "err": err}) |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | // publishGemStats will publish the gem metrics |
| 540 | func (StatMgr *OpenOltStatisticsMgr) publishGemStats() { |
| 541 | for { |
| 542 | statValue := StatMgr.convertGemStats(<-gemStats) |
| 543 | StatMgr.publishMetrics(context.Background(), GEMStats, statValue, &voltha.Port{Label: "GEM"}, StatMgr.Device.device.Id, StatMgr.Device.device.Type) |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | // publishOnuStats will publish the onu metrics |
| 548 | func (StatMgr *OpenOltStatisticsMgr) publishOnuStats() { |
| 549 | for { |
| 550 | statValue := StatMgr.convertONUStats(<-onuStats) |
| 551 | StatMgr.publishMetrics(context.Background(), ONUStats, statValue, &voltha.Port{Label: "ONU"}, StatMgr.Device.device.Id, StatMgr.Device.device.Type) |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | // publishMetrics will publish the pon port metrics |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 556 | func (StatMgr *OpenOltStatisticsMgr) publishMetrics(ctx context.Context, statType string, val map[string]float32, |
Girish Gowdra | 34815db | 2020-05-11 17:18:04 -0700 | [diff] [blame] | 557 | port *voltha.Port, devID string, devType string) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 558 | logger.Debugw(ctx, "publish-metrics", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 559 | log.Fields{ |
| 560 | "port": port.Label, |
| 561 | "metrics": val}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 562 | |
| 563 | var metricInfo voltha.MetricInformation |
| 564 | var ke voltha.KpiEvent2 |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 565 | var volthaEventSubCatgry voltha.EventSubCategory_Types |
Girish Gowdra | 34815db | 2020-05-11 17:18:04 -0700 | [diff] [blame] | 566 | metricsContext := make(map[string]string) |
| 567 | metricsContext["oltid"] = devID |
| 568 | metricsContext["devicetype"] = devType |
| 569 | metricsContext["portlabel"] = port.Label |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 570 | |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 571 | if statType == NNIStats { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 572 | volthaEventSubCatgry = voltha.EventSubCategory_NNI |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 573 | } else if statType == PONStats { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 574 | volthaEventSubCatgry = voltha.EventSubCategory_PON |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 575 | } else if statType == GEMStats || statType == ONUStats { |
| 576 | volthaEventSubCatgry = voltha.EventSubCategory_ONT |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 577 | } |
| 578 | |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 579 | raisedTs := time.Now().Unix() |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 580 | mmd := voltha.MetricMetaData{ |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 581 | Title: statType, |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 582 | Ts: float64(raisedTs), |
Girish Gowdra | 34815db | 2020-05-11 17:18:04 -0700 | [diff] [blame] | 583 | Context: metricsContext, |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 584 | DeviceId: devID, |
| 585 | } |
| 586 | |
| 587 | metricInfo.Metadata = &mmd |
| 588 | metricInfo.Metrics = val |
| 589 | |
| 590 | ke.SliceData = []*voltha.MetricInformation{&metricInfo} |
| 591 | ke.Type = voltha.KpiEventType_slice |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 592 | ke.Ts = float64(raisedTs) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 593 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 594 | if err := StatMgr.Device.EventProxy.SendKpiEvent(ctx, "STATS_EVENT", &ke, voltha.EventCategory_EQUIPMENT, volthaEventSubCatgry, raisedTs); err != nil { |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 595 | logger.Errorw(ctx, "failed-to-send-stats", log.Fields{"err": err}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 596 | } |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 597 | } |
| 598 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 599 | // PortStatisticsIndication handles the port statistics indication |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 600 | func (StatMgr *OpenOltStatisticsMgr) PortStatisticsIndication(ctx context.Context, PortStats *openolt.PortStatistics, NumPonPorts uint32) { |
| 601 | StatMgr.PortsStatisticsKpis(ctx, PortStats, NumPonPorts) |
| 602 | logger.Debugw(ctx, "received-port-stats-indication", log.Fields{"port-stats": PortStats}) |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 603 | //Indicate that PortStatisticsIndication is handled |
| 604 | //PortStats.IntfId is actually the port number |
| 605 | StatMgr.processStatIndication(ctx, portStatsType, PortStats.IntfId) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 606 | // TODO send stats to core topic to the voltha kafka or a different kafka ? |
| 607 | } |
| 608 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 609 | // FlowStatisticsIndication to be implemented |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 610 | func FlowStatisticsIndication(ctx context.Context, self, FlowStats *openolt.FlowStatistics) { |
| 611 | logger.Debugw(ctx, "flow-stats-collected", log.Fields{"flow-stats": FlowStats}) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 612 | //TODO send to kafka ? |
| 613 | } |
| 614 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 615 | // PortsStatisticsKpis map the port stats values into a dictionary, creates the kpiEvent and then publish to Kafka |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 616 | func (StatMgr *OpenOltStatisticsMgr) PortsStatisticsKpis(ctx context.Context, PortStats *openolt.PortStatistics, NumPonPorts uint32) { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 617 | |
| 618 | /*map the port stats values into a dictionary |
| 619 | Create a kpoEvent and publish to Kafka |
| 620 | |
| 621 | :param port_stats: |
| 622 | :return: |
| 623 | */ |
| 624 | //var err error |
| 625 | IntfID := PortStats.IntfId |
| 626 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 627 | if (IntfIDToPortNo(1, voltha.Port_ETHERNET_NNI) < IntfID) && |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 628 | (IntfID < IntfIDToPortNo(4, voltha.Port_ETHERNET_NNI)) { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 629 | /* |
| 630 | for this release we are only interested in the first NNI for |
| 631 | Northbound. |
| 632 | we are not using the other 3 |
| 633 | */ |
| 634 | return |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 635 | } else if IntfIDToPortNo(0, voltha.Port_ETHERNET_NNI) == IntfID { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 636 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 637 | var portNNIStat NniPort |
| 638 | portNNIStat.IntfID = IntfID |
| 639 | portNNIStat.PortNum = uint32(0) |
| 640 | portNNIStat.RxBytes = PortStats.RxBytes |
| 641 | portNNIStat.RxPackets = PortStats.RxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 642 | portNNIStat.RxUcastPackets = PortStats.RxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 643 | portNNIStat.RxMcastPackets = PortStats.RxMcastPackets |
| 644 | portNNIStat.RxBcastPackets = PortStats.RxBcastPackets |
| 645 | portNNIStat.TxBytes = PortStats.TxBytes |
| 646 | portNNIStat.TxPackets = PortStats.TxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 647 | portNNIStat.TxUcastPackets = PortStats.TxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 648 | portNNIStat.TxMcastPackets = PortStats.TxMcastPackets |
| 649 | portNNIStat.TxBcastPackets = PortStats.TxBcastPackets |
| 650 | mutex.Lock() |
| 651 | StatMgr.NorthBoundPort[0] = &portNNIStat |
| 652 | mutex.Unlock() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 653 | logger.Debugw(ctx, "received-nni-stats", log.Fields{"nni-stats": StatMgr.NorthBoundPort}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 654 | } |
| 655 | for i := uint32(0); i < NumPonPorts; i++ { |
| 656 | |
| 657 | if IntfIDToPortNo(i, voltha.Port_PON_OLT) == IntfID { |
| 658 | var portPonStat PonPort |
| 659 | portPonStat.IntfID = IntfID |
| 660 | portPonStat.PortNum = i |
| 661 | portPonStat.PONID = i |
| 662 | portPonStat.RxBytes = PortStats.RxBytes |
| 663 | portPonStat.RxPackets = PortStats.RxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 664 | portPonStat.RxUcastPackets = PortStats.RxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 665 | portPonStat.RxMcastPackets = PortStats.RxMcastPackets |
| 666 | portPonStat.RxBcastPackets = PortStats.RxBcastPackets |
| 667 | portPonStat.TxBytes = PortStats.TxBytes |
| 668 | portPonStat.TxPackets = PortStats.TxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 669 | portPonStat.TxUcastPackets = PortStats.TxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 670 | portPonStat.TxMcastPackets = PortStats.TxMcastPackets |
| 671 | portPonStat.TxBcastPackets = PortStats.TxBcastPackets |
| 672 | mutex.Lock() |
| 673 | StatMgr.SouthBoundPort[i] = &portPonStat |
| 674 | mutex.Unlock() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 675 | logger.Debugw(ctx, "received-pon-stats-for-port", log.Fields{"port-pon-stats": portPonStat}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 676 | } |
| 677 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 678 | |
| 679 | /* |
| 680 | Based upon the intf_id map to an nni port or a pon port |
| 681 | the intf_id is the key to the north or south bound collections |
| 682 | |
| 683 | Based upon the intf_id the port object (nni_port or pon_port) will |
| 684 | have its data attr. updated by the current dataset collected. |
| 685 | |
| 686 | For prefixing the rule is currently to use the port number and not the intf_id |
| 687 | */ |
| 688 | //FIXME : Just use first NNI for now |
| 689 | /* TODO should the data be marshaled before sending it ? |
| 690 | if IntfID == IntfIdToPortNo(0, voltha.Port_ETHERNET_NNI) { |
| 691 | //NNI port (just the first one) |
| 692 | err = UpdatePortObjectKpiData(StatMgr.NorthBoundPorts[PortStats.IntfID], PMData) |
| 693 | } else { |
| 694 | //PON ports |
| 695 | err = UpdatePortObjectKpiData(SouthboundPorts[PortStats.IntfID], PMData) |
| 696 | } |
| 697 | if (err != nil) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 698 | logger.Error(ctx, "Error publishing statistics data") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 699 | } |
| 700 | */ |
| 701 | |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 702 | } |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 703 | |
| 704 | func (StatMgr *OpenOltStatisticsMgr) updateGetOltPortCountersResponse(ctx context.Context, singleValResp *extension.SingleGetValueResponse, stats map[string]float32) { |
| 705 | |
| 706 | metrics := singleValResp.GetResponse().GetPortCoutners() |
| 707 | metrics.TxBytes = uint64(stats["TxBytes"]) |
| 708 | metrics.RxBytes = uint64(stats["RxBytes"]) |
| 709 | metrics.TxPackets = uint64(stats["TxPackets"]) |
| 710 | metrics.RxPackets = uint64(stats["RxPackets"]) |
| 711 | metrics.TxErrorPackets = uint64(stats["TxErrorPackets"]) |
| 712 | metrics.RxErrorPackets = uint64(stats["RxErrorPackets"]) |
| 713 | metrics.TxBcastPackets = uint64(stats["TxBcastPackets"]) |
| 714 | metrics.RxBcastPackets = uint64(stats["RxBcastPackets"]) |
| 715 | metrics.TxUcastPackets = uint64(stats["TxUcastPackets"]) |
| 716 | metrics.RxUcastPackets = uint64(stats["RxUcastPackets"]) |
| 717 | metrics.TxMcastPackets = uint64(stats["TxMcastPackets"]) |
| 718 | metrics.RxMcastPackets = uint64(stats["RxMcastPackets"]) |
| 719 | |
| 720 | singleValResp.Response.Status = extension.GetValueResponse_OK |
| 721 | logger.Debugw(ctx, "updateGetOltPortCountersResponse", log.Fields{"resp": singleValResp}) |
| 722 | } |
| 723 | |
| 724 | //RegisterForStatIndication registers ch as a channel on which indication is sent when statistics of type t is received |
| 725 | func (StatMgr *OpenOltStatisticsMgr) RegisterForStatIndication(ctx context.Context, t StatType, ch chan bool, portNo uint32, portType extension.GetOltPortCounters_PortType) { |
| 726 | statInd := statRegInfo{ |
| 727 | chn: ch, |
| 728 | portNo: portNo, |
| 729 | portType: portType, |
| 730 | } |
| 731 | |
| 732 | logger.Debugf(ctx, "RegisterForStatIndication stat type %v portno %v porttype %v chan %v", t, portNo, portType, ch) |
| 733 | StatMgr.statIndListnerMu.Lock() |
| 734 | StatMgr.statIndListners[t].PushBack(statInd) |
| 735 | StatMgr.statIndListnerMu.Unlock() |
| 736 | |
| 737 | } |
| 738 | |
| 739 | //DeRegisterFromStatIndication removes the previously registered channel ch for type t of statistics |
| 740 | func (StatMgr *OpenOltStatisticsMgr) DeRegisterFromStatIndication(ctx context.Context, t StatType, ch chan bool) { |
| 741 | StatMgr.statIndListnerMu.Lock() |
| 742 | defer StatMgr.statIndListnerMu.Unlock() |
| 743 | |
| 744 | for e := StatMgr.statIndListners[t].Front(); e != nil; e = e.Next() { |
| 745 | statInd := e.Value.(statRegInfo) |
| 746 | if statInd.chn == ch { |
| 747 | StatMgr.statIndListners[t].Remove(e) |
| 748 | return |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | func (StatMgr *OpenOltStatisticsMgr) processStatIndication(ctx context.Context, t StatType, portNo uint32) { |
| 754 | var deRegList []*list.Element |
| 755 | var statInd statRegInfo |
| 756 | |
| 757 | StatMgr.statIndListnerMu.Lock() |
| 758 | defer StatMgr.statIndListnerMu.Unlock() |
| 759 | |
| 760 | if StatMgr.statIndListners[t] == nil || StatMgr.statIndListners[t].Len() == 0 { |
| 761 | logger.Debugf(ctx, "processStatIndication %v list is empty ", t) |
| 762 | return |
| 763 | } |
| 764 | |
| 765 | for e := StatMgr.statIndListners[t].Front(); e != nil; e = e.Next() { |
| 766 | statInd = e.Value.(statRegInfo) |
| 767 | if statInd.portNo != portNo { |
| 768 | fmt.Printf("Skipping %v\n", e.Value) |
| 769 | continue |
| 770 | } |
| 771 | // message sent |
| 772 | statInd.chn <- true |
| 773 | deRegList = append(deRegList, e) |
| 774 | |
| 775 | } |
| 776 | for _, e := range deRegList { |
| 777 | StatMgr.statIndListners[t].Remove(e) |
| 778 | } |
| 779 | |
| 780 | } |