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