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 ( |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 21 | "fmt" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 22 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 23 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 24 | "github.com/opencord/voltha-protos/v3/go/openolt" |
| 25 | "github.com/opencord/voltha-protos/v3/go/voltha" |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 26 | "sync" |
| 27 | "time" |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 28 | ) |
| 29 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 30 | var mutex = &sync.Mutex{} |
| 31 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 32 | // PonPort representation |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 33 | type PonPort struct { |
| 34 | /* |
| 35 | This is a highly reduced version taken from the adtran pon_port. |
| 36 | TODO: Extend for use in the openolt adapter set. |
| 37 | */ |
| 38 | /* MAX_ONUS_SUPPORTED = 256 |
| 39 | DEFAULT_ENABLED = False |
| 40 | MAX_DEPLOYMENT_RANGE = 25000 # Meters (OLT-PB maximum) |
| 41 | |
| 42 | _MCAST_ONU_ID = 253 |
| 43 | _MCAST_ALLOC_BASE = 0x500 |
| 44 | |
| 45 | _SUPPORTED_ACTIVATION_METHODS = ['autodiscovery'] # , 'autoactivate'] |
| 46 | _SUPPORTED_AUTHENTICATION_METHODS = ['serial-number'] |
| 47 | */ |
| 48 | PONID uint32 |
| 49 | DeviceID string |
| 50 | IntfID uint32 |
| 51 | PortNum uint32 |
| 52 | PortID uint32 |
| 53 | Label string |
| 54 | ONUs map[uint32]interface{} |
| 55 | ONUsByID map[uint32]interface{} |
| 56 | |
| 57 | RxBytes uint64 |
| 58 | RxPackets uint64 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 59 | RxUcastPackets uint64 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 60 | RxMcastPackets uint64 |
| 61 | RxBcastPackets uint64 |
| 62 | RxErrorPackets uint64 |
| 63 | TxBytes uint64 |
| 64 | TxPackets uint64 |
| 65 | TxUcastPackets uint64 |
| 66 | TxMcastPackets uint64 |
| 67 | TxBcastPackets uint64 |
| 68 | TxErrorPackets uint64 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 69 | RxCrcErrors uint64 |
| 70 | BipErrors uint64 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 71 | } |
| 72 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 73 | // 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] | 74 | func NewPONPort(PONID uint32, DeviceID string, IntfID uint32, PortNum uint32) *PonPort { |
| 75 | |
| 76 | var PON PonPort |
| 77 | |
| 78 | PON.PONID = PONID |
| 79 | PON.DeviceID = DeviceID |
| 80 | PON.IntfID = IntfID |
| 81 | PON.PortNum = PortNum |
| 82 | PON.PortID = 0 |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 83 | PON.Label = fmt.Sprintf("%s%d", "pon-", PONID) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 84 | |
| 85 | PON.ONUs = make(map[uint32]interface{}) |
| 86 | PON.ONUsByID = make(map[uint32]interface{}) |
| 87 | |
| 88 | /* |
| 89 | Statistics taken from nni_port |
| 90 | self.intf_id = 0 #handled by getter |
| 91 | self.port_no = 0 #handled by getter |
| 92 | self.port_id = 0 #handled by getter |
| 93 | |
| 94 | Note: In the current implementation of the kpis coming from the BAL the stats are the |
| 95 | samne model for NNI and PON. |
| 96 | |
| 97 | TODO: Integrate additional kpis for the PON and other southbound port objecgts. |
| 98 | |
| 99 | */ |
| 100 | |
| 101 | PON.RxBytes = 0 |
| 102 | PON.RxPackets = 0 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 103 | PON.RxUcastPackets = 0 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 104 | PON.RxMcastPackets = 0 |
| 105 | PON.RxBcastPackets = 0 |
| 106 | PON.RxErrorPackets = 0 |
| 107 | PON.TxBytes = 0 |
| 108 | PON.TxPackets = 0 |
| 109 | PON.TxUcastPackets = 0 |
| 110 | PON.TxMcastPackets = 0 |
| 111 | PON.TxBcastPackets = 0 |
| 112 | PON.TxErrorPackets = 0 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 113 | PON.RxCrcErrors = 0 |
| 114 | PON.BipErrors = 0 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 115 | |
| 116 | /* def __str__(self): |
| 117 | return "PonPort-{}: Admin: {}, Oper: {}, OLT: {}".format(self._label, |
| 118 | self._admin_state, |
| 119 | self._oper_status, |
| 120 | self.olt) |
| 121 | */ |
| 122 | return &PON |
| 123 | } |
| 124 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 125 | // NniPort representation |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 126 | type NniPort struct { |
| 127 | /* |
| 128 | Northbound network port, often Ethernet-based |
| 129 | |
| 130 | This is a highly reduced version taken from the adtran nni_port code set |
| 131 | TODO: add functions to allow for port specific values and operations |
| 132 | */ |
| 133 | PortNum uint32 |
| 134 | Name string |
| 135 | LogicalPort uint32 |
| 136 | IntfID uint32 |
| 137 | |
| 138 | RxBytes uint64 |
| 139 | RxPackets uint64 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 140 | RxUcastPackets uint64 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 141 | RxMcastPackets uint64 |
| 142 | RxBcastPackets uint64 |
| 143 | RxErrorPackets uint64 |
| 144 | TxBytes uint64 |
| 145 | TxPackets uint64 |
| 146 | TxUcastPackets uint64 |
| 147 | TxMcastPackets uint64 |
| 148 | TxBcastPackets uint64 |
| 149 | TxErrorPackets uint64 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 150 | RxCrcErrors uint64 |
| 151 | BipErrors uint64 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 152 | } |
| 153 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 154 | // 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] | 155 | func NewNniPort(PortNum uint32, IntfID uint32) *NniPort { |
| 156 | |
| 157 | var NNI NniPort |
| 158 | |
| 159 | NNI.PortNum = PortNum |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 160 | NNI.Name = fmt.Sprintf("%s%d", "nni-", PortNum) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 161 | NNI.IntfID = IntfID |
| 162 | |
| 163 | NNI.RxBytes = 0 |
| 164 | NNI.RxPackets = 0 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 165 | NNI.RxUcastPackets = 0 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 166 | NNI.RxMcastPackets = 0 |
| 167 | NNI.RxBcastPackets = 0 |
| 168 | NNI.RxErrorPackets = 0 |
| 169 | NNI.TxBytes = 0 |
| 170 | NNI.TxPackets = 0 |
| 171 | NNI.TxUcastPackets = 0 |
| 172 | NNI.TxMcastPackets = 0 |
| 173 | NNI.TxBcastPackets = 0 |
| 174 | NNI.TxErrorPackets = 0 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 175 | NNI.RxCrcErrors = 0 |
| 176 | NNI.BipErrors = 0 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 177 | |
| 178 | return &NNI |
| 179 | } |
| 180 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 181 | // OpenOltStatisticsMgr structure |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 182 | type OpenOltStatisticsMgr struct { |
| 183 | Device *DeviceHandler |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 184 | NorthBoundPort map[uint32]*NniPort |
| 185 | SouthBoundPort map[uint32]*PonPort |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 186 | // TODO PMMetrics Metrics |
| 187 | } |
| 188 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 189 | // NewOpenOltStatsMgr returns a new instance of the OpenOltStatisticsMgr |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 190 | func NewOpenOltStatsMgr(Dev *DeviceHandler) *OpenOltStatisticsMgr { |
| 191 | |
| 192 | var StatMgr OpenOltStatisticsMgr |
| 193 | |
| 194 | StatMgr.Device = Dev |
| 195 | // TODO call metric PMMetric = |
| 196 | // Northbound and Southbound ports |
| 197 | // added to initialize the pm_metrics |
| 198 | var Ports interface{} |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 199 | Ports, _ = InitPorts("nni", Dev.deviceID, 1) |
| 200 | StatMgr.NorthBoundPort, _ = Ports.(map[uint32]*NniPort) |
| 201 | NumPonPorts := Dev.resourceMgr.DevInfo.GetPonPorts() |
| 202 | Ports, _ = InitPorts("pon", Dev.deviceID, NumPonPorts) |
| 203 | StatMgr.SouthBoundPort, _ = Ports.(map[uint32]*PonPort) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 204 | return &StatMgr |
| 205 | } |
| 206 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 207 | // InitPorts collects the port objects: nni and pon that are updated with the current data from the OLT |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 208 | func InitPorts(Intftype string, DeviceID string, numOfPorts uint32) (interface{}, error) { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 209 | /* |
| 210 | This method collects the port objects: nni and pon that are updated with the |
| 211 | current data from the OLT |
| 212 | |
| 213 | Both the northbound (nni) and southbound ports are indexed by the interface id (intf_id) |
| 214 | and NOT the port number. When the port object is instantiated it will contain the intf_id and |
| 215 | port_no values |
| 216 | |
| 217 | :param type: |
| 218 | :return: |
| 219 | */ |
| 220 | var i uint32 |
| 221 | if Intftype == "nni" { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 222 | NniPorts := make(map[uint32]*NniPort) |
| 223 | for i = 0; i < numOfPorts; i++ { |
kdarapu | 768708d | 2019-09-16 23:19:15 +0530 | [diff] [blame] | 224 | Port := BuildPortObject(i, "nni", DeviceID).(*NniPort) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 225 | NniPorts[Port.IntfID] = Port |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 226 | } |
| 227 | return NniPorts, nil |
| 228 | } else if Intftype == "pon" { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 229 | PONPorts := make(map[uint32]*PonPort) |
| 230 | for i = 0; i < numOfPorts; i++ { |
kdarapu | 768708d | 2019-09-16 23:19:15 +0530 | [diff] [blame] | 231 | PONPort := BuildPortObject(i, "pon", DeviceID).(*PonPort) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 232 | PONPorts[PortNoToIntfID(PONPort.IntfID, voltha.Port_PON_OLT)] = PONPort |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 233 | } |
| 234 | return PONPorts, nil |
| 235 | } else { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 236 | logger.Errorf("Invalid type of interface %s", Intftype) |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 237 | return nil, olterrors.NewErrInvalidValue(log.Fields{"interface-type": Intftype}, nil) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 241 | // BuildPortObject allows for updating north and southbound ports, newly discovered ports, and devices |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 242 | func BuildPortObject(PortNum uint32, IntfType string, DeviceID string) interface{} { |
| 243 | /* |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 244 | Separate method to allow for updating north and southbound ports |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 245 | newly discovered ports and devices |
| 246 | |
| 247 | :param port_num: |
| 248 | :param type: |
| 249 | :return: |
| 250 | */ |
| 251 | |
| 252 | //This builds a port object which is added to the |
| 253 | //appropriate northbound or southbound values |
| 254 | if IntfType == "nni" { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 255 | IntfID := IntfIDToPortNo(PortNum, voltha.Port_ETHERNET_NNI) |
| 256 | nniID := PortNoToIntfID(IntfID, voltha.Port_ETHERNET_NNI) |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 257 | logger.Debugf("NniID %v", nniID) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 258 | return NewNniPort(PortNum, nniID) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 259 | } else if IntfType == "pon" { |
| 260 | // PON ports require a different configuration |
| 261 | // intf_id and pon_id are currently equal. |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 262 | IntfID := IntfIDToPortNo(PortNum, voltha.Port_PON_OLT) |
| 263 | PONID := PortNoToIntfID(IntfID, voltha.Port_PON_OLT) |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 264 | logger.Debugf("PonID %v", PONID) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 265 | return NewPONPort(PONID, DeviceID, IntfID, PortNum) |
| 266 | } else { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 267 | logger.Errorf("Invalid type of interface %s", IntfType) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 268 | return nil |
| 269 | } |
| 270 | } |
| 271 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 272 | // collectNNIMetrics will collect the nni port metrics |
| 273 | func (StatMgr *OpenOltStatisticsMgr) collectNNIMetrics(nniID uint32) map[string]float32 { |
| 274 | |
| 275 | nnival := make(map[string]float32) |
| 276 | mutex.Lock() |
| 277 | cm := StatMgr.Device.portStats.NorthBoundPort[nniID] |
| 278 | mutex.Unlock() |
| 279 | metricName := StatMgr.Device.metrics.GetSubscriberMetrics() |
| 280 | |
| 281 | if metricName != nil && len(metricName) > 0 { |
| 282 | for mName := range metricName { |
| 283 | switch mName { |
| 284 | case "rx_bytes": |
| 285 | nnival["RxBytes"] = float32(cm.RxBytes) |
| 286 | case "rx_packets": |
| 287 | nnival["RxPackets"] = float32(cm.RxPackets) |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 288 | case "rx_ucast_packets": |
| 289 | nnival["RxUcastPackets"] = float32(cm.RxUcastPackets) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 290 | case "rx_mcast_packets": |
| 291 | nnival["RxMcastPackets"] = float32(cm.RxMcastPackets) |
| 292 | case "rx_bcast_packets": |
| 293 | nnival["RxBcastPackets"] = float32(cm.RxBcastPackets) |
| 294 | case "tx_bytes": |
| 295 | nnival["TxBytes"] = float32(cm.TxBytes) |
| 296 | case "tx_packets": |
| 297 | nnival["TxPackets"] = float32(cm.TxPackets) |
| 298 | case "tx_mcast_packets": |
| 299 | nnival["TxMcastPackets"] = float32(cm.TxMcastPackets) |
| 300 | case "tx_bcast_packets": |
| 301 | nnival["TxBcastPackets"] = float32(cm.TxBcastPackets) |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | return nnival |
| 306 | } |
| 307 | |
| 308 | // collectPONMetrics will collect the pon port metrics |
| 309 | func (StatMgr *OpenOltStatisticsMgr) collectPONMetrics(pID uint32) map[string]float32 { |
| 310 | |
| 311 | ponval := make(map[string]float32) |
| 312 | mutex.Lock() |
| 313 | cm := StatMgr.Device.portStats.SouthBoundPort[pID] |
| 314 | mutex.Unlock() |
| 315 | metricName := StatMgr.Device.metrics.GetSubscriberMetrics() |
| 316 | |
| 317 | if metricName != nil && len(metricName) > 0 { |
| 318 | for mName := range metricName { |
| 319 | switch mName { |
| 320 | case "rx_bytes": |
| 321 | ponval["RxBytes"] = float32(cm.RxBytes) |
| 322 | case "rx_packets": |
| 323 | ponval["RxPackets"] = float32(cm.RxPackets) |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 324 | // these are not supported in OpenOlt Agent now |
| 325 | // will return zero until supported |
| 326 | case "rx_ucast_packets": |
| 327 | ponval["RxUcastPackets"] = float32(cm.RxUcastPackets) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 328 | case "rx_mcast_packets": |
| 329 | ponval["RxMcastPackets"] = float32(cm.RxMcastPackets) |
| 330 | case "rx_bcast_packets": |
| 331 | ponval["RxBcastPackets"] = float32(cm.RxBcastPackets) |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 332 | // End will return zero until supported |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 333 | case "tx_bytes": |
| 334 | ponval["TxBytes"] = float32(cm.TxBytes) |
| 335 | case "tx_packets": |
| 336 | ponval["TxPackets"] = float32(cm.TxPackets) |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 337 | // these are not supported in OpenOlt Agent now |
| 338 | // will return zero until supported |
| 339 | case "tx_ucast_packets": |
| 340 | ponval["TxUcastPackets"] = float32(cm.TxUcastPackets) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 341 | case "tx_mcast_packets": |
| 342 | ponval["TxMcastPackets"] = float32(cm.TxMcastPackets) |
| 343 | case "tx_bcast_packets": |
| 344 | ponval["TxBcastPackets"] = float32(cm.TxBcastPackets) |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | return ponval |
| 349 | } |
| 350 | |
| 351 | // publishMatrics will publish the pon port metrics |
| 352 | func (StatMgr OpenOltStatisticsMgr) publishMetrics(portType string, val map[string]float32, portnum uint32, context map[string]string, devID string) { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 353 | logger.Debugf("Post-%v %v", portType, val) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 354 | |
| 355 | var metricInfo voltha.MetricInformation |
| 356 | var ke voltha.KpiEvent2 |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 357 | var volthaEventSubCatgry voltha.EventSubCategory_Types |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 358 | |
| 359 | if portType == "NNIStats" { |
| 360 | volthaEventSubCatgry = voltha.EventSubCategory_NNI |
| 361 | } else { |
| 362 | volthaEventSubCatgry = voltha.EventSubCategory_PON |
| 363 | } |
| 364 | |
| 365 | raisedTs := time.Now().UnixNano() |
| 366 | mmd := voltha.MetricMetaData{ |
| 367 | Title: portType, |
| 368 | Ts: float64(raisedTs), |
| 369 | Context: context, |
| 370 | DeviceId: devID, |
| 371 | } |
| 372 | |
| 373 | metricInfo.Metadata = &mmd |
| 374 | metricInfo.Metrics = val |
| 375 | |
| 376 | ke.SliceData = []*voltha.MetricInformation{&metricInfo} |
| 377 | ke.Type = voltha.KpiEventType_slice |
| 378 | ke.Ts = float64(time.Now().UnixNano()) |
| 379 | |
| 380 | if err := StatMgr.Device.EventProxy.SendKpiEvent("STATS_EVENT", &ke, voltha.EventCategory_EQUIPMENT, volthaEventSubCatgry, raisedTs); err != nil { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 381 | logger.Errorw("Failed to send Pon stats", log.Fields{"err": err}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | } |
| 385 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 386 | // PortStatisticsIndication handles the port statistics indication |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 387 | func (StatMgr *OpenOltStatisticsMgr) PortStatisticsIndication(PortStats *openolt.PortStatistics, NumPonPorts uint32) { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 388 | logger.Debugf("port-stats-collected %v", PortStats) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 389 | StatMgr.PortsStatisticsKpis(PortStats, NumPonPorts) |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 390 | logger.Infow("Received port stats indication", log.Fields{"PortStats": PortStats}) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 391 | // TODO send stats to core topic to the voltha kafka or a different kafka ? |
| 392 | } |
| 393 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 394 | // FlowStatisticsIndication to be implemented |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 395 | func FlowStatisticsIndication(self, FlowStats *openolt.FlowStatistics) { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 396 | logger.Debugf("flow-stats-collected %v", FlowStats) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 397 | //TODO send to kafka ? |
| 398 | } |
| 399 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 400 | // PortsStatisticsKpis map the port stats values into a dictionary, creates the kpiEvent and then publish to Kafka |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 401 | func (StatMgr *OpenOltStatisticsMgr) PortsStatisticsKpis(PortStats *openolt.PortStatistics, NumPonPorts uint32) { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 402 | |
| 403 | /*map the port stats values into a dictionary |
| 404 | Create a kpoEvent and publish to Kafka |
| 405 | |
| 406 | :param port_stats: |
| 407 | :return: |
| 408 | */ |
| 409 | //var err error |
| 410 | IntfID := PortStats.IntfId |
| 411 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 412 | if (IntfIDToPortNo(1, voltha.Port_ETHERNET_NNI) < IntfID) && |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 413 | (IntfID < IntfIDToPortNo(4, voltha.Port_ETHERNET_NNI)) { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 414 | /* |
| 415 | for this release we are only interested in the first NNI for |
| 416 | Northbound. |
| 417 | we are not using the other 3 |
| 418 | */ |
| 419 | return |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 420 | } else if IntfIDToPortNo(0, voltha.Port_ETHERNET_NNI) == IntfID { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 421 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 422 | var portNNIStat NniPort |
| 423 | portNNIStat.IntfID = IntfID |
| 424 | portNNIStat.PortNum = uint32(0) |
| 425 | portNNIStat.RxBytes = PortStats.RxBytes |
| 426 | portNNIStat.RxPackets = PortStats.RxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 427 | portNNIStat.RxUcastPackets = PortStats.RxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 428 | portNNIStat.RxMcastPackets = PortStats.RxMcastPackets |
| 429 | portNNIStat.RxBcastPackets = PortStats.RxBcastPackets |
| 430 | portNNIStat.TxBytes = PortStats.TxBytes |
| 431 | portNNIStat.TxPackets = PortStats.TxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 432 | portNNIStat.TxUcastPackets = PortStats.TxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 433 | portNNIStat.TxMcastPackets = PortStats.TxMcastPackets |
| 434 | portNNIStat.TxBcastPackets = PortStats.TxBcastPackets |
| 435 | mutex.Lock() |
| 436 | StatMgr.NorthBoundPort[0] = &portNNIStat |
| 437 | mutex.Unlock() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 438 | logger.Debugf("Received-NNI-Stats: %v", StatMgr.NorthBoundPort) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 439 | } |
| 440 | for i := uint32(0); i < NumPonPorts; i++ { |
| 441 | |
| 442 | if IntfIDToPortNo(i, voltha.Port_PON_OLT) == IntfID { |
| 443 | var portPonStat PonPort |
| 444 | portPonStat.IntfID = IntfID |
| 445 | portPonStat.PortNum = i |
| 446 | portPonStat.PONID = i |
| 447 | portPonStat.RxBytes = PortStats.RxBytes |
| 448 | portPonStat.RxPackets = PortStats.RxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 449 | portPonStat.RxUcastPackets = PortStats.RxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 450 | portPonStat.RxMcastPackets = PortStats.RxMcastPackets |
| 451 | portPonStat.RxBcastPackets = PortStats.RxBcastPackets |
| 452 | portPonStat.TxBytes = PortStats.TxBytes |
| 453 | portPonStat.TxPackets = PortStats.TxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 454 | portPonStat.TxUcastPackets = PortStats.TxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 455 | portPonStat.TxMcastPackets = PortStats.TxMcastPackets |
| 456 | portPonStat.TxBcastPackets = PortStats.TxBcastPackets |
| 457 | mutex.Lock() |
| 458 | StatMgr.SouthBoundPort[i] = &portPonStat |
| 459 | mutex.Unlock() |
Girish Gowdra | 316cdd1 | 2020-03-30 08:13:33 -0700 | [diff] [blame^] | 460 | logger.Debugf("Received-PON-Stats-for-Port %v : %v", i, portPonStat) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 461 | } |
| 462 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 463 | |
| 464 | /* |
| 465 | Based upon the intf_id map to an nni port or a pon port |
| 466 | the intf_id is the key to the north or south bound collections |
| 467 | |
| 468 | Based upon the intf_id the port object (nni_port or pon_port) will |
| 469 | have its data attr. updated by the current dataset collected. |
| 470 | |
| 471 | For prefixing the rule is currently to use the port number and not the intf_id |
| 472 | */ |
| 473 | //FIXME : Just use first NNI for now |
| 474 | /* TODO should the data be marshaled before sending it ? |
| 475 | if IntfID == IntfIdToPortNo(0, voltha.Port_ETHERNET_NNI) { |
| 476 | //NNI port (just the first one) |
| 477 | err = UpdatePortObjectKpiData(StatMgr.NorthBoundPorts[PortStats.IntfID], PMData) |
| 478 | } else { |
| 479 | //PON ports |
| 480 | err = UpdatePortObjectKpiData(SouthboundPorts[PortStats.IntfID], PMData) |
| 481 | } |
| 482 | if (err != nil) { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 483 | logger.Error("Error publishing statistics data") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 484 | } |
| 485 | */ |
| 486 | |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 487 | } |