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 ( |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 21 | "context" |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 22 | "fmt" |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 23 | "strconv" |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 24 | "sync" |
| 25 | "time" |
| 26 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 27 | "github.com/opencord/voltha-lib-go/v4/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" |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 29 | "github.com/opencord/voltha-protos/v4/go/openolt" |
| 30 | "github.com/opencord/voltha-protos/v4/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 |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 193 | func NewOpenOltStatsMgr(ctx context.Context, Dev *DeviceHandler) *OpenOltStatisticsMgr { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 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{} |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 202 | Ports, _ = InitPorts(ctx, "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() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 205 | Ports, _ = InitPorts(ctx, "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 |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 211 | 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] | 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++ { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 227 | Port := BuildPortObject(ctx, 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++ { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 234 | PONPort := BuildPortObject(ctx, 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 { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 239 | 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] | 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 |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 245 | 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] | 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) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 260 | logger.Debugw(ctx, "interface-type-nni", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 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) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 270 | logger.Debugw(ctx, "interface-type-pon", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 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 { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 276 | 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] | 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() |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 288 | metricNames := StatMgr.Device.metrics.GetSubscriberMetrics() |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 289 | |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 290 | var metrics []string |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 291 | for metric := range metricNames { |
| 292 | if metricNames[metric].Enabled { |
| 293 | metrics = append(metrics, metric) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 294 | } |
| 295 | } |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 296 | |
| 297 | for _, mName := range metrics { |
| 298 | switch mName { |
| 299 | case "rx_bytes": |
| 300 | nnival["RxBytes"] = float32(cm.RxBytes) |
| 301 | case "rx_packets": |
| 302 | nnival["RxPackets"] = float32(cm.RxPackets) |
| 303 | case "rx_ucast_packets": |
| 304 | nnival["RxUcastPackets"] = float32(cm.RxUcastPackets) |
| 305 | case "rx_mcast_packets": |
| 306 | nnival["RxMcastPackets"] = float32(cm.RxMcastPackets) |
| 307 | case "rx_bcast_packets": |
| 308 | nnival["RxBcastPackets"] = float32(cm.RxBcastPackets) |
| 309 | case "tx_bytes": |
| 310 | nnival["TxBytes"] = float32(cm.TxBytes) |
| 311 | case "tx_packets": |
| 312 | nnival["TxPackets"] = float32(cm.TxPackets) |
| 313 | case "tx_mcast_packets": |
| 314 | nnival["TxMcastPackets"] = float32(cm.TxMcastPackets) |
| 315 | case "tx_bcast_packets": |
| 316 | nnival["TxBcastPackets"] = float32(cm.TxBcastPackets) |
| 317 | } |
| 318 | } |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 319 | return nnival |
| 320 | } |
| 321 | |
| 322 | // collectPONMetrics will collect the pon port metrics |
| 323 | func (StatMgr *OpenOltStatisticsMgr) collectPONMetrics(pID uint32) map[string]float32 { |
| 324 | |
| 325 | ponval := make(map[string]float32) |
| 326 | mutex.Lock() |
| 327 | cm := StatMgr.Device.portStats.SouthBoundPort[pID] |
| 328 | mutex.Unlock() |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 329 | metricNames := StatMgr.Device.metrics.GetSubscriberMetrics() |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 330 | |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 331 | var metrics []string |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 332 | for metric := range metricNames { |
| 333 | if metricNames[metric].Enabled { |
| 334 | metrics = append(metrics, metric) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 335 | } |
| 336 | } |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 337 | |
| 338 | for _, mName := range metrics { |
| 339 | switch mName { |
| 340 | case "rx_bytes": |
| 341 | ponval["RxBytes"] = float32(cm.RxBytes) |
| 342 | case "rx_packets": |
| 343 | ponval["RxPackets"] = float32(cm.RxPackets) |
| 344 | case "rx_ucast_packets": |
| 345 | ponval["RxUcastPackets"] = float32(cm.RxUcastPackets) |
| 346 | case "rx_mcast_packets": |
| 347 | ponval["RxMcastPackets"] = float32(cm.RxMcastPackets) |
| 348 | case "rx_bcast_packets": |
| 349 | ponval["RxBcastPackets"] = float32(cm.RxBcastPackets) |
| 350 | case "tx_bytes": |
| 351 | ponval["TxBytes"] = float32(cm.TxBytes) |
| 352 | case "tx_packets": |
| 353 | ponval["TxPackets"] = float32(cm.TxPackets) |
| 354 | case "tx_mcast_packets": |
| 355 | ponval["TxMcastPackets"] = float32(cm.TxMcastPackets) |
| 356 | case "tx_bcast_packets": |
| 357 | ponval["TxBcastPackets"] = float32(cm.TxBcastPackets) |
| 358 | } |
| 359 | } |
| 360 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 361 | return ponval |
| 362 | } |
| 363 | |
| 364 | // publishMatrics will publish the pon port metrics |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 365 | func (StatMgr OpenOltStatisticsMgr) publishMetrics(ctx context.Context, val map[string]float32, |
Girish Gowdra | 34815db | 2020-05-11 17:18:04 -0700 | [diff] [blame] | 366 | port *voltha.Port, devID string, devType string) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 367 | logger.Debugw(ctx, "publish-metrics", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 368 | log.Fields{ |
| 369 | "port": port.Label, |
| 370 | "metrics": val}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 371 | |
| 372 | var metricInfo voltha.MetricInformation |
| 373 | var ke voltha.KpiEvent2 |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 374 | var volthaEventSubCatgry voltha.EventSubCategory_Types |
Girish Gowdra | 34815db | 2020-05-11 17:18:04 -0700 | [diff] [blame] | 375 | metricsContext := make(map[string]string) |
| 376 | metricsContext["oltid"] = devID |
| 377 | metricsContext["devicetype"] = devType |
| 378 | metricsContext["portlabel"] = port.Label |
| 379 | metricsContext["portno"] = strconv.Itoa(int(port.PortNo)) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 380 | |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 381 | if port.Type == voltha.Port_ETHERNET_NNI { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 382 | volthaEventSubCatgry = voltha.EventSubCategory_NNI |
| 383 | } else { |
| 384 | volthaEventSubCatgry = voltha.EventSubCategory_PON |
| 385 | } |
| 386 | |
| 387 | raisedTs := time.Now().UnixNano() |
| 388 | mmd := voltha.MetricMetaData{ |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 389 | Title: port.Type.String(), |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 390 | Ts: float64(raisedTs), |
Girish Gowdra | 34815db | 2020-05-11 17:18:04 -0700 | [diff] [blame] | 391 | Context: metricsContext, |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 392 | DeviceId: devID, |
| 393 | } |
| 394 | |
| 395 | metricInfo.Metadata = &mmd |
| 396 | metricInfo.Metrics = val |
| 397 | |
| 398 | ke.SliceData = []*voltha.MetricInformation{&metricInfo} |
| 399 | ke.Type = voltha.KpiEventType_slice |
| 400 | ke.Ts = float64(time.Now().UnixNano()) |
| 401 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 402 | if err := StatMgr.Device.EventProxy.SendKpiEvent(ctx, "STATS_EVENT", &ke, voltha.EventCategory_EQUIPMENT, volthaEventSubCatgry, raisedTs); err != nil { |
| 403 | logger.Errorw(ctx, "failed-to-send-pon-stats", log.Fields{"err": err}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 404 | } |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 405 | } |
| 406 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 407 | // PortStatisticsIndication handles the port statistics indication |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 408 | func (StatMgr *OpenOltStatisticsMgr) PortStatisticsIndication(ctx context.Context, PortStats *openolt.PortStatistics, NumPonPorts uint32) { |
| 409 | StatMgr.PortsStatisticsKpis(ctx, PortStats, NumPonPorts) |
| 410 | logger.Debugw(ctx, "received-port-stats-indication", log.Fields{"port-stats": PortStats}) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 411 | // TODO send stats to core topic to the voltha kafka or a different kafka ? |
| 412 | } |
| 413 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 414 | // FlowStatisticsIndication to be implemented |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 415 | func FlowStatisticsIndication(ctx context.Context, self, FlowStats *openolt.FlowStatistics) { |
| 416 | logger.Debugw(ctx, "flow-stats-collected", log.Fields{"flow-stats": FlowStats}) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 417 | //TODO send to kafka ? |
| 418 | } |
| 419 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 420 | // 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] | 421 | 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] | 422 | |
| 423 | /*map the port stats values into a dictionary |
| 424 | Create a kpoEvent and publish to Kafka |
| 425 | |
| 426 | :param port_stats: |
| 427 | :return: |
| 428 | */ |
| 429 | //var err error |
| 430 | IntfID := PortStats.IntfId |
| 431 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 432 | if (IntfIDToPortNo(1, voltha.Port_ETHERNET_NNI) < IntfID) && |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 433 | (IntfID < IntfIDToPortNo(4, voltha.Port_ETHERNET_NNI)) { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 434 | /* |
| 435 | for this release we are only interested in the first NNI for |
| 436 | Northbound. |
| 437 | we are not using the other 3 |
| 438 | */ |
| 439 | return |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 440 | } else if IntfIDToPortNo(0, voltha.Port_ETHERNET_NNI) == IntfID { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 441 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 442 | var portNNIStat NniPort |
| 443 | portNNIStat.IntfID = IntfID |
| 444 | portNNIStat.PortNum = uint32(0) |
| 445 | portNNIStat.RxBytes = PortStats.RxBytes |
| 446 | portNNIStat.RxPackets = PortStats.RxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 447 | portNNIStat.RxUcastPackets = PortStats.RxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 448 | portNNIStat.RxMcastPackets = PortStats.RxMcastPackets |
| 449 | portNNIStat.RxBcastPackets = PortStats.RxBcastPackets |
| 450 | portNNIStat.TxBytes = PortStats.TxBytes |
| 451 | portNNIStat.TxPackets = PortStats.TxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 452 | portNNIStat.TxUcastPackets = PortStats.TxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 453 | portNNIStat.TxMcastPackets = PortStats.TxMcastPackets |
| 454 | portNNIStat.TxBcastPackets = PortStats.TxBcastPackets |
| 455 | mutex.Lock() |
| 456 | StatMgr.NorthBoundPort[0] = &portNNIStat |
| 457 | mutex.Unlock() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 458 | logger.Debugw(ctx, "received-nni-stats", log.Fields{"nni-stats": StatMgr.NorthBoundPort}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 459 | } |
| 460 | for i := uint32(0); i < NumPonPorts; i++ { |
| 461 | |
| 462 | if IntfIDToPortNo(i, voltha.Port_PON_OLT) == IntfID { |
| 463 | var portPonStat PonPort |
| 464 | portPonStat.IntfID = IntfID |
| 465 | portPonStat.PortNum = i |
| 466 | portPonStat.PONID = i |
| 467 | portPonStat.RxBytes = PortStats.RxBytes |
| 468 | portPonStat.RxPackets = PortStats.RxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 469 | portPonStat.RxUcastPackets = PortStats.RxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 470 | portPonStat.RxMcastPackets = PortStats.RxMcastPackets |
| 471 | portPonStat.RxBcastPackets = PortStats.RxBcastPackets |
| 472 | portPonStat.TxBytes = PortStats.TxBytes |
| 473 | portPonStat.TxPackets = PortStats.TxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 474 | portPonStat.TxUcastPackets = PortStats.TxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 475 | portPonStat.TxMcastPackets = PortStats.TxMcastPackets |
| 476 | portPonStat.TxBcastPackets = PortStats.TxBcastPackets |
| 477 | mutex.Lock() |
| 478 | StatMgr.SouthBoundPort[i] = &portPonStat |
| 479 | mutex.Unlock() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 480 | 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] | 481 | } |
| 482 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 483 | |
| 484 | /* |
| 485 | Based upon the intf_id map to an nni port or a pon port |
| 486 | the intf_id is the key to the north or south bound collections |
| 487 | |
| 488 | Based upon the intf_id the port object (nni_port or pon_port) will |
| 489 | have its data attr. updated by the current dataset collected. |
| 490 | |
| 491 | For prefixing the rule is currently to use the port number and not the intf_id |
| 492 | */ |
| 493 | //FIXME : Just use first NNI for now |
| 494 | /* TODO should the data be marshaled before sending it ? |
| 495 | if IntfID == IntfIdToPortNo(0, voltha.Port_ETHERNET_NNI) { |
| 496 | //NNI port (just the first one) |
| 497 | err = UpdatePortObjectKpiData(StatMgr.NorthBoundPorts[PortStats.IntfID], PMData) |
| 498 | } else { |
| 499 | //PON ports |
| 500 | err = UpdatePortObjectKpiData(SouthboundPorts[PortStats.IntfID], PMData) |
| 501 | } |
| 502 | if (err != nil) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 503 | logger.Error(ctx, "Error publishing statistics data") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 504 | } |
| 505 | */ |
| 506 | |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 507 | } |