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