| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1 | /* |
| Joey Armstrong | 11f5a57 | 2024-01-12 19:11:32 -0500 | [diff] [blame] | 2 | * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 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 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 17 | // Package core provides the utility for olt devices, flows and statistics |
| Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 18 | package core |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 21 | "context" |
| Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 22 | "encoding/binary" |
| Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 23 | "encoding/hex" |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 24 | "encoding/json" |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 25 | "errors" |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 26 | "fmt" |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 27 | "net" |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 28 | "strconv" |
| 29 | "strings" |
| 30 | "sync" |
| 31 | "time" |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 32 | |
| Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 33 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
| 34 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 35 | |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 36 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 37 | |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 38 | "github.com/cenkalti/backoff/v3" |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 39 | "github.com/gogo/protobuf/proto" |
| Girish Kumar | 93e9174 | 2020-07-27 16:43:19 +0000 | [diff] [blame] | 40 | grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" |
| 41 | grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing" |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 42 | "github.com/opencord/voltha-lib-go/v7/pkg/config" |
| 43 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
| 44 | flow_utils "github.com/opencord/voltha-lib-go/v7/pkg/flows" |
| 45 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 46 | plt "github.com/opencord/voltha-lib-go/v7/pkg/platform" |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 47 | "github.com/opencord/voltha-lib-go/v7/pkg/pmmetrics" |
| Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 48 | |
| nikesh.krishnan | d981254 | 2023-08-01 18:31:39 +0530 | [diff] [blame] | 49 | grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry" |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 50 | conf "github.com/opencord/voltha-openolt-adapter/internal/pkg/config" |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 51 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
| Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 52 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 53 | "github.com/opencord/voltha-protos/v5/go/common" |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 54 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 55 | "github.com/opencord/voltha-protos/v5/go/extension" |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 56 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
| 57 | "github.com/opencord/voltha-protos/v5/go/onu_inter_adapter_service" |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 58 | of "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 59 | oop "github.com/opencord/voltha-protos/v5/go/openolt" |
| Akash Reddy Kankanala | c6b6ca1 | 2025-06-12 14:26:57 +0530 | [diff] [blame] | 60 | tp_pb "github.com/opencord/voltha-protos/v5/go/tech_profile" |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 61 | "github.com/opencord/voltha-protos/v5/go/voltha" |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 62 | "google.golang.org/grpc" |
| nikesh.krishnan | d981254 | 2023-08-01 18:31:39 +0530 | [diff] [blame] | 63 | codes "google.golang.org/grpc/codes" |
| Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 64 | "google.golang.org/grpc/status" |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 65 | ) |
| 66 | |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 67 | // Constants for number of retries and for timeout |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 68 | const ( |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 69 | InvalidPort = 0xffffffff |
| 70 | MaxNumOfGroupHandlerChannels = 256 |
| 71 | |
| 72 | McastFlowOrGroupAdd = "McastFlowOrGroupAdd" |
| 73 | McastFlowOrGroupModify = "McastFlowOrGroupModify" |
| 74 | McastFlowOrGroupRemove = "McastFlowOrGroupRemove" |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 75 | oltPortInfoTimeout = 3 |
| Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 76 | |
| 77 | defaultPortSpeedMbps = 1000 |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 78 | heartbeatPath = "heartbeat" |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 79 | ) |
| 80 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 81 | // DeviceHandler will interact with the OLT device. |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 82 | type DeviceHandler struct { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 83 | EventProxy eventif.EventProxy |
| 84 | Client oop.OpenoltClient |
| 85 | cm *config.ConfigManager |
| 86 | device *voltha.Device |
| 87 | cfg *conf.AdapterFlags |
| 88 | coreClient *vgrpc.Client |
| 89 | childAdapterClients map[string]*vgrpc.Client |
| 90 | openOLT *OpenOLT |
| 91 | exitChannel chan struct{} |
| 92 | transitionMap *TransitionMap |
| 93 | clientCon *grpc.ClientConn |
| 94 | groupMgr *OpenOltGroupMgr |
| 95 | eventMgr *OpenOltEventMgr |
| 96 | kvStore *db.Backend // backend kv store connection handle |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 97 | |
| 98 | deviceInfo *oop.DeviceInfo |
| Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 99 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 100 | portStats *OpenOltStatisticsMgr |
| 101 | metrics *pmmetrics.PmMetrics |
| 102 | stopCollector chan bool |
| 103 | stopHeartbeatCheck chan bool |
| 104 | stopIndications chan bool |
| 105 | perPonOnuIndicationChannel map[uint32]onuIndicationChannels |
| 106 | |
| Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 107 | // discOnus (map[onuSn]bool) contains a list of ONUs that have been discovered, indexed by ONU SerialNumber. |
| 108 | // if the value is true that means the OnuDiscovery indication |
| 109 | // is currently being processed and thus we can ignore concurrent requests |
| 110 | // if it's false it means the processing has completed and we shouldn't be receiving a new indication |
| 111 | // if we do it means something went wrong and we need to retry |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 112 | discOnus sync.Map |
| 113 | onus sync.Map |
| 114 | activePorts sync.Map |
| 115 | flowMgr []*OpenOltFlowMgr |
| 116 | resourceMgr []*rsrcMgr.OpenOltResourceMgr |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 117 | |
| 118 | // Slice of channels. Each channel in slice, index by (mcast-group-id modulo MaxNumOfGroupHandlerChannels) |
| 119 | // A go routine per index, waits on a unique channel for incoming mcast flow or group (add/modify/remove). |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 120 | incomingMcastFlowOrGroup []chan McastFlowOrGroupControlBlock |
| 121 | stopMcastHandlerRoutine []chan bool |
| 122 | mcastHandlerRoutineActive []bool |
| Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 123 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 124 | lockChildAdapterClients sync.RWMutex |
| 125 | lockDevice sync.RWMutex |
| 126 | perPonOnuIndicationChannelLock sync.Mutex |
| 127 | |
| 128 | totalPonPorts uint32 |
| 129 | heartbeatSignature uint32 |
| 130 | isCollectorActive bool |
| 131 | isHeartbeatCheckActive bool |
| 132 | isReadIndicationRoutineActive bool |
| 133 | |
| Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 134 | adapterPreviouslyConnected bool |
| 135 | agentPreviouslyConnected bool |
| Girish Gowdra | 950326e | 2021-11-05 12:43:24 -0700 | [diff] [blame] | 136 | |
| 137 | isDeviceDeletionInProgress bool |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 138 | prevOperStatus common.OperStatus_Types |
| bseeniva | aa9165b | 2025-09-18 17:28:12 +0530 | [diff] [blame] | 139 | collectorWaitGroup sync.WaitGroup |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 142 | // OnuDevice represents ONU related info |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 143 | type OnuDevice struct { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 144 | deviceID string |
| 145 | deviceType string |
| 146 | serialNumber string |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 147 | proxyDeviceID string |
| 148 | adapterEndpoint string |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 149 | onuID uint32 |
| 150 | intfID uint32 |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 151 | losRaised bool |
| 152 | rdiRaised bool |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 155 | type onuIndicationMsg struct { |
| 156 | ctx context.Context |
| 157 | indication *oop.Indication |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | type onuIndicationChannels struct { |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 161 | indicationChannel chan onuIndicationMsg |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 162 | stopChannel chan struct{} |
| 163 | } |
| 164 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 165 | // McastFlowOrGroupControlBlock is created per mcast flow/group add/modify/remove and pushed on the incomingMcastFlowOrGroup channel slice |
| 166 | // The McastFlowOrGroupControlBlock is then picked by the mcastFlowOrGroupChannelHandlerRoutine for further processing. |
| 167 | // There are MaxNumOfGroupHandlerChannels number of mcastFlowOrGroupChannelHandlerRoutine routines which monitor for any incoming mcast flow/group messages |
| 168 | // and process them serially. The mcast flow/group are assigned these routines based on formula (group-id modulo MaxNumOfGroupHandlerChannels) |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 169 | type McastFlowOrGroupControlBlock struct { |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 170 | ctx context.Context // Flow/group handler context |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 171 | flow *of.OfpFlowStats // Flow message (can be nil or valid flow) |
| 172 | group *of.OfpGroupEntry // Group message (can be nil or valid group) |
| 173 | errChan *chan error // channel to report the mcast Flow/group handling error |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 174 | flowOrGroupAction string // one of McastFlowOrGroupAdd, McastFlowOrGroupModify or McastFlowOrGroupDelete |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 177 | var pmNames = []string{ |
| 178 | "rx_bytes", |
| 179 | "rx_packets", |
| akashreddyk | 302516f | 2025-11-17 15:18:44 +0530 | [diff] [blame] | 180 | "rx_ucast_packets", |
| Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 181 | "rx_mcast_packets", |
| 182 | "rx_bcast_packets", |
| akashreddyk | 302516f | 2025-11-17 15:18:44 +0530 | [diff] [blame] | 183 | "rx_error_packets", |
| 184 | "rx_crc_errors", |
| 185 | "rx_packets_dropped", |
| Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 186 | "tx_bytes", |
| 187 | "tx_packets", |
| akashreddyk | 302516f | 2025-11-17 15:18:44 +0530 | [diff] [blame] | 188 | "tx_ucast_packets", |
| Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 189 | "tx_mcast_packets", |
| 190 | "tx_bcast_packets", |
| akashreddyk | 302516f | 2025-11-17 15:18:44 +0530 | [diff] [blame] | 191 | "tx_error_packets", |
| 192 | "tx_dropped_total", |
| Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 193 | } |
| 194 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 195 | // NewOnuDevice creates a new Onu Device |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 196 | func NewOnuDevice(devID, deviceTp, serialNum string, onuID, intfID uint32, proxyDevID string, losRaised bool, adapterEndpoint string) *OnuDevice { |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 197 | var device OnuDevice |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 198 | device.deviceID = devID |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 199 | device.deviceType = deviceTp |
| 200 | device.serialNumber = serialNum |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 201 | device.onuID = onuID |
| 202 | device.intfID = intfID |
| 203 | device.proxyDeviceID = proxyDevID |
| Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 204 | device.losRaised = losRaised |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 205 | device.adapterEndpoint = adapterEndpoint |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 206 | return &device |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 207 | } |
| 208 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 209 | // NewDeviceHandler creates a new device handler |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 210 | func NewDeviceHandler(cc *vgrpc.Client, ep eventif.EventProxy, device *voltha.Device, adapter *OpenOLT, cm *config.ConfigManager, cfg *conf.AdapterFlags) *DeviceHandler { |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 211 | var dh DeviceHandler |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 212 | ctx := context.Background() |
| Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 213 | dh.cm = cm |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 214 | dh.coreClient = cc |
| Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 215 | dh.EventProxy = ep |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 216 | cloned := (proto.Clone(device)).(*voltha.Device) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 217 | dh.device = cloned |
| 218 | dh.openOLT = adapter |
| khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 219 | dh.exitChannel = make(chan struct{}) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 220 | dh.lockDevice = sync.RWMutex{} |
| Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 221 | dh.stopCollector = make(chan bool, 1) // TODO: Why buffered? |
| 222 | dh.stopHeartbeatCheck = make(chan bool, 1) // TODO: Why buffered? |
| Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 223 | dh.metrics = pmmetrics.NewPmMetrics(cloned.Id, pmmetrics.Frequency(150), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames)) |
| Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 224 | dh.activePorts = sync.Map{} |
| Girish Gowdra | ae56c72 | 2021-11-22 14:31:11 -0800 | [diff] [blame] | 225 | dh.stopIndications = make(chan bool, 1) // TODO: Why buffered? |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 226 | dh.perPonOnuIndicationChannel = make(map[uint32]onuIndicationChannels) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 227 | dh.childAdapterClients = make(map[string]*vgrpc.Client) |
| 228 | dh.cfg = cfg |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 229 | dh.kvStore = SetKVClient(ctx, dh.openOLT.KVStoreType, dh.openOLT.KVStoreAddress, dh.device.Id, dh.cm.Backend.PathPrefix) |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 230 | if dh.kvStore == nil { |
| 231 | logger.Error(ctx, "Failed to setup KV store") |
| 232 | return nil |
| 233 | } |
| 234 | |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 235 | // Create a slice of buffered channels for handling concurrent mcast flow/group. |
| 236 | dh.incomingMcastFlowOrGroup = make([]chan McastFlowOrGroupControlBlock, MaxNumOfGroupHandlerChannels) |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 237 | dh.stopMcastHandlerRoutine = make([]chan bool, MaxNumOfGroupHandlerChannels) |
| 238 | dh.mcastHandlerRoutineActive = make([]bool, MaxNumOfGroupHandlerChannels) |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 239 | for i := range dh.incomingMcastFlowOrGroup { |
| 240 | dh.incomingMcastFlowOrGroup[i] = make(chan McastFlowOrGroupControlBlock, MaxNumOfGroupHandlerChannels) |
| Girish Gowdra | ae56c72 | 2021-11-22 14:31:11 -0800 | [diff] [blame] | 241 | dh.stopMcastHandlerRoutine[i] = make(chan bool) |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 242 | // Spin up a go routine to handling incoming mcast flow/group (add/modify/remove). |
| 243 | // There will be MaxNumOfGroupHandlerChannels number of mcastFlowOrGroupChannelHandlerRoutine go routines. |
| 244 | // These routines will be blocked on the dh.incomingMcastFlowOrGroup[mcast-group-id modulo MaxNumOfGroupHandlerChannels] channel |
| 245 | // for incoming mcast flow/group to be processed serially. |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 246 | dh.mcastHandlerRoutineActive[i] = true |
| 247 | go dh.mcastFlowOrGroupChannelHandlerRoutine(i, dh.incomingMcastFlowOrGroup[i], dh.stopMcastHandlerRoutine[i]) |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 248 | } |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 249 | // TODO initialize the support classes. |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 250 | return &dh |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 251 | } |
| 252 | |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 253 | func newKVClient(ctx context.Context, storeType string, address string, timeout time.Duration) (kvstore.Client, error) { |
| 254 | logger.Infow(ctx, "kv-store-type", log.Fields{"store": storeType}) |
| 255 | switch storeType { |
| 256 | case "etcd": |
| 257 | return kvstore.NewEtcdClient(ctx, address, timeout, log.FatalLevel) |
| Abhay Kumar | 9bcfeb2 | 2024-07-12 09:14:25 +0530 | [diff] [blame] | 258 | case "redis": |
| 259 | return kvstore.NewRedisClient(address, timeout, false) |
| 260 | case "redis-sentinel": |
| 261 | return kvstore.NewRedisClient(address, timeout, true) |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 262 | } |
| 263 | return nil, errors.New("unsupported-kv-store") |
| 264 | } |
| 265 | |
| 266 | // SetKVClient sets the KV client and return a kv backend |
| 267 | func SetKVClient(ctx context.Context, backend string, addr string, DeviceID string, basePathKvStore string) *db.Backend { |
| 268 | kvClient, err := newKVClient(ctx, backend, addr, rsrcMgr.KvstoreTimeout) |
| 269 | if err != nil { |
| 270 | logger.Fatalw(ctx, "Failed to init KV client\n", log.Fields{"err": err}) |
| 271 | return nil |
| 272 | } |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 273 | kvbackend := &db.Backend{ |
| 274 | Client: kvClient, |
| 275 | StoreType: backend, |
| 276 | Address: addr, |
| 277 | Timeout: rsrcMgr.KvstoreTimeout, |
| 278 | PathPrefix: fmt.Sprintf(rsrcMgr.BasePathKvStore, basePathKvStore, DeviceID)} |
| 279 | |
| 280 | return kvbackend |
| 281 | } |
| 282 | |
| Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 283 | // CloseKVClient closes open KV clients |
| 284 | func (dh *DeviceHandler) CloseKVClient(ctx context.Context) { |
| 285 | if dh.resourceMgr != nil { |
| 286 | for _, rscMgr := range dh.resourceMgr { |
| 287 | if rscMgr != nil { |
| 288 | rscMgr.CloseKVClient(ctx) |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | if dh.flowMgr != nil { |
| 293 | for _, flMgr := range dh.flowMgr { |
| 294 | if flMgr != nil { |
| 295 | flMgr.CloseKVClient(ctx) |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 301 | // start save the device to the data model |
| 302 | func (dh *DeviceHandler) start(ctx context.Context) { |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 303 | dh.lockDevice.Lock() |
| 304 | defer dh.lockDevice.Unlock() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 305 | logger.Debugw(ctx, "starting-device-agent", log.Fields{"device": dh.device}) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 306 | // Add the initial device to the local model |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 307 | logger.Debug(ctx, "device-agent-started") |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 308 | } |
| 309 | |
| khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 310 | // Stop stops the device handler |
| 311 | func (dh *DeviceHandler) Stop(ctx context.Context) { |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 312 | dh.lockDevice.Lock() |
| 313 | defer dh.lockDevice.Unlock() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 314 | logger.Debug(ctx, "stopping-device-agent") |
| khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 315 | close(dh.exitChannel) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 316 | |
| khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 317 | // Delete (which will stop also) all grpc connections to the child adapters |
| 318 | dh.deleteAdapterClients(ctx) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 319 | logger.Debug(ctx, "device-agent-stopped") |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 320 | } |
| 321 | |
| ssiddiqui | 04386ee | 2021-08-23 21:58:25 +0530 | [diff] [blame] | 322 | func (dh *DeviceHandler) getPonTechnology(intfID uint32) string { |
| 323 | for _, resourceRanges := range dh.deviceInfo.GetRanges() { |
| 324 | for _, pooledIntfID := range resourceRanges.GetIntfIds() { |
| 325 | if pooledIntfID == intfID { |
| 326 | return resourceRanges.GetTechnology() |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | return "" |
| 331 | } |
| 332 | |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 333 | func macifyIP(ip net.IP) string { |
| 334 | if len(ip) > 0 { |
| 335 | oct1 := strconv.FormatInt(int64(ip[12]), 16) |
| 336 | oct2 := strconv.FormatInt(int64(ip[13]), 16) |
| 337 | oct3 := strconv.FormatInt(int64(ip[14]), 16) |
| 338 | oct4 := strconv.FormatInt(int64(ip[15]), 16) |
| 339 | return fmt.Sprintf("00:00:%02v:%02v:%02v:%02v", oct1, oct2, oct3, oct4) |
| 340 | } |
| 341 | return "" |
| 342 | } |
| 343 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 344 | func generateMacFromHost(ctx context.Context, host string) (string, error) { |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 345 | var genmac string |
| 346 | var addr net.IP |
| 347 | var ips []string |
| 348 | var err error |
| 349 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 350 | logger.Debugw(ctx, "generating-mac-from-host", log.Fields{"host": host}) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 351 | |
| 352 | if addr = net.ParseIP(host); addr == nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 353 | logger.Debugw(ctx, "looking-up-hostname", log.Fields{"host": host}) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 354 | |
| 355 | if ips, err = net.LookupHost(host); err == nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 356 | logger.Debugw(ctx, "dns-result-ips", log.Fields{"ips": ips}) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 357 | if addr = net.ParseIP(ips[0]); addr == nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 358 | return "", olterrors.NewErrInvalidValue(log.Fields{"ip": ips[0]}, nil) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 359 | } |
| 360 | genmac = macifyIP(addr) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 361 | logger.Debugw(ctx, "using-ip-as-mac", |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 362 | log.Fields{"host": ips[0], |
| 363 | "mac": genmac}) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 364 | return genmac, nil |
| 365 | } |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 366 | return "", olterrors.NewErrAdapter("cannot-resolve-hostname-to-ip", log.Fields{"host": host}, err) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | genmac = macifyIP(addr) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 370 | logger.Debugw(ctx, "using-ip-as-mac", |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 371 | log.Fields{"host": host, |
| 372 | "mac": genmac}) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 373 | return genmac, nil |
| 374 | } |
| 375 | |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 376 | func macAddressToUint32Array(mac string) []uint32 { |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 377 | slist := strings.Split(mac, ":") |
| 378 | result := make([]uint32, len(slist)) |
| 379 | var err error |
| 380 | var tmp int64 |
| 381 | for index, val := range slist { |
| 382 | if tmp, err = strconv.ParseInt(val, 16, 32); err != nil { |
| 383 | return []uint32{1, 2, 3, 4, 5, 6} |
| 384 | } |
| 385 | result[index] = uint32(tmp) |
| 386 | } |
| 387 | return result |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 388 | } |
| 389 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 390 | // GetportLabel returns the label for the NNI and the PON port based on port number and port type |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 391 | func GetportLabel(portNum uint32, portType voltha.Port_PortType) (string, error) { |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 392 | switch portType { |
| 393 | case voltha.Port_ETHERNET_NNI: |
| 394 | return fmt.Sprintf("nni-%d", portNum), nil |
| 395 | case voltha.Port_PON_OLT: |
| 396 | return fmt.Sprintf("pon-%d", portNum), nil |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 397 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 398 | |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 399 | return "", olterrors.NewErrInvalidValue(log.Fields{"port-type": portType}, nil) |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 400 | } |
| 401 | |
| Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 402 | func makeOfpPort(macAddress string, speedMbps uint32) *of.OfpPort { |
| 403 | if speedMbps == 0 { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 404 | // In case it was not set in the indication |
| 405 | // and no other value was provided |
| Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 406 | speedMbps = defaultPortSpeedMbps |
| 407 | } |
| 408 | |
| 409 | ofpPortSpeed := of.OfpPortFeatures_OFPPF_OTHER |
| 410 | switch speedMbps { |
| 411 | case 1000000: |
| 412 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_1TB_FD |
| 413 | case 100000: |
| 414 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_100GB_FD |
| 415 | case 40000: |
| 416 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_40GB_FD |
| 417 | case 10000: |
| 418 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_10GB_FD |
| 419 | case 1000: |
| 420 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_1GB_FD |
| 421 | case 100: |
| 422 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_100MB_FD |
| 423 | case 10: |
| 424 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_10MB_FD |
| 425 | } |
| 426 | |
| 427 | capacity := uint32(ofpPortSpeed | of.OfpPortFeatures_OFPPF_FIBER) |
| 428 | |
| 429 | port := &of.OfpPort{ |
| 430 | HwAddr: macAddressToUint32Array(macAddress), |
| 431 | Config: 0, |
| 432 | State: uint32(of.OfpPortState_OFPPS_LIVE), |
| 433 | Curr: capacity, |
| 434 | Advertised: capacity, |
| 435 | Peer: capacity, |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 436 | CurrSpeed: speedMbps * 1000, // kbps |
| 437 | MaxSpeed: speedMbps * 1000, // kbps |
| Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | return port |
| 441 | } |
| 442 | |
| 443 | func (dh *DeviceHandler) addPort(ctx context.Context, intfID uint32, portType voltha.Port_PortType, state string, speedMbps uint32) error { |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 444 | var operStatus common.OperStatus_Types |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 445 | if state == "up" { |
| 446 | operStatus = voltha.OperStatus_ACTIVE |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 447 | // populating the intfStatus map |
| Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 448 | dh.activePorts.Store(intfID, true) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 449 | } else { |
| 450 | operStatus = voltha.OperStatus_DISCOVERED |
| Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 451 | dh.activePorts.Store(intfID, false) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 452 | } |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 453 | portNum := plt.IntfIDToPortNo(intfID, portType) |
| Chaitrashree G S | c0878ec | 2020-05-21 04:59:53 -0400 | [diff] [blame] | 454 | label, err := GetportLabel(intfID, portType) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 455 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 456 | return olterrors.NewErrNotFound("port-label", log.Fields{"port-number": portNum, "port-type": portType}, err) |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 457 | } |
| Chaitrashree G S | ded0a83 | 2020-01-09 20:21:48 -0500 | [diff] [blame] | 458 | |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 459 | // Check if port exists |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 460 | port, err := dh.getPortFromCore(ctx, &ca.PortFilter{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 461 | DeviceId: dh.device.Id, |
| 462 | Port: portNum, |
| 463 | }) |
| 464 | if err == nil && port.Type == portType { |
| Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 465 | logger.Debug(ctx, "port-already-exists-updating-oper-status-of-port") |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 466 | err = dh.updatePortStateInCore(ctx, &ca.PortState{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 467 | DeviceId: dh.device.Id, |
| 468 | PortType: portType, |
| 469 | PortNo: portNum, |
| 470 | OperStatus: operStatus}) |
| 471 | if err != nil { |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 472 | return olterrors.NewErrAdapter("failed-to-update-port-state", log.Fields{ |
| 473 | "device-id": dh.device.Id, |
| 474 | "port-type": portType, |
| 475 | "port-number": portNum, |
| 476 | "oper-status": operStatus}, err).Log() |
| Chaitrashree G S | ded0a83 | 2020-01-09 20:21:48 -0500 | [diff] [blame] | 477 | } |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 478 | return nil |
| Chaitrashree G S | ded0a83 | 2020-01-09 20:21:48 -0500 | [diff] [blame] | 479 | } |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 480 | |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 481 | // Now create Port |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 482 | port = &voltha.Port{ |
| 483 | DeviceId: dh.device.Id, |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 484 | PortNo: portNum, |
| 485 | Label: label, |
| 486 | Type: portType, |
| 487 | OperStatus: operStatus, |
| Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 488 | OfpPort: makeOfpPort(dh.device.MacAddress, speedMbps), |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 489 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 490 | logger.Debugw(ctx, "sending-port-update-to-core", log.Fields{"port": port}) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 491 | // Synchronous call to update device - this method is run in its own go routine |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 492 | err = dh.createPortInCore(ctx, port) |
| 493 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 494 | return olterrors.NewErrAdapter("error-creating-port", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 495 | "device-id": dh.device.Id, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 496 | "port-type": portType}, err) |
| Girish Gowdru | 1110ef2 | 2019-06-24 11:17:59 -0400 | [diff] [blame] | 497 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 498 | go dh.updateLocalDevice(ctx) |
| Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 499 | return nil |
| 500 | } |
| 501 | |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 502 | func (dh *DeviceHandler) updateLocalDevice(ctx context.Context) { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 503 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
| Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 504 | if err != nil || device == nil { |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 505 | logger.Errorf(ctx, "device-not-found", log.Fields{"device-id": dh.device.Id}, err) |
| 506 | return |
| Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 507 | } |
| Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 508 | dh.lockDevice.Lock() |
| 509 | defer dh.lockDevice.Unlock() |
| Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 510 | dh.device = device |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 511 | } |
| 512 | |
| David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 513 | // nolint: gocyclo |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 514 | // readIndications to read the indications from the OLT device |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 515 | func (dh *DeviceHandler) readIndications(ctx context.Context) error { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 516 | defer logger.Debugw(ctx, "indications-ended", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 517 | defer func() { |
| 518 | dh.lockDevice.Lock() |
| 519 | dh.isReadIndicationRoutineActive = false |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 520 | logger.Debugw(ctx, "isReadIndicationRoutineActive set to false", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 521 | dh.lockDevice.Unlock() |
| 522 | }() |
| Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 523 | indications, err := dh.startOpenOltIndicationStream(ctx) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 524 | if err != nil { |
| Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 525 | return err |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 526 | } |
| Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 527 | |
| David Bainbridge | f5879ca | 2019-12-13 21:17:54 +0000 | [diff] [blame] | 528 | // Create an exponential backoff around re-enabling indications. The |
| 529 | // maximum elapsed time for the back off is set to 0 so that we will |
| 530 | // continue to retry. The max interval defaults to 1m, but is set |
| 531 | // here for code clarity |
| 532 | indicationBackoff := backoff.NewExponentialBackOff() |
| 533 | indicationBackoff.MaxElapsedTime = 0 |
| 534 | indicationBackoff.MaxInterval = 1 * time.Minute |
| Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 535 | |
| Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 536 | dh.lockDevice.Lock() |
| 537 | dh.isReadIndicationRoutineActive = true |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 538 | logger.Debugw(ctx, "isReadIndicationRoutineActive set to true", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 539 | dh.lockDevice.Unlock() |
| 540 | |
| Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 541 | Loop: |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 542 | for { |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 543 | select { |
| 544 | case <-dh.stopIndications: |
| divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 545 | logger.Debugw(ctx, "stopping-collecting-indications-for-olt", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 546 | break Loop |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 547 | default: |
| 548 | indication, err := indications.Recv() |
| Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 549 | |
| 550 | select { |
| 551 | case <-indications.Context().Done(): |
| 552 | if err != nil { |
| 553 | logger.Warnw(ctx, "error-during-enable-indications", |
| 554 | log.Fields{"err": err, |
| 555 | "device-id": dh.device.Id}) |
| 556 | } |
| 557 | |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 558 | // Use an exponential back off to prevent getting into a tight loop |
| 559 | duration := indicationBackoff.NextBackOff() |
| Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 560 | logger.Infow(ctx, "backing-off-enable-indication", log.Fields{ |
| 561 | "device-id": dh.device.Id, |
| 562 | "duration": duration, |
| 563 | }) |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 564 | if duration == backoff.Stop { |
| 565 | // If we reach a maximum then warn and reset the backoff |
| 566 | // timer and keep attempting. |
| Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 567 | logger.Warnw(ctx, "maximum-indication-backoff-reached-resetting-backoff-timer", |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 568 | log.Fields{"max-indication-backoff": indicationBackoff.MaxElapsedTime, |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 569 | "device-id": dh.device.Id}) |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 570 | indicationBackoff.Reset() |
| 571 | } |
| David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 572 | |
| 573 | // On failure process a backoff timer while watching for stopIndications |
| 574 | // events |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 575 | backoffTimer := time.NewTimer(indicationBackoff.NextBackOff()) |
| David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 576 | select { |
| 577 | case <-dh.stopIndications: |
| divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 578 | logger.Debugw(ctx, "stopping-collecting-indications-for-olt", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 579 | if !backoffTimer.Stop() { |
| 580 | <-backoffTimer.C |
| David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 581 | } |
| 582 | break Loop |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 583 | case <-backoffTimer.C: |
| 584 | // backoffTimer expired continue |
| David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 585 | } |
| Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 586 | if indications, err = dh.startOpenOltIndicationStream(ctx); err != nil { |
| 587 | return err |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 588 | } |
| 589 | continue |
| Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 590 | default: |
| 591 | if err != nil { |
| 592 | logger.Errorw(ctx, "read-indication-error", |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 593 | log.Fields{"err": err, |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 594 | "device-id": dh.device.Id}) |
| Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 595 | // Close the stream, and re-initialize it |
| 596 | if err = indications.CloseSend(); err != nil { |
| 597 | // Ok to ignore here, because we landed here due to a problem on the stream |
| 598 | // In all probability, the closeSend call may fail |
| 599 | logger.Debugw(ctx, "error-closing-send stream--error-ignored", |
| 600 | log.Fields{"err": err, |
| 601 | "device-id": dh.device.Id}) |
| 602 | } |
| 603 | if indications, err = dh.startOpenOltIndicationStream(ctx); err != nil { |
| 604 | return err |
| 605 | } |
| 606 | // once we re-initialized the indication stream, continue to read indications |
| 607 | continue |
| Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 608 | } |
| Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 609 | // Reset backoff if we have a successful receive |
| 610 | indicationBackoff.Reset() |
| 611 | // When OLT is admin down, ignore all indications. |
| 612 | if dh.device.AdminState == voltha.AdminState_DISABLED && !isIndicationAllowedDuringOltAdminDown(indication) { |
| 613 | logger.Debugw(ctx, "olt-is-admin-down, ignore indication", |
| 614 | log.Fields{"indication": indication, |
| 615 | "device-id": dh.device.Id}) |
| 616 | continue |
| Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 617 | } |
| Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 618 | dh.handleIndication(ctx, indication) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 619 | } |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 620 | } |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 621 | } |
| Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 622 | // Close the send stream |
| 623 | _ = indications.CloseSend() // Ok to ignore error, as we stopping the readIndication anyway |
| Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 624 | |
| Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 625 | return nil |
| 626 | } |
| 627 | |
| 628 | func (dh *DeviceHandler) startOpenOltIndicationStream(ctx context.Context) (oop.Openolt_EnableIndicationClient, error) { |
| Girish Gowdra | 852ad91 | 2021-05-04 00:05:50 -0700 | [diff] [blame] | 629 | logger.Infow(ctx, "enabling read indications", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 630 | indications, err := dh.Client.EnableIndication(ctx, new(oop.Empty)) |
| 631 | if err != nil { |
| 632 | return nil, olterrors.NewErrCommunication("indication-read-failure", log.Fields{"device-id": dh.device.Id}, err).Log() |
| 633 | } |
| 634 | if indications == nil { |
| 635 | return nil, olterrors.NewErrInvalidValue(log.Fields{"indications": nil, "device-id": dh.device.Id}, nil).Log() |
| 636 | } |
| Girish Gowdra | 852ad91 | 2021-05-04 00:05:50 -0700 | [diff] [blame] | 637 | logger.Infow(ctx, "read indication started successfully", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 638 | return indications, nil |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | // isIndicationAllowedDuringOltAdminDown returns true if the indication is allowed during OLT Admin down, else false |
| 642 | func isIndicationAllowedDuringOltAdminDown(indication *oop.Indication) bool { |
| 643 | switch indication.Data.(type) { |
| 644 | case *oop.Indication_OltInd, *oop.Indication_IntfInd, *oop.Indication_IntfOperInd: |
| 645 | return true |
| 646 | |
| 647 | default: |
| 648 | return false |
| 649 | } |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 652 | func (dh *DeviceHandler) handleOltIndication(ctx context.Context, oltIndication *oop.OltIndication) error { |
| Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 653 | raisedTs := time.Now().Unix() |
| Gamze Abaka | a1a5052 | 2019-10-03 19:28:27 +0000 | [diff] [blame] | 654 | if oltIndication.OperState == "up" && dh.transitionMap.currentDeviceState != deviceStateUp { |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 655 | dh.transitionMap.Handle(ctx, DeviceUpInd) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 656 | } else if oltIndication.OperState == "down" { |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 657 | dh.transitionMap.Handle(ctx, DeviceDownInd) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 658 | } |
| Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 659 | // Send or clear Alarm |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 660 | if err := dh.eventMgr.oltUpDownIndication(ctx, oltIndication, dh.device.Id, raisedTs); err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 661 | return olterrors.NewErrAdapter("failed-indication", log.Fields{ |
| divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 662 | "device-id": dh.device.Id, |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 663 | "indication": oltIndication, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 664 | "timestamp": raisedTs}, err) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 665 | } |
| 666 | return nil |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| balaji.nagarajan | 68f56e8 | 2025-07-04 15:16:01 +0530 | [diff] [blame] | 669 | func (dh *DeviceHandler) handleOnuDisableIndication(ctx context.Context, onuIndication *oop.OnuDisabledIndication) error { |
| 670 | logger.Infow(ctx, "handleOnuDisableIndication", log.Fields{"device-id": dh.device.Id, "onuInd": onuIndication}) |
| 671 | sn := dh.stringifySerialNumber(onuIndication.SerialNumber) |
| 672 | intfID := onuIndication.GetIntfId() |
| 673 | ponPort := plt.IntfIDToPortNo(intfID, voltha.Port_PON_OLT) |
| 674 | onuDev := dh.getChildDevice(ctx, sn, ponPort) |
| 675 | if onuDev == nil { |
| 676 | logger.Warnw(ctx, "handleOnuDisableIndication onu-device-fetch-failed", log.Fields{"device-id": dh.device.Id, "onuInd": onuIndication}) |
| 677 | onuDev = &OnuDevice{ |
| 678 | serialNumber: sn, |
| 679 | } |
| 680 | } |
| 681 | dh.discOnus.Delete(sn) |
| 682 | |
| 683 | raisedTs := time.Now().Unix() |
| 684 | if err := dh.eventMgr.onuDisableIndication(ctx, onuIndication, dh.device.Id, onuDev, raisedTs); err != nil { |
| 685 | return olterrors.NewErrAdapter("failed-indication", log.Fields{ |
| 686 | "device-id": dh.device.Id, |
| 687 | "indication": onuIndication, |
| 688 | "timestamp": raisedTs}, err) |
| 689 | } |
| 690 | OnuIndication := generateOnuIndication(onuDev.intfID, onuDev.onuID, "down", "down") |
| 691 | err := dh.sendOnuIndicationToChildAdapter(ctx, onuDev.adapterEndpoint, &ia.OnuIndicationMessage{ |
| 692 | DeviceId: onuDev.deviceID, |
| 693 | OnuIndication: OnuIndication.GetOnuInd(), |
| 694 | }) |
| 695 | if err != nil { |
| 696 | return olterrors.NewErrCommunication("inter-adapter-send-failed", log.Fields{ |
| 697 | "onu-indicator": OnuIndication.GetOnuInd(), |
| 698 | "source": dh.openOLT.config.AdapterEndpoint, |
| 699 | "device-type": onuDev.deviceType, |
| 700 | "device-id": onuDev.deviceID}, err) |
| 701 | } |
| 702 | return nil |
| 703 | } |
| 704 | |
| 705 | func (dh *DeviceHandler) handleOnuEnableIndication(ctx context.Context, onuIndication *oop.OnuEnabledIndication) error { |
| 706 | logger.Infow(ctx, "handleOnuEnableIndication", log.Fields{"device-id": dh.device.Id, "onuInd": onuIndication}) |
| 707 | sn := dh.stringifySerialNumber(onuIndication.SerialNumber) |
| 708 | intfID := onuIndication.GetIntfId() |
| 709 | ponPort := plt.IntfIDToPortNo(intfID, voltha.Port_PON_OLT) |
| 710 | onuDev := dh.getChildDevice(ctx, sn, ponPort) |
| 711 | if onuDev == nil { |
| 712 | logger.Warnw(ctx, "handleOnuEnableIndication onu-device-fetch-failed", log.Fields{"device-id": dh.device.Id, "onuInd": onuIndication}) |
| 713 | onuDev = &OnuDevice{ |
| 714 | serialNumber: sn, |
| 715 | } |
| 716 | } |
| 717 | raisedTs := time.Now().Unix() |
| 718 | |
| 719 | if err := dh.eventMgr.onuEnableIndication(ctx, onuIndication, dh.device.Id, onuDev, raisedTs); err != nil { |
| 720 | return olterrors.NewErrAdapter("failed-indication", log.Fields{ |
| 721 | "device-id": dh.device.Id, |
| 722 | "indication": onuIndication, |
| 723 | "timestamp": raisedTs}, err) |
| 724 | } |
| 725 | return nil |
| 726 | } |
| 727 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 728 | // nolint: gocyclo,govet |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 729 | func (dh *DeviceHandler) handleIndication(ctx context.Context, indication *oop.Indication) { |
| Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 730 | raisedTs := time.Now().Unix() |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 731 | switch indication.Data.(type) { |
| 732 | case *oop.Indication_OltInd: |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 733 | span, ctx := log.CreateChildSpan(ctx, "olt-indication", log.Fields{"device-id": dh.device.Id}) |
| 734 | defer span.Finish() |
| Girish Gowdra | 852ad91 | 2021-05-04 00:05:50 -0700 | [diff] [blame] | 735 | logger.Infow(ctx, "received olt indication", log.Fields{"device-id": dh.device.Id, "olt-ind": indication.GetOltInd()}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 736 | if err := dh.handleOltIndication(ctx, indication.GetOltInd()); err != nil { |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 737 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "olt", "device-id": dh.device.Id}, err).Log() |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 738 | } |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 739 | case *oop.Indication_IntfInd: |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 740 | span, ctx := log.CreateChildSpan(ctx, "interface-indication", log.Fields{"device-id": dh.device.Id}) |
| 741 | defer span.Finish() |
| 742 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 743 | intfInd := indication.GetIntfInd() |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 744 | go func() { |
| Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 745 | if err := dh.addPort(ctx, intfInd.GetIntfId(), voltha.Port_PON_OLT, intfInd.GetOperState(), defaultPortSpeedMbps); err != nil { |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 746 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "interface", "device-id": dh.device.Id}, err).Log() |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 747 | } |
| 748 | }() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 749 | logger.Infow(ctx, "received-interface-indication", log.Fields{"InterfaceInd": intfInd, "device-id": dh.device.Id}) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 750 | case *oop.Indication_IntfOperInd: |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 751 | span, ctx := log.CreateChildSpan(ctx, "interface-oper-indication", log.Fields{"device-id": dh.device.Id}) |
| 752 | defer span.Finish() |
| 753 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 754 | intfOperInd := indication.GetIntfOperInd() |
| 755 | if intfOperInd.GetType() == "nni" { |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 756 | go func() { |
| Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 757 | if err := dh.addPort(ctx, intfOperInd.GetIntfId(), voltha.Port_ETHERNET_NNI, intfOperInd.GetOperState(), intfOperInd.GetSpeed()); err != nil { |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 758 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "interface-oper-nni", "device-id": dh.device.Id}, err).Log() |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 759 | } |
| 760 | }() |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 761 | } else if intfOperInd.GetType() == "pon" { |
| 762 | // TODO: Check what needs to be handled here for When PON PORT down, ONU will be down |
| 763 | // Handle pon port update |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 764 | go func() { |
| Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 765 | if err := dh.addPort(ctx, intfOperInd.GetIntfId(), voltha.Port_PON_OLT, intfOperInd.GetOperState(), defaultPortSpeedMbps); err != nil { |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 766 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "interface-oper-pon", "device-id": dh.device.Id}, err).Log() |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 767 | } |
| 768 | }() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 769 | go dh.eventMgr.oltIntfOperIndication(ctx, indication.GetIntfOperInd(), dh.device.Id, raisedTs) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 770 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 771 | logger.Infow(ctx, "received-interface-oper-indication", |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 772 | log.Fields{"interfaceOperInd": intfOperInd, |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 773 | "device-id": dh.device.Id}) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 774 | case *oop.Indication_OnuDiscInd: |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 775 | span, ctx := log.CreateChildSpan(ctx, "onu-discovery-indication", log.Fields{"device-id": dh.device.Id}) |
| 776 | defer span.Finish() |
| 777 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 778 | onuDiscInd := indication.GetOnuDiscInd() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 779 | logger.Infow(ctx, "received-onu-discovery-indication", log.Fields{"OnuDiscInd": onuDiscInd, "device-id": dh.device.Id}) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 780 | // put message to channel and return immediately |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 781 | dh.putOnuIndicationToChannel(ctx, indication, onuDiscInd.GetIntfId()) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 782 | case *oop.Indication_OnuInd: |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 783 | span, ctx := log.CreateChildSpan(ctx, "onu-indication", log.Fields{"device-id": dh.device.Id}) |
| 784 | defer span.Finish() |
| 785 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 786 | onuInd := indication.GetOnuInd() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 787 | logger.Infow(ctx, "received-onu-indication", log.Fields{"OnuInd": onuInd, "device-id": dh.device.Id}) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 788 | // put message to channel and return immediately |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 789 | dh.putOnuIndicationToChannel(ctx, indication, onuInd.GetIntfId()) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 790 | case *oop.Indication_OmciInd: |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 791 | span, ctx := log.CreateChildSpan(ctx, "omci-indication", log.Fields{"device-id": dh.device.Id}) |
| 792 | defer span.Finish() |
| 793 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 794 | omciInd := indication.GetOmciInd() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 795 | logger.Debugw(ctx, "received-omci-indication", log.Fields{"intf-id": omciInd.IntfId, "onu-id": omciInd.OnuId, "device-id": dh.device.Id}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 796 | go func() { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 797 | if err := dh.omciIndication(ctx, omciInd); err != nil { |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 798 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "omci", "device-id": dh.device.Id}, err).Log() |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 799 | } |
| 800 | }() |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 801 | case *oop.Indication_PktInd: |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 802 | span, ctx := log.CreateChildSpan(ctx, "packet-indication", log.Fields{"device-id": dh.device.Id}) |
| 803 | defer span.Finish() |
| 804 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 805 | pktInd := indication.GetPktInd() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 806 | logger.Debugw(ctx, "received-packet-indication", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 807 | "intf-type": pktInd.IntfId, |
| 808 | "intf-id": pktInd.IntfId, |
| 809 | "gem-port-id": pktInd.GemportId, |
| 810 | "port-no": pktInd.PortNo, |
| 811 | "device-id": dh.device.Id, |
| 812 | }) |
| 813 | |
| 814 | if logger.V(log.DebugLevel) { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 815 | logger.Debugw(ctx, "received-packet-indication-packet", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 816 | "intf-type": pktInd.IntfId, |
| 817 | "intf-id": pktInd.IntfId, |
| 818 | "gem-port-id": pktInd.GemportId, |
| 819 | "port-no": pktInd.PortNo, |
| 820 | "packet": hex.EncodeToString(pktInd.Pkt), |
| 821 | "device-id": dh.device.Id, |
| 822 | }) |
| 823 | } |
| 824 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 825 | go func() { |
| 826 | if err := dh.handlePacketIndication(ctx, pktInd); err != nil { |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 827 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "packet", "device-id": dh.device.Id}, err).Log() |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 828 | } |
| 829 | }() |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 830 | case *oop.Indication_PortStats: |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 831 | span, ctx := log.CreateChildSpan(ctx, "port-statistics-indication", log.Fields{"device-id": dh.device.Id}) |
| 832 | defer span.Finish() |
| 833 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 834 | portStats := indication.GetPortStats() |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 835 | go dh.portStats.PortStatisticsIndication(ctx, portStats, dh.totalPonPorts) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 836 | case *oop.Indication_FlowStats: |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 837 | span, ctx := log.CreateChildSpan(ctx, "flow-stats-indication", log.Fields{"device-id": dh.device.Id}) |
| 838 | defer span.Finish() |
| 839 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 840 | flowStats := indication.GetFlowStats() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 841 | logger.Infow(ctx, "received-flow-stats", log.Fields{"FlowStats": flowStats, "device-id": dh.device.Id}) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 842 | case *oop.Indication_AlarmInd: |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 843 | span, ctx := log.CreateChildSpan(ctx, "alarm-indication", log.Fields{"device-id": dh.device.Id}) |
| 844 | defer span.Finish() |
| 845 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 846 | alarmInd := indication.GetAlarmInd() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 847 | logger.Infow(ctx, "received-alarm-indication", log.Fields{"AlarmInd": alarmInd, "device-id": dh.device.Id}) |
| 848 | go dh.eventMgr.ProcessEvents(ctx, alarmInd, dh.device.Id, raisedTs) |
| balaji.nagarajan | 68f56e8 | 2025-07-04 15:16:01 +0530 | [diff] [blame] | 849 | case *oop.Indication_OnuDisabledInd: |
| 850 | span, ctx := log.CreateChildSpan(ctx, "onu-disable-indication", log.Fields{"device-id": dh.device.Id}) |
| 851 | defer span.Finish() |
| 852 | logger.Infow(ctx, "received onu-disable-indication", log.Fields{"device-id": dh.device.Id, "onu-ind": indication.GetOnuInd()}) |
| 853 | if err := dh.handleOnuDisableIndication(ctx, indication.GetOnuDisabledInd()); err != nil { |
| 854 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "olt", "device-id": dh.device.Id, "onu-ind": indication.GetOnuInd()}, err).Log() |
| 855 | } |
| 856 | case *oop.Indication_OnuEnabledInd: |
| 857 | span, ctx := log.CreateChildSpan(ctx, "onu-enable-indication", log.Fields{"device-id": dh.device.Id}) |
| 858 | defer span.Finish() |
| 859 | logger.Infow(ctx, "received onu-enable-indication", log.Fields{"device-id": dh.device.Id, "onu-ind": indication.GetOnuInd()}) |
| 860 | if err := dh.handleOnuEnableIndication(ctx, indication.GetOnuEnabledInd()); err != nil { |
| 861 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "olt", "device-id": dh.device.Id, "onu-ind": indication.GetOnuInd()}, err).Log() |
| 862 | } |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 863 | } |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 864 | } |
| 865 | |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 866 | func generateOnuIndication(intfID, onuID uint32, operState, adminState string) *oop.Indication { |
| 867 | onuInd := &oop.OnuIndication{ |
| 868 | IntfId: intfID, |
| 869 | OnuId: onuID, |
| 870 | OperState: operState, |
| 871 | AdminState: adminState, |
| 872 | } |
| 873 | indication := &oop.Indication{ |
| 874 | Data: &oop.Indication_OnuInd{ |
| 875 | OnuInd: onuInd, |
| 876 | }, |
| 877 | } |
| 878 | return indication |
| 879 | } |
| 880 | |
| 881 | func generateOnuAlarmIndication(intfID uint32, onuID uint32, losStatus string) *oop.AlarmIndication { |
| 882 | onuAlarmInd := &oop.OnuAlarmIndication{ |
| 883 | IntfId: intfID, |
| 884 | OnuId: onuID, |
| 885 | LosStatus: losStatus, |
| 886 | } |
| 887 | alarmInd := &oop.AlarmIndication{ |
| 888 | Data: &oop.AlarmIndication_OnuAlarmInd{ |
| 889 | OnuAlarmInd: onuAlarmInd, |
| 890 | }, |
| 891 | } |
| 892 | return alarmInd |
| 893 | } |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 894 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 895 | func generatePonLosAlarmIndication(intfID uint32, losStatus string) *oop.AlarmIndication { |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 896 | ponlosAlarmInd := &oop.LosIndication{ |
| 897 | IntfId: intfID, |
| 898 | Status: losStatus, |
| 899 | } |
| 900 | alarmInd := &oop.AlarmIndication{ |
| 901 | Data: &oop.AlarmIndication_LosInd{ |
| 902 | LosInd: ponlosAlarmInd, |
| 903 | }, |
| 904 | } |
| 905 | return alarmInd |
| 906 | } |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 907 | |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 908 | func (dh *DeviceHandler) updateIntfOperStateAndRaiseIndication(ctx context.Context, operState string, intfID uint32) { |
| 909 | go func() { |
| 910 | if err := dh.addPort(ctx, intfID, voltha.Port_PON_OLT, operState, defaultPortSpeedMbps); err != nil { |
| 911 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "interface-oper-pon", "device-id": dh.device.Id}, err).Log() |
| 912 | } |
| 913 | }() |
| 914 | |
| 915 | raisedTs := time.Now().Unix() |
| 916 | go dh.eventMgr.oltIntfOperIndication(ctx, &oop.IntfOperIndication{Type: "pon", IntfId: intfID, OperState: operState}, dh.device.Id, raisedTs) |
| 917 | } |
| 918 | |
| 919 | func (dh *DeviceHandler) reconcileOnus(ctx context.Context) error { |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 920 | onuDevicesFromCore, err := dh.getChildDevicesFromCore(ctx, dh.device.Id) |
| 921 | if err != nil { |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 922 | logger.Error(ctx, "unable to fetch child device", log.Fields{"eeror": err}) |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 923 | return err |
| 924 | } |
| 925 | for _, onuDeviceFromCore := range onuDevicesFromCore.Items { |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 926 | onuOperStatusFromCore := onuDeviceFromCore.OperStatus |
| 927 | onuConnectStatusFromCore := onuDeviceFromCore.ConnectStatus |
| 928 | intfID := plt.PortNoToIntfID(onuDeviceFromCore.ParentPortNo, voltha.Port_PON_OLT) |
| 929 | |
| 930 | onuID := onuDeviceFromCore.ProxyAddress.OnuId |
| 931 | onuDeviceFromOlt, err := dh.getOnuInfo(ctx, intfID, &onuID) |
| 932 | if err != nil { |
| 933 | logger.Error(ctx, "unable to get onu object from olt agent", log.Fields{"eeror": err}) |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 934 | } else { |
| 935 | onuOperStatusFromOlt := onuDeviceFromOlt.GetState() |
| 936 | onuLosFromOlt := onuDeviceFromOlt.GetLosi() |
| 937 | switch { |
| 938 | case onuOperStatusFromOlt.String() == "ACTIVE" && onuOperStatusFromCore.String() != "ACTIVE": |
| 939 | OnuIndication := generateOnuIndication(intfID, onuID, "up", "up") |
| 940 | dh.putOnuIndicationToChannel(ctx, OnuIndication, intfID) |
| 941 | |
| 942 | case onuLosFromOlt.String() == "ON" && onuConnectStatusFromCore.String() == "REACHABLE": |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 943 | OnuIndication := generateOnuIndication(intfID, onuID, "down", "down") // check bal cli login notepad |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 944 | alarmInd := generateOnuAlarmIndication(intfID, onuID, "on") |
| 945 | raisedTs := time.Now().Unix() |
| 946 | go dh.eventMgr.ProcessEvents(ctx, alarmInd, dh.device.Id, raisedTs) |
| 947 | |
| 948 | dh.putOnuIndicationToChannel(ctx, OnuIndication, intfID) |
| 949 | } |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 950 | } |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 951 | } |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 952 | return nil |
| 953 | } |
| 954 | |
| 955 | func (dh *DeviceHandler) reconcilePonPorts(ctx context.Context) error { // need onuid and pon id |
| 956 | portsFromCore, err := dh.getAllPortsFromCore(ctx, &ca.PortFilter{ |
| 957 | DeviceId: dh.device.Id, |
| 958 | PortType: voltha.Port_PON_OLT, |
| 959 | }) |
| 960 | if err != nil { |
| 961 | logger.Error(ctx, "unable to fetch ports from core", log.Fields{"eeror": err}) |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 962 | return err |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 963 | } |
| 964 | for _, portFromCore := range portsFromCore.Items { |
| 965 | portNum := portFromCore.GetPortNo() |
| 966 | intfID := plt.PortNoToIntfID(portNum, voltha.Port_PON_OLT) |
| 967 | portOperStatusFromCore := portFromCore.OperStatus |
| 968 | portAdminStateFromCore := portFromCore.AdminState |
| 969 | ponPortFromOlt, err := dh.getIntfInfo(ctx, intfID) |
| 970 | if err != nil { |
| 971 | logger.Error(ctx, "unable to get pon objects from olt agent", log.Fields{"eeror": err}) |
| 972 | } else { |
| 973 | portLosFromOlt := ponPortFromOlt.GetLos() |
| 974 | portStateFromOlt := ponPortFromOlt.GetState() |
| 975 | if portOperStatusFromCore.String() == "ACTIVE" && portLosFromOlt.String() == "ON" { |
| 976 | logger.Debug(ctx, "port is active in core but los is fired from olt", log.Fields{ |
| 977 | "portStateFromOlt": portStateFromOlt.String(), |
| 978 | "portOperStatusFromCore": portOperStatusFromCore.String(), |
| 979 | "device-id": dh.device.Id, |
| 980 | "port": portNum}) |
| 981 | ponLosindication := generatePonLosAlarmIndication(intfID, "on") |
| 982 | raisedTs := time.Now().Unix() |
| 983 | go dh.eventMgr.ProcessEvents(ctx, ponLosindication, dh.device.Id, raisedTs) |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 984 | } |
| 985 | switch { |
| 986 | case portStateFromOlt.String() == "ACTIVE_WORKING" && portOperStatusFromCore.String() != "ACTIVE": |
| 987 | logger.Debug(ctx, "mismatch between port state in voltha core and raising port up event", log.Fields{ |
| 988 | "portStateFromOlt": portStateFromOlt.String(), |
| 989 | "portOperStatusFromCore": portOperStatusFromCore.String(), |
| 990 | "device-id": dh.device.Id, |
| 991 | "port": portNum}) |
| 992 | dh.updateIntfOperStateAndRaiseIndication(ctx, "up", intfID) |
| 993 | case (portStateFromOlt.String() == "INACTIVE" || portStateFromOlt.String() == "UNKNOWN") && portOperStatusFromCore.String() == "ACTIVE": |
| 994 | logger.Debug(ctx, "mismatch between port state in voltha core and raising port down event", log.Fields{ |
| 995 | "portStateFromOlt": portStateFromOlt.String(), |
| 996 | "portOperStatusFromCore": portOperStatusFromCore.String(), |
| 997 | "device-id": dh.device.Id, |
| 998 | "port": portNum}) |
| 999 | dh.updateIntfOperStateAndRaiseIndication(ctx, "down", intfID) |
| 1000 | case portStateFromOlt.String() == "DISABLED" && portAdminStateFromCore.String() == "ENABLED": |
| 1001 | logger.Error(ctx, "port enabled in device but disabled at votlha core", log.Fields{ |
| 1002 | "device-id": dh.device.Id, |
| 1003 | "port": portNum}) |
| 1004 | default: |
| 1005 | logger.Error(ctx, "mismatch between port state in voltha core and voltha device", log.Fields{ |
| 1006 | "portStateFromOlt": portStateFromOlt.String(), |
| 1007 | "portOperStatusFromCore": portOperStatusFromCore.String(), |
| 1008 | "device-id": dh.device.Id, |
| 1009 | "port": portNum}) |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 1010 | } |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 1011 | } |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 1012 | } |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 1013 | return nil |
| 1014 | } |
| 1015 | |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1016 | // doStateUp handle the olt up indication and update to voltha core |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1017 | func (dh *DeviceHandler) doStateUp(ctx context.Context) error { |
| Thomas Lee S | 85f3731 | 2020-04-03 17:06:12 +0530 | [diff] [blame] | 1018 | //starting the stat collector |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 1019 | // Declare deviceStateFilter to be used later |
| 1020 | var deviceStateFilter *ca.DeviceStateFilter |
| bseeniva | aa9165b | 2025-09-18 17:28:12 +0530 | [diff] [blame] | 1021 | dh.collectorWaitGroup.Add(1) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1022 | go startCollector(ctx, dh) |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 1023 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 1024 | if err != nil { |
| 1025 | return fmt.Errorf("failed to get device from core: %w", err) |
| 1026 | } |
| 1027 | logger.Info(ctx, "Device state", log.Fields{ |
| 1028 | "device-id": device.Id, |
| 1029 | "CurrOperStatus": device.OperStatus, |
| 1030 | "CurrConnStatus": device.ConnectStatus, |
| 1031 | }) |
| 1032 | // Perform cleanup if the device's operational status is REBOOTED |
| 1033 | if device.OperStatus == voltha.OperStatus_RECONCILING && dh.prevOperStatus == voltha.OperStatus_REBOOTED { |
| 1034 | // Log the device's operational status if it's REBOOTED |
| 1035 | logger.Info(ctx, "Device is transitioning from REBOOTED to RECONCILING", log.Fields{ |
| 1036 | "device-id": device.Id, |
| 1037 | "OperStatus": device.OperStatus, |
| 1038 | }) |
| 1039 | dh.lockDevice.RLock() |
| 1040 | // Stop the read indication only if it the routine is active |
| 1041 | // The read indication would have already stopped due to failure on the gRPC stream following OLT going unreachable |
| 1042 | // Sending message on the 'stopIndication' channel again will cause the readIndication routine to immediately stop |
| 1043 | // on next execution of the readIndication routine. |
| 1044 | if dh.isHeartbeatCheckActive { |
| 1045 | dh.stopHeartbeatCheck <- true |
| 1046 | } |
| 1047 | if dh.isReadIndicationRoutineActive { |
| 1048 | dh.stopIndications <- true |
| 1049 | } |
| bseeniva | aa9165b | 2025-09-18 17:28:12 +0530 | [diff] [blame] | 1050 | if dh.isCollectorActive { |
| 1051 | dh.stopCollector <- true |
| 1052 | } |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 1053 | dh.lockDevice.RUnlock() |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1054 | if err = dh.cleanupDeviceResources(ctx); err != nil { |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 1055 | logger.Error(ctx, "unable to clean up device resources", log.Fields{"error": err}) |
| 1056 | return fmt.Errorf("cleanup device resources failed: %w", err) |
| 1057 | } |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1058 | if err = dh.initializeDeviceHandlerModules(ctx); err != nil { |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 1059 | return olterrors.NewErrAdapter("device-handler-initialization-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| 1060 | } |
| bseeniva | aa9165b | 2025-09-18 17:28:12 +0530 | [diff] [blame] | 1061 | dh.collectorWaitGroup.Add(1) |
| 1062 | go startCollector(ctx, dh) |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 1063 | go startHeartbeatCheck(ctx, dh) |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 1064 | //dh.lockDevice.RUnlock() |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 1065 | } else if device.OperStatus == voltha.OperStatus_RECONCILING { |
| 1066 | // Log the device's operational status if it's RECONCILING |
| 1067 | logger.Info(ctx, "Device is being reconciled", log.Fields{ |
| 1068 | "device-id": device.Id, |
| 1069 | "OperStatus": device.OperStatus, |
| 1070 | }) |
| 1071 | |
| 1072 | // Perform reconciliation steps |
| 1073 | err = dh.reconcileOnus(ctx) |
| 1074 | if err != nil { |
| 1075 | logger.Error(ctx, "unable to reconcile onu", log.Fields{"error": err}) |
| 1076 | } |
| 1077 | err = dh.reconcilePonPorts(ctx) |
| 1078 | if err != nil { |
| 1079 | logger.Error(ctx, "unable to reconcile pon ports", log.Fields{"error": err}) |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 1080 | } |
| 1081 | } |
| Girish Gowdra | 618fa57 | 2021-09-01 17:19:29 -0700 | [diff] [blame] | 1082 | // instantiate the mcast handler routines. |
| 1083 | for i := range dh.incomingMcastFlowOrGroup { |
| 1084 | // We land inside the below "if" code path, after the OLT comes back from a reboot, otherwise the routines |
| 1085 | // are already active when the DeviceHandler module is first instantiated (as part of Adopt_device RPC invocation). |
| 1086 | if !dh.mcastHandlerRoutineActive[i] { |
| 1087 | // Spin up a go routine to handling incoming mcast flow/group (add/modify/remove). |
| 1088 | // There will be MaxNumOfGroupHandlerChannels number of mcastFlowOrGroupChannelHandlerRoutine go routines. |
| 1089 | // These routines will be blocked on the dh.incomingMcastFlowOrGroup[mcast-group-id modulo MaxNumOfGroupHandlerChannels] channel |
| 1090 | // for incoming mcast flow/group to be processed serially. |
| 1091 | dh.mcastHandlerRoutineActive[i] = true |
| 1092 | go dh.mcastFlowOrGroupChannelHandlerRoutine(i, dh.incomingMcastFlowOrGroup[i], dh.stopMcastHandlerRoutine[i]) |
| 1093 | } |
| 1094 | } |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 1095 | // Create DeviceStateFilter with the desired operational and connection statuses |
| 1096 | deviceStateFilter = &ca.DeviceStateFilter{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1097 | DeviceId: dh.device.Id, |
| 1098 | OperStatus: voltha.OperStatus_ACTIVE, |
| 1099 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 1100 | } |
| 1101 | // Log DeviceStateFilter for debugging purposes |
| 1102 | logger.Info(ctx, "DeviceStateFilter", log.Fields{ |
| 1103 | "DeviceId": deviceStateFilter.DeviceId, |
| 1104 | "OperStatus": deviceStateFilter.OperStatus, |
| 1105 | "ConnStatus": deviceStateFilter.ConnStatus, |
| 1106 | }) |
| 1107 | // Synchronous call to update device state - this method is run in its own go routine |
| balaji6299 | cb23cbe | 2025-04-14 17:53:10 +0530 | [diff] [blame] | 1108 | if err = dh.updateDeviceStateInCore(ctx, deviceStateFilter); err != nil { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1109 | return olterrors.NewErrAdapter("device-state-update-failed", log.Fields{"device-id": dh.device.Id}, err) |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1110 | } |
| Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 1111 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1112 | // Clear olt communication failure event |
| Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 1113 | dh.device.ConnectStatus = voltha.ConnectStatus_REACHABLE |
| 1114 | dh.device.OperStatus = voltha.OperStatus_ACTIVE |
| balaji6299 | cb23cbe | 2025-04-14 17:53:10 +0530 | [diff] [blame] | 1115 | |
| 1116 | ports, err := dh.listDevicePortsFromCore(ctx, dh.device.Id) |
| 1117 | if err != nil { |
| 1118 | return olterrors.NewErrAdapter("fetch-ports-failed", log.Fields{"device-id": dh.device.Id}, err) |
| 1119 | } |
| 1120 | dh.populateActivePorts(ctx, ports.Items) |
| 1121 | if err = dh.disableAdminDownPorts(ctx, ports.Items); err != nil { |
| 1122 | logger.Error(ctx, "port-status-update-failed", log.Fields{"error": err, "ports": ports}) |
| 1123 | } |
| 1124 | |
| Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 1125 | raisedTs := time.Now().Unix() |
| Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 1126 | go dh.eventMgr.oltCommunicationEvent(ctx, dh.device, raisedTs) |
| 1127 | |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1128 | return nil |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | // doStateDown handle the olt down indication |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1132 | func (dh *DeviceHandler) doStateDown(ctx context.Context) error { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1133 | logger.Debugw(ctx, "do-state-down-start", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1134 | |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1135 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
| Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1136 | if err != nil || device == nil { |
| 1137 | /*TODO: needs to handle error scenarios */ |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1138 | return olterrors.NewErrNotFound("device", log.Fields{"device-id": dh.device.Id}, err) |
| Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | cloned := proto.Clone(device).(*voltha.Device) |
| Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1142 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1143 | // Update the device oper state and connection status |
| Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1144 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 1145 | dh.lockDevice.Lock() |
| Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1146 | dh.device = cloned |
| Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 1147 | dh.lockDevice.Unlock() |
| Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1148 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1149 | if err = dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1150 | DeviceId: cloned.Id, |
| 1151 | OperStatus: cloned.OperStatus, |
| 1152 | ConnStatus: cloned.ConnectStatus, |
| 1153 | }); err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1154 | return olterrors.NewErrAdapter("state-update-failed", log.Fields{"device-id": device.Id}, err) |
| Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1155 | } |
| Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1156 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1157 | // get the child device for the parent device |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1158 | onuDevices, err := dh.getChildDevicesFromCore(ctx, dh.device.Id) |
| Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1159 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1160 | return olterrors.NewErrAdapter("child-device-fetch-failed", log.Fields{"device-id": dh.device.Id}, err) |
| Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1161 | } |
| 1162 | for _, onuDevice := range onuDevices.Items { |
| Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1163 | // Update onu state as down in onu adapter |
| 1164 | onuInd := oop.OnuIndication{} |
| 1165 | onuInd.OperState = "down" |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1166 | |
| 1167 | ogClient, err := dh.getChildAdapterServiceClient(onuDevice.AdapterEndpoint) |
| 1168 | if err != nil { |
| 1169 | return err |
| 1170 | } |
| 1171 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1172 | _, err = ogClient.OnuIndication(subCtx, &ia.OnuIndicationMessage{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1173 | DeviceId: onuDevice.Id, |
| 1174 | OnuIndication: &onuInd, |
| 1175 | }) |
| 1176 | cancel() |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1177 | if err != nil { |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1178 | _ = olterrors.NewErrCommunication("inter-adapter-send-failed", log.Fields{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1179 | "source": dh.openOLT.config.AdapterEndpoint, |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1180 | "onu-indicator": onuInd, |
| 1181 | "device-type": onuDevice.Type, |
| 1182 | "device-id": onuDevice.Id}, err).LogAt(log.ErrorLevel) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1183 | // Do not return here and continue to process other ONUs |
| Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 1184 | } else { |
| 1185 | logger.Debugw(ctx, "sending inter adapter down ind to onu success", log.Fields{"olt-device-id": device.Id, "onu-device-id": onuDevice.Id}) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1186 | } |
| Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1187 | } |
| Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 1188 | dh.lockDevice.Lock() |
| serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1189 | /* Discovered ONUs entries need to be cleared , since after OLT |
| 1190 | is up, it starts sending discovery indications again*/ |
| Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1191 | dh.discOnus = sync.Map{} |
| Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 1192 | dh.lockDevice.Unlock() |
| 1193 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1194 | logger.Debugw(ctx, "do-state-down-end", log.Fields{"device-id": device.Id}) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1195 | return nil |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | // doStateInit dial the grpc before going to init state |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1199 | func (dh *DeviceHandler) doStateInit(ctx context.Context) error { |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1200 | var err error |
| Gamze Abaka | 49c40b3 | 2021-05-06 09:30:41 +0000 | [diff] [blame] | 1201 | |
| 1202 | // if the connection is already available, close the previous connection (olt reboot case) |
| 1203 | if dh.clientCon != nil { |
| 1204 | if err = dh.clientCon.Close(); err != nil { |
| 1205 | logger.Errorw(ctx, "failed-to-close-previous-connection", log.Fields{"device-id": dh.device.Id}) |
| 1206 | } else { |
| 1207 | logger.Debugw(ctx, "previous-grpc-channel-closed-successfully", log.Fields{"device-id": dh.device.Id}) |
| 1208 | } |
| 1209 | } |
| 1210 | |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1211 | logger.Debugw(ctx, "Dailing grpc", log.Fields{"device-id": dh.device.Id}) |
| Gamze Abaka | 49c40b3 | 2021-05-06 09:30:41 +0000 | [diff] [blame] | 1212 | // Use Interceptors to automatically inject and publish Open Tracing Spans by this GRPC client |
| Girish Kumar | 93e9174 | 2020-07-27 16:43:19 +0000 | [diff] [blame] | 1213 | dh.clientCon, err = grpc.Dial(dh.device.GetHostAndPort(), |
| 1214 | grpc.WithInsecure(), |
| 1215 | grpc.WithBlock(), |
| 1216 | grpc.WithStreamInterceptor(grpc_middleware.ChainStreamClient( |
| Girish Kumar | 935f7af | 2020-08-18 11:59:42 +0000 | [diff] [blame] | 1217 | grpc_opentracing.StreamClientInterceptor(grpc_opentracing.WithTracer(log.ActiveTracerProxy{})), |
| Girish Kumar | 93e9174 | 2020-07-27 16:43:19 +0000 | [diff] [blame] | 1218 | )), |
| 1219 | grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient( |
| Girish Kumar | 935f7af | 2020-08-18 11:59:42 +0000 | [diff] [blame] | 1220 | grpc_opentracing.UnaryClientInterceptor(grpc_opentracing.WithTracer(log.ActiveTracerProxy{})), |
| Girish Kumar | 93e9174 | 2020-07-27 16:43:19 +0000 | [diff] [blame] | 1221 | ))) |
| 1222 | |
| 1223 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1224 | return olterrors.NewErrCommunication("dial-failure", log.Fields{ |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1225 | "device-id": dh.device.Id, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1226 | "host-and-port": dh.device.GetHostAndPort()}, err) |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1227 | } |
| Akash Soni | f49299a | 2024-04-25 12:06:37 +0530 | [diff] [blame] | 1228 | //Setting oper and connection state to RECONCILING and conn state to reachable |
| 1229 | cgClient, err := dh.coreClient.GetCoreServiceClient() |
| 1230 | if err != nil { |
| 1231 | return err |
| 1232 | } |
| 1233 | |
| 1234 | if dh.device.OperStatus == voltha.OperStatus_RECONCILING { |
| 1235 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.openOLT.rpcTimeout) |
| 1236 | defer cancel() |
| 1237 | if _, err := cgClient.DeviceStateUpdate(subCtx, &ca.DeviceStateFilter{ |
| 1238 | DeviceId: dh.device.Id, |
| 1239 | OperStatus: voltha.OperStatus_RECONCILING, |
| 1240 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 1241 | }); err != nil { |
| 1242 | return olterrors.NewErrAdapter("device-update-failed", log.Fields{"device-id": dh.device.Id}, err) |
| 1243 | } |
| 1244 | // The OperState and connection state of the device is set to RECONCILING and REACHABLE in the previous section. This also needs to be set on the |
| 1245 | // locally cached copy of the device struct. |
| 1246 | dh.device.OperStatus = voltha.OperStatus_RECONCILING |
| 1247 | dh.device.ConnectStatus = voltha.ConnectStatus_REACHABLE |
| 1248 | } |
| 1249 | |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1250 | return nil |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | // postInit create olt client instance to invoke RPC on the olt device |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1254 | func (dh *DeviceHandler) postInit(ctx context.Context) error { |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1255 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1256 | dh.transitionMap.Handle(ctx, GrpcConnected) |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1257 | return nil |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | // doStateConnected get the device info and update to voltha core |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1261 | func (dh *DeviceHandler) doStateConnected(ctx context.Context) error { |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1262 | var err error |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1263 | logger.Debugw(ctx, "olt-device-connected", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1264 | |
| 1265 | // Case where OLT is disabled and then rebooted. |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1266 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1267 | if err != nil || device == nil { |
| 1268 | /*TODO: needs to handle error scenarios */ |
| 1269 | return olterrors.NewErrAdapter("device-fetch-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| 1270 | } |
| 1271 | if device.AdminState == voltha.AdminState_DISABLED { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1272 | logger.Debugln(ctx, "do-state-connected--device-admin-state-down") |
| Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1273 | |
| 1274 | cloned := proto.Clone(device).(*voltha.Device) |
| 1275 | cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE |
| 1276 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 1277 | dh.device = cloned |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1278 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1279 | if err = dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1280 | DeviceId: cloned.Id, |
| 1281 | OperStatus: cloned.OperStatus, |
| 1282 | ConnStatus: cloned.ConnectStatus, |
| 1283 | }); err != nil { |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1284 | return olterrors.NewErrAdapter("device-state-update-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1285 | } |
| 1286 | |
| Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 1287 | // Since the device was disabled before the OLT was rebooted, enforce the OLT to be Disabled after re-connection. |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1288 | _, err = dh.Client.DisableOlt(ctx, new(oop.Empty)) |
| Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1289 | if err != nil { |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1290 | return olterrors.NewErrAdapter("olt-disable-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1291 | } |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1292 | // We should still go ahead an initialize various device handler modules so that when OLT is re-enabled, we have |
| 1293 | // all the modules initialized and ready to handle incoming ONUs. |
| 1294 | |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1295 | err = dh.initializeDeviceHandlerModules(ctx) |
| 1296 | if err != nil { |
| 1297 | return olterrors.NewErrAdapter("device-handler-initialization-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1298 | } |
| Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1299 | |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1300 | go startHeartbeatCheck(ctx, dh) |
| 1301 | |
| Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1302 | return nil |
| 1303 | } |
| 1304 | |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1305 | if err := dh.initializeDeviceHandlerModules(ctx); err != nil { |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1306 | return olterrors.NewErrAdapter("device-handler-initialization-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1307 | } |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1308 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1309 | go dh.updateLocalDevice(ctx) |
| Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 1310 | |
| 1311 | if device.PmConfigs != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1312 | dh.UpdatePmConfig(ctx, device.PmConfigs) |
| Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 1313 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1314 | |
| 1315 | go startHeartbeatCheck(ctx, dh) |
| 1316 | |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1317 | return nil |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1318 | } |
| 1319 | |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1320 | func (dh *DeviceHandler) initializeDeviceHandlerModules(ctx context.Context) error { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1321 | var err error |
| 1322 | dh.deviceInfo, err = dh.populateDeviceInfo(ctx) |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1323 | |
| Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 1324 | if dh.flowMgr != nil { |
| 1325 | dh.StopAllFlowRoutines(ctx) |
| 1326 | } |
| 1327 | |
| 1328 | dh.CloseKVClient(ctx) |
| 1329 | |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1330 | if err != nil { |
| 1331 | return olterrors.NewErrAdapter("populate-device-info-failed", log.Fields{"device-id": dh.device.Id}, err) |
| 1332 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1333 | dh.totalPonPorts = dh.deviceInfo.GetPonPorts() |
| 1334 | dh.agentPreviouslyConnected = dh.deviceInfo.PreviouslyConnected |
| bseeniva | aa9165b | 2025-09-18 17:28:12 +0530 | [diff] [blame] | 1335 | // If collector go routine is active, wait for it to stop |
| 1336 | dh.lockDevice.RLock() |
| 1337 | if dh.isCollectorActive { |
| 1338 | dh.lockDevice.RUnlock() |
| 1339 | dh.collectorWaitGroup.Wait() |
| 1340 | } else { |
| 1341 | dh.lockDevice.RUnlock() |
| 1342 | } |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1343 | // +1 is for NNI |
| 1344 | dh.resourceMgr = make([]*rsrcMgr.OpenOltResourceMgr, dh.totalPonPorts+1) |
| 1345 | dh.flowMgr = make([]*OpenOltFlowMgr, dh.totalPonPorts+1) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1346 | var i uint32 |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1347 | // Index from 0 to until totalPonPorts ( Ex: 0 .. 15 ) -> PonPort Managers |
| 1348 | // Index totalPonPorts ( Ex: 16 ) -> NniPort Manager |
| 1349 | // There is only one NNI manager since multiple NNI is not supported for now |
| 1350 | for i = 0; i < dh.totalPonPorts+1; i++ { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1351 | // Instantiate resource manager |
| 1352 | if dh.resourceMgr[i] = rsrcMgr.NewResourceMgr(ctx, i, dh.device.Id, dh.openOLT.KVStoreAddress, dh.openOLT.KVStoreType, dh.device.Type, dh.deviceInfo, dh.cm.Backend.PathPrefix); dh.resourceMgr[i] == nil { |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1353 | return olterrors.ErrResourceManagerInstantiating |
| 1354 | } |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1355 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1356 | // GroupManager instance is per OLT. But it needs a reference to any instance of resourceMgr to interface with |
| 1357 | // the KV store to manage mcast group data. Provide the first instance (0th index) |
| 1358 | if dh.groupMgr = NewGroupManager(ctx, dh, dh.resourceMgr[0]); dh.groupMgr == nil { |
| 1359 | return olterrors.ErrGroupManagerInstantiating |
| 1360 | } |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1361 | for i = 0; i < dh.totalPonPorts+1; i++ { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1362 | // Instantiate flow manager |
| 1363 | if dh.flowMgr[i] = NewFlowManager(ctx, dh, dh.resourceMgr[i], dh.groupMgr, i); dh.flowMgr[i] == nil { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1364 | // Continue to check the rest of the ports |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 1365 | logger.Errorw(ctx, "error-initializing-flow-manager-for-intf", log.Fields{"intfID": i, "device-id": dh.device.Id}) |
| 1366 | } else { |
| 1367 | dh.resourceMgr[i].TechprofileRef = dh.flowMgr[i].techprofile |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1368 | } |
| 1369 | } |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1370 | /* TODO: Instantiate Alarm , stats , BW managers */ |
| 1371 | /* Instantiating Event Manager to handle Alarms and KPIs */ |
| 1372 | dh.eventMgr = NewEventMgr(dh.EventProxy, dh) |
| 1373 | |
| 1374 | // Stats config for new device |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1375 | dh.portStats = NewOpenOltStatsMgr(ctx, dh) |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1376 | |
| 1377 | return nil |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1378 | } |
| 1379 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1380 | func (dh *DeviceHandler) populateDeviceInfo(ctx context.Context) (*oop.DeviceInfo, error) { |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1381 | var err error |
| 1382 | var deviceInfo *oop.DeviceInfo |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1383 | var genmac string |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1384 | |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1385 | deviceInfo, err = dh.Client.GetDeviceInfo(log.WithSpanFromContext(context.Background(), ctx), new(oop.Empty)) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1386 | |
| 1387 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1388 | return nil, olterrors.NewErrPersistence("get", "device", 0, nil, err) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1389 | } |
| 1390 | if deviceInfo == nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1391 | return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1392 | } |
| 1393 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1394 | logger.Debugw(ctx, "fetched-device-info", log.Fields{"deviceInfo": deviceInfo, "device-id": dh.device.Id}) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1395 | dh.device.Root = true |
| 1396 | dh.device.Vendor = deviceInfo.Vendor |
| 1397 | dh.device.Model = deviceInfo.Model |
| 1398 | dh.device.SerialNumber = deviceInfo.DeviceSerialNumber |
| 1399 | dh.device.HardwareVersion = deviceInfo.HardwareVersion |
| 1400 | dh.device.FirmwareVersion = deviceInfo.FirmwareVersion |
| 1401 | |
| 1402 | if deviceInfo.DeviceId == "" { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1403 | logger.Warnw(ctx, "no-device-id-provided-using-host", log.Fields{"hostport": dh.device.GetHostAndPort()}) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1404 | host := strings.Split(dh.device.GetHostAndPort(), ":")[0] |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1405 | genmac, err = generateMacFromHost(ctx, host) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1406 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1407 | return nil, olterrors.NewErrAdapter("failed-to-generate-mac-host", log.Fields{"host": host}, err) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1408 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1409 | logger.Debugw(ctx, "using-host-for-mac-address", log.Fields{"host": host, "mac": genmac}) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1410 | dh.device.MacAddress = genmac |
| 1411 | } else { |
| 1412 | dh.device.MacAddress = deviceInfo.DeviceId |
| 1413 | } |
| 1414 | |
| 1415 | // Synchronous call to update device - this method is run in its own go routine |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1416 | if err = dh.updateDeviceInCore(ctx, dh.device); err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1417 | return nil, olterrors.NewErrAdapter("device-update-failed", log.Fields{"device-id": dh.device.Id}, err) |
| Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | return deviceInfo, nil |
| 1421 | } |
| 1422 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1423 | func startCollector(ctx context.Context, dh *DeviceHandler) { |
| bseeniva | aa9165b | 2025-09-18 17:28:12 +0530 | [diff] [blame] | 1424 | logger.Infow(ctx, "starting-collector", log.Fields{"device-id": dh.device.Id}) |
| Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 1425 | |
| 1426 | defer func() { |
| 1427 | dh.lockDevice.Lock() |
| 1428 | dh.isCollectorActive = false |
| 1429 | dh.lockDevice.Unlock() |
| bseeniva | aa9165b | 2025-09-18 17:28:12 +0530 | [diff] [blame] | 1430 | dh.collectorWaitGroup.Done() |
| Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 1431 | }() |
| 1432 | |
| 1433 | dh.lockDevice.Lock() |
| 1434 | dh.isCollectorActive = true |
| 1435 | dh.lockDevice.Unlock() |
| 1436 | |
| Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1437 | for { |
| 1438 | select { |
| 1439 | case <-dh.stopCollector: |
| bseeniva | aa9165b | 2025-09-18 17:28:12 +0530 | [diff] [blame] | 1440 | logger.Infow(ctx, "stopping-collector-for-olt", log.Fields{"device-id": dh.device.Id}) |
| Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1441 | return |
| Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 1442 | case <-time.After(time.Duration(dh.metrics.ToPmConfigs().DefaultFreq) * time.Second): |
| Girish Gowdra | 34815db | 2020-05-11 17:18:04 -0700 | [diff] [blame] | 1443 | |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1444 | ports, err := dh.listDevicePortsFromCore(ctx, dh.device.Id) |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 1445 | if err != nil { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1446 | logger.Warnw(ctx, "failed-to-list-ports", log.Fields{"device-id": dh.device.Id, "err": err}) |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 1447 | continue |
| 1448 | } |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1449 | for _, port := range ports.Items { |
| Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1450 | // NNI Stats |
| 1451 | if port.Type == voltha.Port_ETHERNET_NNI { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1452 | intfID := plt.PortNoToIntfID(port.PortNo, voltha.Port_ETHERNET_NNI) |
| Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1453 | cmnni := dh.portStats.collectNNIMetrics(intfID) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1454 | logger.Debugw(ctx, "collect-nni-metrics", log.Fields{"metrics": cmnni}) |
| Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 1455 | go dh.portStats.publishMetrics(ctx, NNIStats, cmnni, port, dh.device.Id, dh.device.Type) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1456 | logger.Debugw(ctx, "publish-nni-metrics", log.Fields{"nni-port": port.Label}) |
| Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1457 | } |
| 1458 | // PON Stats |
| 1459 | if port.Type == voltha.Port_PON_OLT { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1460 | intfID := plt.PortNoToIntfID(port.PortNo, voltha.Port_PON_OLT) |
| Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1461 | if val, ok := dh.activePorts.Load(intfID); ok && val == true { |
| 1462 | cmpon := dh.portStats.collectPONMetrics(intfID) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1463 | logger.Debugw(ctx, "collect-pon-metrics", log.Fields{"metrics": cmpon}) |
| Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 1464 | go dh.portStats.publishMetrics(ctx, PONStats, cmpon, port, dh.device.Id, dh.device.Type) |
| Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1465 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1466 | logger.Debugw(ctx, "publish-pon-metrics", log.Fields{"pon-port": port.Label}) |
| Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 1467 | |
| yasin sapli | 9e4c509 | 2022-02-01 13:52:33 +0000 | [diff] [blame] | 1468 | onuGemInfoLst := dh.resourceMgr[intfID].GetOnuGemInfoList(ctx) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1469 | if len(onuGemInfoLst) > 0 { |
| 1470 | go dh.portStats.collectOnuAndGemStats(ctx, onuGemInfoLst) |
| Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 1471 | } |
| Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 1472 | } |
| Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1473 | } |
| 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 1478 | // AdoptDevice adopts the OLT device |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1479 | func (dh *DeviceHandler) AdoptDevice(ctx context.Context, device *voltha.Device) { |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1480 | dh.transitionMap = NewTransitionMap(dh) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1481 | logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id, "Address": device.GetHostAndPort()}) |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1482 | dh.transitionMap.Handle(ctx, DeviceInit) |
| Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1483 | |
| 1484 | // Now, set the initial PM configuration for that device |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1485 | cgClient, err := dh.coreClient.GetCoreServiceClient() |
| 1486 | if err != nil { |
| 1487 | logger.Errorw(ctx, "no-core-connection", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 1488 | return |
| 1489 | } |
| 1490 | |
| 1491 | // Now, set the initial PM configuration for that device |
| 1492 | if _, err := cgClient.DevicePMConfigUpdate(ctx, dh.metrics.ToPmConfigs()); err != nil { |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1493 | _ = olterrors.NewErrAdapter("error-updating-performance-metrics", log.Fields{"device-id": device.Id}, err).LogAt(log.ErrorLevel) |
| Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1494 | } |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1495 | } |
| 1496 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 1497 | // GetOfpDeviceInfo Gets the Ofp information of the given device |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1498 | func (dh *DeviceHandler) GetOfpDeviceInfo(device *voltha.Device) (*ca.SwitchCapability, error) { |
| 1499 | return &ca.SwitchCapability{ |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1500 | Desc: &of.OfpDesc{ |
| Devmalya Paul | 70dd497 | 2019-06-10 15:19:17 +0530 | [diff] [blame] | 1501 | MfrDesc: "VOLTHA Project", |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1502 | HwDesc: "open_pon", |
| 1503 | SwDesc: "open_pon", |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1504 | SerialNum: device.SerialNumber, |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1505 | }, |
| 1506 | SwitchFeatures: &of.OfpSwitchFeatures{ |
| 1507 | NBuffers: 256, |
| 1508 | NTables: 2, |
| 1509 | Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS | |
| 1510 | of.OfpCapabilities_OFPC_TABLE_STATS | |
| 1511 | of.OfpCapabilities_OFPC_PORT_STATS | |
| 1512 | of.OfpCapabilities_OFPC_GROUP_STATS), |
| 1513 | }, |
| 1514 | }, nil |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1515 | } |
| 1516 | |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1517 | // GetTechProfileDownloadMessage fetches the TechProfileDownloadMessage for the caller. |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1518 | func (dh *DeviceHandler) GetTechProfileDownloadMessage(ctx context.Context, request *ia.TechProfileInstanceRequestMessage) (*ia.TechProfileDownloadMessage, error) { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1519 | ifID, err := plt.IntfIDFromPonPortNum(ctx, request.ParentPonPort) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1520 | if err != nil { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1521 | return nil, err |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1522 | } |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 1523 | if dh.flowMgr == nil || dh.flowMgr[ifID] == nil { |
| 1524 | return nil, olterrors.NewErrNotFound("no-flow-manager-found", log.Fields{"intf-id": ifID, "parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log() |
| 1525 | } |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1526 | return dh.flowMgr[ifID].getTechProfileDownloadMessage(ctx, request.TpInstancePath, request.OnuId, request.DeviceId) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1529 | func (dh *DeviceHandler) omciIndication(ctx context.Context, omciInd *oop.OmciIndication) error { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1530 | logger.Debugw(ctx, "omci-indication", log.Fields{"intf-id": omciInd.IntfId, "onu-id": omciInd.OnuId, "parent-device-id": dh.device.Id}) |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1531 | var deviceType string |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1532 | var deviceID string |
| 1533 | var proxyDeviceID string |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1534 | var childAdapterEndpoint string |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1535 | |
| Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1536 | transid := extractOmciTransactionID(omciInd.Pkt) |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1537 | if logger.V(log.DebugLevel) { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1538 | logger.Debugw(ctx, "recv-omci-msg", log.Fields{"intf-id": omciInd.IntfId, "onu-id": omciInd.OnuId, "device-id": dh.device.Id, |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1539 | "omci-transaction-id": transid, "omci-msg": hex.EncodeToString(omciInd.Pkt)}) |
| 1540 | } |
| Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1541 | |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1542 | onuKey := dh.formOnuKey(omciInd.IntfId, omciInd.OnuId) |
| Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1543 | |
| 1544 | if onuInCache, ok := dh.onus.Load(onuKey); !ok { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1545 | logger.Debugw(ctx, "omci-indication-for-a-device-not-in-cache.", log.Fields{"intf-id": omciInd.IntfId, "onu-id": omciInd.OnuId, "device-id": dh.device.Id}) |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1546 | ponPort := plt.IntfIDToPortNo(omciInd.GetIntfId(), voltha.Port_PON_OLT) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1547 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1548 | onuDevice, err := dh.getChildDeviceFromCore(ctx, &ca.ChildDeviceFilter{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1549 | ParentId: dh.device.Id, |
| 1550 | OnuId: omciInd.OnuId, |
| 1551 | ParentPortNo: ponPort, |
| 1552 | }) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1553 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1554 | return olterrors.NewErrNotFound("onu", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1555 | "intf-id": omciInd.IntfId, |
| 1556 | "onu-id": omciInd.OnuId}, err) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1557 | } |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1558 | deviceType = onuDevice.Type |
| 1559 | deviceID = onuDevice.Id |
| 1560 | proxyDeviceID = onuDevice.ProxyAddress.DeviceId |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1561 | childAdapterEndpoint = onuDevice.AdapterEndpoint |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1562 | // if not exist in cache, then add to cache. |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1563 | dh.onus.Store(onuKey, NewOnuDevice(deviceID, deviceType, onuDevice.SerialNumber, omciInd.OnuId, omciInd.IntfId, proxyDeviceID, false, onuDevice.AdapterEndpoint)) |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1564 | } else { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1565 | // found in cache |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1566 | logger.Debugw(ctx, "omci-indication-for-a-device-in-cache.", log.Fields{"intf-id": omciInd.IntfId, "onu-id": omciInd.OnuId, "device-id": dh.device.Id}) |
| Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1567 | deviceType = onuInCache.(*OnuDevice).deviceType |
| 1568 | deviceID = onuInCache.(*OnuDevice).deviceID |
| 1569 | proxyDeviceID = onuInCache.(*OnuDevice).proxyDeviceID |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1570 | childAdapterEndpoint = onuInCache.(*OnuDevice).adapterEndpoint |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1571 | } |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1572 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1573 | if err := dh.sendOmciIndicationToChildAdapter(ctx, childAdapterEndpoint, &ia.OmciMessage{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1574 | ParentDeviceId: proxyDeviceID, |
| 1575 | ChildDeviceId: deviceID, |
| 1576 | Message: omciInd.Pkt, |
| 1577 | }); err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1578 | return olterrors.NewErrCommunication("omci-request", log.Fields{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1579 | "source": dh.openOLT.config.AdapterEndpoint, |
| 1580 | "device-type": deviceType, |
| 1581 | "destination": childAdapterEndpoint, |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1582 | "onu-id": deviceID, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1583 | "proxy-device-id": proxyDeviceID}, err) |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1584 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1585 | return nil |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1586 | } |
| 1587 | |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1588 | // //ProcessInterAdapterMessage sends the proxied messages to the target device |
| 1589 | // // If the proxy address is not found in the unmarshalled message, it first fetches the onu device for which the message |
| 1590 | // // is meant, and then send the unmarshalled omci message to this onu |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1591 | // func (dh *DeviceHandler) ProcessInterAdapterMessage(ctx context.Context, msg *ca.InterAdapterMessage) error { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1592 | // logger.Debugw(ctx, "process-inter-adapter-message", log.Fields{"msgID": msg.Header.Id}) |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1593 | // if msg.Header.Type == ca.InterAdapterMessageType_OMCI_REQUEST { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1594 | // return dh.handleInterAdapterOmciMsg(ctx, msg) |
| 1595 | // } |
| 1596 | // return olterrors.NewErrInvalidValue(log.Fields{"inter-adapter-message-type": msg.Header.Type}, nil) |
| 1597 | // } |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1598 | |
| kesavand | b9f54fd | 2021-11-25 20:08:04 +0530 | [diff] [blame] | 1599 | // ProxyOmciRequests sends the proxied OMCI message to the target device |
| 1600 | func (dh *DeviceHandler) ProxyOmciRequests(ctx context.Context, omciMsgs *ia.OmciMessages) error { |
| Abhilash Laxmeshwar | 092e6ca | 2022-12-08 19:51:27 +0530 | [diff] [blame] | 1601 | if DeviceState(dh.device.ConnectStatus) != DeviceState(voltha.ConnectStatus_REACHABLE) { |
| 1602 | return status.Error(codes.Unavailable, "OLT unreachable") |
| 1603 | } |
| kesavand | b9f54fd | 2021-11-25 20:08:04 +0530 | [diff] [blame] | 1604 | if omciMsgs.GetProxyAddress() == nil { |
| 1605 | onuDevice, err := dh.getDeviceFromCore(ctx, omciMsgs.ChildDeviceId) |
| 1606 | if err != nil { |
| 1607 | return olterrors.NewErrNotFound("onu", log.Fields{ |
| 1608 | "parent-device-id": dh.device.Id, |
| 1609 | "child-device-id": omciMsgs.ChildDeviceId}, err) |
| 1610 | } |
| 1611 | logger.Debugw(ctx, "device-retrieved-from-core", log.Fields{"onu-device-proxy-address": onuDevice.ProxyAddress}) |
| 1612 | if err := dh.sendProxyOmciRequests(log.WithSpanFromContext(context.Background(), ctx), onuDevice, omciMsgs); err != nil { |
| 1613 | return olterrors.NewErrCommunication("send-failed", log.Fields{ |
| 1614 | "parent-device-id": dh.device.Id, |
| 1615 | "child-device-id": omciMsgs.ChildDeviceId}, err) |
| 1616 | } |
| 1617 | } else { |
| 1618 | logger.Debugw(ctx, "proxy-address-found-in-omci-message", log.Fields{"onu-device-proxy-address": omciMsgs.ProxyAddress}) |
| 1619 | if err := dh.sendProxyOmciRequests(log.WithSpanFromContext(context.Background(), ctx), nil, omciMsgs); err != nil { |
| 1620 | return olterrors.NewErrCommunication("send-failed", log.Fields{ |
| 1621 | "parent-device-id": dh.device.Id, |
| 1622 | "child-device-id": omciMsgs.ChildDeviceId}, err) |
| 1623 | } |
| 1624 | } |
| 1625 | return nil |
| 1626 | } |
| 1627 | |
| 1628 | func (dh *DeviceHandler) sendProxyOmciRequests(ctx context.Context, onuDevice *voltha.Device, omciMsgs *ia.OmciMessages) error { |
| 1629 | var intfID uint32 |
| 1630 | var onuID uint32 |
| 1631 | var connectStatus common.ConnectStatus_Types |
| 1632 | if onuDevice != nil { |
| 1633 | intfID = onuDevice.ProxyAddress.GetChannelId() |
| 1634 | onuID = onuDevice.ProxyAddress.GetOnuId() |
| 1635 | connectStatus = onuDevice.ConnectStatus |
| 1636 | } else { |
| 1637 | intfID = omciMsgs.GetProxyAddress().GetChannelId() |
| 1638 | onuID = omciMsgs.GetProxyAddress().GetOnuId() |
| 1639 | connectStatus = omciMsgs.GetConnectStatus() |
| 1640 | } |
| 1641 | if connectStatus != voltha.ConnectStatus_REACHABLE { |
| 1642 | logger.Debugw(ctx, "onu-not-reachable--cannot-send-omci", log.Fields{"intf-id": intfID, "onu-id": onuID}) |
| 1643 | |
| 1644 | return olterrors.NewErrCommunication("unreachable", log.Fields{ |
| 1645 | "intf-id": intfID, |
| 1646 | "onu-id": onuID}, nil) |
| 1647 | } |
| 1648 | |
| 1649 | // TODO: OpenOLT Agent oop.OmciMsg expects a hex encoded string for OMCI packets rather than the actual bytes. |
| 1650 | // Fix this in the agent and then we can pass byte array as Pkt: omciMsg.Message. |
| 1651 | |
| 1652 | onuSecOmciMsgList := omciMsgs.GetMessages() |
| 1653 | |
| 1654 | for _, onuSecOmciMsg := range onuSecOmciMsgList { |
| kesavand | b9f54fd | 2021-11-25 20:08:04 +0530 | [diff] [blame] | 1655 | var omciMessage *oop.OmciMsg |
| 1656 | hexPkt := make([]byte, hex.EncodedLen(len(onuSecOmciMsg))) |
| 1657 | hex.Encode(hexPkt, onuSecOmciMsg) |
| 1658 | omciMessage = &oop.OmciMsg{IntfId: intfID, OnuId: onuID, Pkt: hexPkt} |
| 1659 | |
| 1660 | // TODO: Below logging illustrates the "stringify" of the omci Pkt. |
| 1661 | // once above is fixed this log line can change to just use hex.EncodeToString(omciMessage.Pkt) |
| 1662 | //https://jira.opencord.org/browse/VOL-4604 |
| 1663 | transid := extractOmciTransactionID(onuSecOmciMsg) |
| 1664 | logger.Debugw(ctx, "sent-omci-msg", log.Fields{"intf-id": intfID, "onu-id": onuID, |
| 1665 | "omciTransactionID": transid, "omciMsg": string(omciMessage.Pkt)}) |
| 1666 | |
| 1667 | _, err := dh.Client.OmciMsgOut(log.WithSpanFromContext(context.Background(), ctx), omciMessage) |
| 1668 | if err != nil { |
| 1669 | return olterrors.NewErrCommunication("omci-send-failed", log.Fields{ |
| 1670 | "intf-id": intfID, |
| 1671 | "onu-id": onuID, |
| 1672 | "message": omciMessage}, err) |
| 1673 | } |
| 1674 | } |
| 1675 | return nil |
| 1676 | } |
| 1677 | |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1678 | // ProxyOmciMessage sends the proxied OMCI message to the target device |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1679 | func (dh *DeviceHandler) ProxyOmciMessage(ctx context.Context, omciMsg *ia.OmciMessage) error { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1680 | logger.Debugw(ctx, "proxy-omci-message", log.Fields{"parent-device-id": omciMsg.ParentDeviceId, "child-device-id": omciMsg.ChildDeviceId, "proxy-address": omciMsg.ProxyAddress, "connect-status": omciMsg.ConnectStatus}) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1681 | |
| Abhilash Laxmeshwar | 092e6ca | 2022-12-08 19:51:27 +0530 | [diff] [blame] | 1682 | if DeviceState(dh.device.ConnectStatus) != DeviceState(voltha.ConnectStatus_REACHABLE) { |
| 1683 | return status.Error(codes.Unavailable, "OLT unreachable") |
| 1684 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1685 | if omciMsg.GetProxyAddress() == nil { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1686 | onuDevice, err := dh.getDeviceFromCore(ctx, omciMsg.ChildDeviceId) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1687 | if err != nil { |
| 1688 | return olterrors.NewErrNotFound("onu", log.Fields{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1689 | "parent-device-id": dh.device.Id, |
| 1690 | "child-device-id": omciMsg.ChildDeviceId}, err) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1691 | } |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1692 | logger.Debugw(ctx, "device-retrieved-from-core", log.Fields{"onu-device-proxy-address": onuDevice.ProxyAddress}) |
| 1693 | if err := dh.sendProxiedMessage(log.WithSpanFromContext(context.Background(), ctx), onuDevice, omciMsg); err != nil { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1694 | return olterrors.NewErrCommunication("send-failed", log.Fields{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1695 | "parent-device-id": dh.device.Id, |
| 1696 | "child-device-id": omciMsg.ChildDeviceId}, err) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1697 | } |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1698 | } else { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1699 | logger.Debugw(ctx, "proxy-address-found-in-omci-message", log.Fields{"onu-device-proxy-address": omciMsg.ProxyAddress}) |
| 1700 | if err := dh.sendProxiedMessage(log.WithSpanFromContext(context.Background(), ctx), nil, omciMsg); err != nil { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1701 | return olterrors.NewErrCommunication("send-failed", log.Fields{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1702 | "parent-device-id": dh.device.Id, |
| 1703 | "child-device-id": omciMsg.ChildDeviceId}, err) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1704 | } |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1705 | } |
| 1706 | return nil |
| Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1707 | } |
| 1708 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1709 | func (dh *DeviceHandler) sendProxiedMessage(ctx context.Context, onuDevice *voltha.Device, omciMsg *ia.OmciMessage) error { |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1710 | var intfID uint32 |
| 1711 | var onuID uint32 |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1712 | var connectStatus common.ConnectStatus_Types |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1713 | if onuDevice != nil { |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1714 | intfID = onuDevice.ProxyAddress.GetChannelId() |
| 1715 | onuID = onuDevice.ProxyAddress.GetOnuId() |
| 1716 | connectStatus = onuDevice.ConnectStatus |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1717 | } else { |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1718 | intfID = omciMsg.GetProxyAddress().GetChannelId() |
| 1719 | onuID = omciMsg.GetProxyAddress().GetOnuId() |
| 1720 | connectStatus = omciMsg.GetConnectStatus() |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1721 | } |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1722 | if connectStatus != voltha.ConnectStatus_REACHABLE { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1723 | logger.Debugw(ctx, "onu-not-reachable--cannot-send-omci", log.Fields{"intf-id": intfID, "onu-id": onuID}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1724 | |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1725 | return olterrors.NewErrCommunication("unreachable", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1726 | "intf-id": intfID, |
| 1727 | "onu-id": onuID}, nil) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
| Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1730 | // TODO: OpenOLT Agent oop.OmciMsg expects a hex encoded string for OMCI packets rather than the actual bytes. |
| 1731 | // Fix this in the agent and then we can pass byte array as Pkt: omciMsg.Message. |
| kesavand | b9f54fd | 2021-11-25 20:08:04 +0530 | [diff] [blame] | 1732 | // https://jira.opencord.org/browse/VOL-4604 |
| lcui | e24ef18 | 2019-04-29 22:58:36 -0700 | [diff] [blame] | 1733 | var omciMessage *oop.OmciMsg |
| Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1734 | hexPkt := make([]byte, hex.EncodedLen(len(omciMsg.Message))) |
| 1735 | hex.Encode(hexPkt, omciMsg.Message) |
| 1736 | omciMessage = &oop.OmciMsg{IntfId: intfID, OnuId: onuID, Pkt: hexPkt} |
| 1737 | |
| 1738 | // TODO: Below logging illustrates the "stringify" of the omci Pkt. |
| 1739 | // once above is fixed this log line can change to just use hex.EncodeToString(omciMessage.Pkt) |
| 1740 | transid := extractOmciTransactionID(omciMsg.Message) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1741 | logger.Debugw(ctx, "sent-omci-msg", log.Fields{"intf-id": intfID, "onu-id": onuID, |
| Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1742 | "omciTransactionID": transid, "omciMsg": string(omciMessage.Pkt)}) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1743 | |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1744 | _, err := dh.Client.OmciMsgOut(log.WithSpanFromContext(context.Background(), ctx), omciMessage) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1745 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1746 | return olterrors.NewErrCommunication("omci-send-failed", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1747 | "intf-id": intfID, |
| 1748 | "onu-id": onuID, |
| 1749 | "message": omciMessage}, err) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1750 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1751 | return nil |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1754 | func (dh *DeviceHandler) activateONU(ctx context.Context, intfID uint32, onuID int64, serialNum *oop.SerialNumber, serialNumber string) error { |
| kesavand | 494c208 | 2020-08-31 11:16:12 +0530 | [diff] [blame] | 1755 | logger.Debugw(ctx, "activate-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "serialNum": serialNum, "serialNumber": serialNumber, "device-id": dh.device.Id, "OmccEncryption": dh.openOLT.config.OmccEncryption}) |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1756 | if err := dh.resourceMgr[intfID].AddNewOnuGemInfoToCacheAndKvStore(ctx, uint32(onuID), serialNumber); err != nil { |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1757 | return olterrors.NewErrAdapter("onu-activate-failed", log.Fields{"onu": onuID, "intf-id": intfID}, err) |
| Andrea Campanella | b83b39d | 2020-03-30 11:41:16 +0200 | [diff] [blame] | 1758 | } |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1759 | var pir uint32 = 1000000 |
| kesavand | 494c208 | 2020-08-31 11:16:12 +0530 | [diff] [blame] | 1760 | Onu := oop.Onu{IntfId: intfID, OnuId: uint32(onuID), SerialNumber: serialNum, Pir: pir, OmccEncryption: dh.openOLT.config.OmccEncryption} |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1761 | if _, err := dh.Client.ActivateOnu(ctx, &Onu); err != nil { |
| Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1762 | st, _ := status.FromError(err) |
| 1763 | if st.Code() == codes.AlreadyExists { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1764 | logger.Debugw(ctx, "onu-activation-in-progress", log.Fields{"SerialNumber": serialNumber, "onu-id": onuID, "device-id": dh.device.Id}) |
| Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1765 | } else { |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1766 | return olterrors.NewErrAdapter("onu-activate-failed", log.Fields{"onu": Onu, "device-id": dh.device.Id}, err) |
| Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1767 | } |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1768 | } else { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1769 | logger.Infow(ctx, "activated-onu", log.Fields{"SerialNumber": serialNumber, "device-id": dh.device.Id}) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1770 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1771 | return nil |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 1774 | // getChildDevice function can be used in general to get child device, if not found in cache the function will |
| 1775 | // get from core and update the cache and return the child device. |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1776 | func (dh *DeviceHandler) getChildDevice(ctx context.Context, sn string, parentPortNo uint32) *OnuDevice { |
| 1777 | var InCacheOnuDev *OnuDevice |
| 1778 | dh.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool { |
| 1779 | if onuInCache.(*OnuDevice).serialNumber == sn { |
| 1780 | InCacheOnuDev = onuInCache.(*OnuDevice) |
| 1781 | return false |
| 1782 | } |
| 1783 | return true |
| 1784 | }) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1785 | // Got the onu device from cache return |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1786 | if InCacheOnuDev != nil { |
| 1787 | logger.Debugw(ctx, "Got child device from cache", log.Fields{"onudev": InCacheOnuDev.serialNumber}) |
| 1788 | return InCacheOnuDev |
| 1789 | } |
| 1790 | onuDevice, _ := dh.getChildDeviceFromCore(ctx, &ca.ChildDeviceFilter{ |
| 1791 | ParentId: dh.device.Id, |
| 1792 | SerialNumber: sn, |
| 1793 | ParentPortNo: parentPortNo, |
| 1794 | }) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1795 | // No device found in core return nil |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1796 | if onuDevice == nil { |
| 1797 | return nil |
| 1798 | } |
| 1799 | onuID := onuDevice.ProxyAddress.OnuId |
| 1800 | intfID := plt.PortNoToIntfID(parentPortNo, voltha.Port_PON_OLT) |
| 1801 | onuKey := dh.formOnuKey(intfID, onuID) |
| 1802 | |
| 1803 | onuDev := NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuDevice.ProxyAddress.OnuId, intfID, onuDevice.ProxyAddress.DeviceId, false, onuDevice.AdapterEndpoint) |
| 1804 | dh.onus.Store(onuKey, onuDev) |
| 1805 | logger.Debugw(ctx, "got child device from core", log.Fields{"onudev": onuDevice}) |
| 1806 | return onuDev |
| 1807 | } |
| 1808 | |
| Sridhar Ravindra | ab785f2 | 2025-07-21 17:20:55 +0530 | [diff] [blame] | 1809 | // checkForResourceExistance checks for either device in rw-core or active techprofile in olt-adapter, based on the flag CheckOnuDevExistenceAtOnuDiscovery. |
| 1810 | // If the ONU device/resource exists in either of these, the ONU discovery will be ignored. |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1811 | func (dh *DeviceHandler) checkForResourceExistance(ctx context.Context, onuDiscInd *oop.OnuDiscIndication, sn string) (bool, error) { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1812 | parentPortNo := plt.IntfIDToPortNo(onuDiscInd.GetIntfId(), voltha.Port_PON_OLT) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1813 | // CheckOnuDevExistenceAtOnuDiscovery if true , a check will be made for the existence of the onu device. If the onu device |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1814 | // still exists , the onu discovery will be ignored, else a check for active techprofiles for ONU is checked. |
| Sridhar Ravindra | ab785f2 | 2025-07-21 17:20:55 +0530 | [diff] [blame] | 1815 | if dh.openOLT.CheckOnuDevExistenceAtOnuDiscovery { |
| 1816 | onuDevice, _ := dh.getChildDeviceFromCore(ctx, &ca.ChildDeviceFilter{ |
| 1817 | ParentId: dh.device.Id, |
| 1818 | SerialNumber: sn, |
| 1819 | ParentPortNo: parentPortNo, |
| 1820 | }) |
| 1821 | if onuDevice != nil { |
| 1822 | logger.Infow(ctx, "Child device still present ignoring discovery indication", log.Fields{"sn": sn}) |
| 1823 | return true, nil |
| 1824 | } |
| 1825 | logger.Infow(ctx, "No device present in core , continuing with discovery", log.Fields{"sn": sn}) |
| 1826 | |
| 1827 | return false, nil |
| 1828 | } else { |
| 1829 | tpInstExists := false |
| 1830 | channelID := onuDiscInd.GetIntfId() |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1831 | onuDev := dh.getChildDevice(ctx, sn, parentPortNo) |
| 1832 | if onuDev != nil { |
| 1833 | var onuGemInfo *rsrcMgr.OnuGemInfo |
| 1834 | var err error |
| 1835 | if onuGemInfo, err = dh.resourceMgr[channelID].GetOnuGemInfo(ctx, onuDev.onuID); err != nil { |
| 1836 | logger.Warnw(ctx, "Unable to find onuGemInfo", log.Fields{"onuID": onuDev.onuID}) |
| 1837 | return false, err |
| 1838 | } |
| 1839 | if onuGemInfo != nil { |
| 1840 | for _, uni := range onuGemInfo.UniPorts { |
| 1841 | uniID := plt.UniIDFromPortNum(uni) |
| 1842 | tpIDs := dh.resourceMgr[channelID].GetTechProfileIDForOnu(ctx, onuDev.onuID, uniID) |
| 1843 | if len(tpIDs) != 0 { |
| 1844 | logger.Warnw(ctx, "Techprofile present for ONU, ignoring onu discovery", log.Fields{"onuID": onuDev.onuID}) |
| 1845 | tpInstExists = true |
| 1846 | break |
| 1847 | } |
| 1848 | } |
| 1849 | } |
| 1850 | } |
| 1851 | return tpInstExists, nil |
| 1852 | } |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1853 | } |
| 1854 | |
| Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 1855 | // processDiscONULOSClear clears the LOS Alarm if it's needed |
| 1856 | func (dh *DeviceHandler) processDiscONULOSClear(ctx context.Context, onuDiscInd *oop.OnuDiscIndication, sn string) { |
| Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 1857 | var alarmInd oop.OnuAlarmIndication |
| Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 1858 | raisedTs := time.Now().Unix() |
| Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 1859 | |
| Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 1860 | /* When PON cable disconnected and connected back from OLT, it was expected OnuAlarmIndication |
| 1861 | with "los_status: off" should be raised but BAL does not raise this Alarm hence manually sending |
| 1862 | OnuLosClear event on receiving OnuDiscoveryIndication for the Onu after checking whether |
| 1863 | OnuLosRaise event sent for it */ |
| 1864 | dh.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool { |
| 1865 | if onuInCache.(*OnuDevice).serialNumber == sn && onuInCache.(*OnuDevice).losRaised { |
| 1866 | if onuDiscInd.GetIntfId() != onuInCache.(*OnuDevice).intfID { |
| 1867 | logger.Warnw(ctx, "onu-is-on-a-different-intf-id-now", log.Fields{ |
| 1868 | "previousIntfId": onuInCache.(*OnuDevice).intfID, |
| 1869 | "currentIntfId": onuDiscInd.GetIntfId()}) |
| 1870 | // TODO:: Should we need to ignore raising OnuLosClear event |
| 1871 | // when onu connected to different PON? |
| Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 1872 | } |
| Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 1873 | alarmInd.IntfId = onuInCache.(*OnuDevice).intfID |
| 1874 | alarmInd.OnuId = onuInCache.(*OnuDevice).onuID |
| 1875 | alarmInd.LosStatus = statusCheckOff |
| 1876 | go func() { |
| 1877 | if err := dh.eventMgr.onuAlarmIndication(ctx, &alarmInd, onuInCache.(*OnuDevice).deviceID, raisedTs); err != nil { |
| 1878 | logger.Errorw(ctx, "indication-failed", log.Fields{"err": err}) |
| 1879 | } |
| 1880 | }() |
| 1881 | // stop iterating |
| 1882 | return false |
| 1883 | } |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1884 | return true |
| Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 1885 | }) |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1886 | } |
| 1887 | |
| bseeniva | 43b5a91 | 2025-06-05 12:48:15 +0530 | [diff] [blame] | 1888 | func (dh *DeviceHandler) handleOnuDiscoveryProcessingError(ctx context.Context, err error, sn string, tpInstExists bool) { |
| 1889 | if err != nil || tpInstExists { |
| 1890 | logger.Infow(ctx, "onu-processing-errored-out-not-adding-to-discovery-map", log.Fields{"sn": sn}) |
| 1891 | } else { |
| 1892 | // once the function completes set the value to false so that |
| 1893 | // we know the processing has inProcess. |
| 1894 | // Note that this is done after checking if we are already processing |
| 1895 | // to avoid changing the value from a different thread |
| 1896 | logger.Infow(ctx, "onu-processing-completed", log.Fields{"sn": sn}) |
| 1897 | dh.discOnus.Store(sn, false) |
| 1898 | } |
| 1899 | } |
| 1900 | |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1901 | func (dh *DeviceHandler) onuDiscIndication(ctx context.Context, onuDiscInd *oop.OnuDiscIndication) error { |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1902 | var error error |
| bseeniva | 43b5a91 | 2025-06-05 12:48:15 +0530 | [diff] [blame] | 1903 | var tpInstExists bool |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1904 | |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1905 | channelID := onuDiscInd.GetIntfId() |
| 1906 | parentPortNo := plt.IntfIDToPortNo(onuDiscInd.GetIntfId(), voltha.Port_PON_OLT) |
| 1907 | |
| 1908 | sn := dh.stringifySerialNumber(onuDiscInd.SerialNumber) |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1909 | defer func() { |
| bseeniva | 43b5a91 | 2025-06-05 12:48:15 +0530 | [diff] [blame] | 1910 | dh.handleOnuDiscoveryProcessingError(ctx, error, sn, tpInstExists) |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1911 | }() |
| 1912 | |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1913 | logger.Infow(ctx, "new-discovery-indication", log.Fields{"sn": sn}) |
| 1914 | |
| Sridhar Ravindra | ab785f2 | 2025-07-21 17:20:55 +0530 | [diff] [blame] | 1915 | // Check for resource existence only if the ForceOnuDiscIndProcessing is disabled. |
| 1916 | if !dh.cfg.ForceOnuDiscIndProcessing { |
| 1917 | tpInstExists, error = dh.checkForResourceExistance(ctx, onuDiscInd, sn) |
| 1918 | if error != nil { |
| 1919 | return error |
| 1920 | } |
| 1921 | if tpInstExists { |
| 1922 | // ignore the discovery if tpinstance is present. |
| 1923 | logger.Debugw(ctx, "ignoring-onu-indication-as-tp-already-exists", log.Fields{"sn": sn}) |
| 1924 | return nil |
| 1925 | } |
| Amit Ghosh | e5c6a85 | 2020-02-10 15:09:46 +0000 | [diff] [blame] | 1926 | } |
| Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 1927 | inProcess, existing := dh.discOnus.LoadOrStore(sn, true) |
| 1928 | |
| 1929 | // if the ONU existed, handle the LOS Alarm |
| 1930 | if existing { |
| Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 1931 | if inProcess.(bool) { |
| 1932 | // if we're currently processing the ONU on a different thread, do nothing |
| 1933 | logger.Warnw(ctx, "onu-sn-is-being-processed", log.Fields{"sn": sn}) |
| 1934 | return nil |
| 1935 | } |
| 1936 | // if we had dealt with this ONU before, but the process didn't complete (this happens in case of errors) |
| 1937 | // then continue processing it |
| 1938 | logger.Debugw(ctx, "onu-processing-had-completed-but-new-indication", log.Fields{"sn": sn}) |
| 1939 | |
| 1940 | dh.processDiscONULOSClear(ctx, onuDiscInd, sn) |
| serkantul | e333d15 | 2022-10-12 01:44:00 +0300 | [diff] [blame] | 1941 | return nil |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1942 | } |
| Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 1943 | var onuID uint32 |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1944 | |
| 1945 | // check the ONU is already know to the OLT |
| 1946 | // NOTE the second time the ONU is discovered this should return a device |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1947 | onuDevice, error := dh.getChildDeviceFromCore(ctx, &ca.ChildDeviceFilter{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1948 | ParentId: dh.device.Id, |
| 1949 | SerialNumber: sn, |
| 1950 | }) |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1951 | |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1952 | if error != nil { |
| 1953 | logger.Debugw(ctx, "core-proxy-get-child-device-failed", log.Fields{"parentDevice": dh.device.Id, "err": error, "sn": sn}) |
| 1954 | if e, ok := status.FromError(error); ok { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1955 | logger.Debugw(ctx, "core-proxy-get-child-device-failed-with-code", log.Fields{"errCode": e.Code(), "sn": sn}) |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1956 | switch e.Code() { |
| 1957 | case codes.Internal: |
| 1958 | // this probably means NOT FOUND, so just create a new device |
| 1959 | onuDevice = nil |
| 1960 | case codes.DeadlineExceeded: |
| 1961 | // if the call times out, cleanup and exit |
| 1962 | dh.discOnus.Delete(sn) |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1963 | error = olterrors.NewErrTimeout("get-child-device", log.Fields{"device-id": dh.device.Id}, error) |
| 1964 | return error |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1965 | } |
| 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | if onuDevice == nil { |
| 1970 | // NOTE this should happen a single time, and only if GetChildDevice returns NotFound |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1971 | logger.Debugw(ctx, "creating-new-onu", log.Fields{"sn": sn}) |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1972 | // we need to create a new ChildDevice |
| Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 1973 | ponintfid := onuDiscInd.GetIntfId() |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1974 | onuID, error = dh.resourceMgr[ponintfid].GetONUID(ctx) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1975 | logger.Infow(ctx, "creating-new-onu-got-onu-id", log.Fields{"sn": sn, "onuId": onuID}) |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1976 | |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1977 | if error != nil { |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1978 | // if we can't create an ID in resource manager, |
| 1979 | // cleanup and exit |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1980 | dh.discOnus.Delete(sn) |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1981 | |
| 1982 | error = olterrors.NewErrAdapter("resource-manager-get-onu-id-failed", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1983 | "pon-intf-id": ponintfid, |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1984 | "serial-number": sn}, error) |
| 1985 | return error |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1986 | } |
| 1987 | |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1988 | if onuDevice, error = dh.sendChildDeviceDetectedToCore(ctx, &ca.DeviceDiscovery{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1989 | ParentId: dh.device.Id, |
| 1990 | ParentPortNo: parentPortNo, |
| 1991 | ChannelId: channelID, |
| 1992 | VendorId: string(onuDiscInd.SerialNumber.GetVendorId()), |
| 1993 | SerialNumber: sn, |
| 1994 | OnuId: onuID, |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1995 | }); error != nil { |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1996 | dh.discOnus.Delete(sn) |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1997 | dh.resourceMgr[ponintfid].FreeonuID(ctx, []uint32{onuID}) // NOTE I'm not sure this method is actually cleaning up the right thing |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1998 | |
| 1999 | error = olterrors.NewErrAdapter("core-proxy-child-device-detected-failed", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2000 | "pon-intf-id": ponintfid, |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 2001 | "serial-number": sn}, error) |
| 2002 | return error |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 2003 | } |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2004 | if error = dh.eventMgr.OnuDiscoveryIndication(ctx, onuDiscInd, dh.device.Id, onuDevice.Id, onuID, sn, time.Now().Unix()); error != nil { |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 2005 | logger.Error(ctx, "discovery-indication-failed", log.Fields{"err": error}) |
| 2006 | error = olterrors.NewErrAdapter("discovery-indication-failed", log.Fields{ |
| 2007 | "onu-id": onuID, |
| 2008 | "device-id": dh.device.Id, |
| 2009 | "serial-number": sn}, error) |
| 2010 | return error |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2011 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2012 | logger.Infow(ctx, "onu-child-device-added", |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2013 | log.Fields{"onuDevice": onuDevice, |
| 2014 | "sn": sn, |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2015 | "onu-id": onuID, |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2016 | "device-id": dh.device.Id}) |
| Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 2017 | } |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 2018 | |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2019 | // Setup the gRPC connection to the adapter responsible for that onuDevice, if not setup yet |
| 2020 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 2021 | error = dh.setupChildInterAdapterClient(subCtx, onuDevice.AdapterEndpoint) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2022 | cancel() |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 2023 | if error != nil { |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 2024 | error = olterrors.NewErrCommunication("no-connection-to-child-adapter", log.Fields{"device-id": onuDevice.Id}, error) |
| 2025 | return error |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2026 | } |
| 2027 | |
| Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 2028 | // we can now use the existing ONU Id |
| 2029 | onuID = onuDevice.ProxyAddress.OnuId |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2030 | // Insert the ONU into cache to use in OnuIndication. |
| Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2031 | //TODO: Do we need to remove this from the cache on ONU change, or wait for overwritten on next discovery. |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2032 | logger.Debugw(ctx, "onu-discovery-indication-key-create", |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2033 | log.Fields{"onu-id": onuID, |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2034 | "intfId": onuDiscInd.GetIntfId(), |
| 2035 | "sn": sn}) |
| Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2036 | onuKey := dh.formOnuKey(onuDiscInd.GetIntfId(), onuID) |
| Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 2037 | |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2038 | onuDev := NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuID, onuDiscInd.GetIntfId(), onuDevice.ProxyAddress.DeviceId, false, onuDevice.AdapterEndpoint) |
| Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 2039 | dh.onus.Store(onuKey, onuDev) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2040 | logger.Debugw(ctx, "new-onu-device-discovered", |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2041 | log.Fields{"onu": onuDev, |
| 2042 | "sn": sn}) |
| Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 2043 | |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 2044 | if error = dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2045 | DeviceId: onuDevice.Id, |
| 2046 | ParentDeviceId: dh.device.Id, |
| 2047 | OperStatus: common.OperStatus_DISCOVERED, |
| 2048 | ConnStatus: common.ConnectStatus_REACHABLE, |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 2049 | }); error != nil { |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 2050 | error = olterrors.NewErrAdapter("failed-to-update-device-state", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2051 | "device-id": onuDevice.Id, |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 2052 | "serial-number": sn}, error) |
| 2053 | return error |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2054 | } |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2055 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2056 | logger.Infow(ctx, "onu-discovered-reachable", log.Fields{"device-id": onuDevice.Id, "sn": sn}) |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 2057 | if error = dh.activateONU(ctx, onuDiscInd.IntfId, int64(onuID), onuDiscInd.SerialNumber, sn); error != nil { |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 2058 | error = olterrors.NewErrAdapter("onu-activation-failed", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2059 | "device-id": onuDevice.Id, |
| nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 2060 | "serial-number": sn}, error) |
| 2061 | return error |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2062 | } |
| 2063 | return nil |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2066 | func (dh *DeviceHandler) onuIndication(ctx context.Context, onuInd *oop.OnuIndication) error { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2067 | ponPort := plt.IntfIDToPortNo(onuInd.GetIntfId(), voltha.Port_PON_OLT) |
| Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2068 | var onuDevice *voltha.Device |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2069 | var err error |
| Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2070 | foundInCache := false |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2071 | logger.Debugw(ctx, "onu-indication-key-create", |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2072 | log.Fields{"onuId": onuInd.OnuId, |
| 2073 | "intfId": onuInd.GetIntfId(), |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2074 | "device-id": dh.device.Id}) |
| Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2075 | onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.OnuId) |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2076 | serialNumber := dh.stringifySerialNumber(onuInd.SerialNumber) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2077 | errFields := log.Fields{"device-id": dh.device.Id} |
| 2078 | |
| Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 2079 | if onuInCache, ok := dh.onus.Load(onuKey); ok { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2080 | // If ONU id is discovered before then use GetDevice to get onuDevice because it is cheaper. |
| Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2081 | foundInCache = true |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2082 | errFields["onu-id"] = onuInCache.(*OnuDevice).deviceID |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2083 | onuDevice, err = dh.getDeviceFromCore(ctx, onuInCache.(*OnuDevice).deviceID) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2084 | } else { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2085 | // If ONU not found in adapter cache then we have to use GetChildDevice to get onuDevice |
| Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2086 | if serialNumber != "" { |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2087 | errFields["serial-number"] = serialNumber |
| Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2088 | } else { |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2089 | errFields["onu-id"] = onuInd.OnuId |
| 2090 | errFields["parent-port-no"] = ponPort |
| Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2091 | } |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2092 | onuDevice, err = dh.getChildDeviceFromCore(ctx, &ca.ChildDeviceFilter{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2093 | ParentId: dh.device.Id, |
| 2094 | SerialNumber: serialNumber, |
| 2095 | OnuId: onuInd.OnuId, |
| 2096 | ParentPortNo: ponPort, |
| 2097 | }) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2098 | } |
| Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2099 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2100 | if err != nil || onuDevice == nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2101 | return olterrors.NewErrNotFound("onu-device", errFields, err) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2104 | if onuDevice.ParentPortNo != ponPort { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2105 | logger.Warnw(ctx, "onu-is-on-a-different-intf-id-now", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2106 | "previousIntfId": onuDevice.ParentPortNo, |
| 2107 | "currentIntfId": ponPort}) |
| 2108 | } |
| 2109 | |
| 2110 | if onuDevice.ProxyAddress.OnuId != onuInd.OnuId { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2111 | logger.Warnw(ctx, "onu-id-mismatch-possible-if-voltha-and-olt-rebooted", log.Fields{ |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2112 | "expected-onu-id": onuDevice.ProxyAddress.OnuId, |
| 2113 | "received-onu-id": onuInd.OnuId, |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2114 | "device-id": dh.device.Id}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2115 | } |
| 2116 | if !foundInCache { |
| 2117 | onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.GetOnuId()) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2118 | dh.onus.Store(onuKey, NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuInd.GetOnuId(), onuInd.GetIntfId(), onuDevice.ProxyAddress.DeviceId, false, onuDevice.AdapterEndpoint)) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2119 | } |
| kesavand | 7cf3a05 | 2020-08-28 12:49:18 +0530 | [diff] [blame] | 2120 | if onuInd.OperState == "down" && onuInd.FailReason != oop.OnuIndication_ONU_ACTIVATION_FAIL_REASON_NONE { |
| Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 2121 | if err := dh.eventMgr.onuActivationIndication(ctx, onuActivationFailEvent, onuInd, dh.device.Id, time.Now().Unix()); err != nil { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2122 | logger.Warnw(ctx, "onu-activation-indication-reporting-failed", log.Fields{"err": err}) |
| kesavand | 7cf3a05 | 2020-08-28 12:49:18 +0530 | [diff] [blame] | 2123 | } |
| 2124 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2125 | if err := dh.updateOnuStates(ctx, onuDevice, onuInd); err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2126 | return olterrors.NewErrCommunication("state-update-failed", errFields, err) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2127 | } |
| 2128 | return nil |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2131 | func (dh *DeviceHandler) updateOnuStates(ctx context.Context, onuDevice *voltha.Device, onuInd *oop.OnuIndication) error { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2132 | logger.Debugw(ctx, "onu-indication-for-state", log.Fields{"onuIndication": onuInd, "device-id": onuDevice.Id, "operStatus": onuDevice.OperStatus, "adminStatus": onuDevice.AdminState}) |
| Girish Gowdra | 748de5c | 2020-07-01 10:27:52 -0700 | [diff] [blame] | 2133 | if onuInd.AdminState == "down" || onuInd.OperState == "down" { |
| 2134 | // The ONU has gone admin_state "down" or oper_state "down" - we expect the ONU to send discovery again |
| 2135 | // The ONU admin_state is "up" while "oper_state" is down in cases where ONU activation fails. In this case |
| 2136 | // the ONU sends Discovery again. |
| Girish Gowdra | 429f950 | 2020-05-04 13:22:16 -0700 | [diff] [blame] | 2137 | dh.discOnus.Delete(onuDevice.SerialNumber) |
| Amit Ghosh | 9bbc565 | 2020-02-17 13:37:32 +0000 | [diff] [blame] | 2138 | // Tests have shown that we sometimes get OperState as NOT down even if AdminState is down, forcing it |
| 2139 | if onuInd.OperState != "down" { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2140 | logger.Warnw(ctx, "onu-admin-state-down", log.Fields{"operState": onuInd.OperState}) |
| Amit Ghosh | 9bbc565 | 2020-02-17 13:37:32 +0000 | [diff] [blame] | 2141 | onuInd.OperState = "down" |
| 2142 | } |
| 2143 | } |
| 2144 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2145 | switch onuInd.OperState { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2146 | case "up", "down": |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2147 | logger.Debugw(ctx, "sending-interadapter-onu-indication", log.Fields{"onuIndication": onuInd, "device-id": onuDevice.Id, "operStatus": onuDevice.OperStatus, "adminStatus": onuDevice.AdminState}) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2148 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2149 | err := dh.sendOnuIndicationToChildAdapter(ctx, onuDevice.AdapterEndpoint, &ia.OnuIndicationMessage{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2150 | DeviceId: onuDevice.Id, |
| 2151 | OnuIndication: onuInd, |
| 2152 | }) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2153 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2154 | return olterrors.NewErrCommunication("inter-adapter-send-failed", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2155 | "onu-indicator": onuInd, |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2156 | "source": dh.openOLT.config.AdapterEndpoint, |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2157 | "device-type": onuDevice.Type, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2158 | "device-id": onuDevice.Id}, err) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2159 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2160 | default: |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2161 | return olterrors.NewErrInvalidValue(log.Fields{"oper-state": onuInd.OperState}, nil) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2162 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2163 | return nil |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2164 | } |
| 2165 | |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2166 | func (dh *DeviceHandler) stringifySerialNumber(serialNum *oop.SerialNumber) string { |
| 2167 | if serialNum != nil { |
| 2168 | return string(serialNum.VendorId) + dh.stringifyVendorSpecific(serialNum.VendorSpecific) |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2169 | } |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2170 | return "" |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2171 | } |
| Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 2172 | func (dh *DeviceHandler) deStringifySerialNumber(serialNum string) (*oop.SerialNumber, error) { |
| 2173 | decodedStr, err := hex.DecodeString(serialNum[4:]) |
| 2174 | if err != nil { |
| 2175 | return nil, err |
| 2176 | } |
| 2177 | return &oop.SerialNumber{ |
| 2178 | VendorId: []byte(serialNum[:4]), |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2179 | VendorSpecific: decodedStr, |
| Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 2180 | }, nil |
| 2181 | } |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2182 | |
| 2183 | func (dh *DeviceHandler) stringifyVendorSpecific(vendorSpecific []byte) string { |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2184 | if len(vendorSpecific) > 3 { |
| 2185 | tmp := fmt.Sprintf("%x", (uint32(vendorSpecific[0])>>4)&0x0f) + |
| 2186 | fmt.Sprintf("%x", uint32(vendorSpecific[0]&0x0f)) + |
| 2187 | fmt.Sprintf("%x", (uint32(vendorSpecific[1])>>4)&0x0f) + |
| 2188 | fmt.Sprintf("%x", (uint32(vendorSpecific[1]))&0x0f) + |
| 2189 | fmt.Sprintf("%x", (uint32(vendorSpecific[2])>>4)&0x0f) + |
| 2190 | fmt.Sprintf("%x", (uint32(vendorSpecific[2]))&0x0f) + |
| 2191 | fmt.Sprintf("%x", (uint32(vendorSpecific[3])>>4)&0x0f) + |
| 2192 | fmt.Sprintf("%x", (uint32(vendorSpecific[3]))&0x0f) |
| 2193 | return tmp |
| 2194 | } |
| 2195 | return "" |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2198 | // UpdateFlowsBulk upates the bulk flow |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2199 | func (dh *DeviceHandler) UpdateFlowsBulk() error { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2200 | return olterrors.ErrNotImplemented |
| cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2201 | } |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2202 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2203 | // GetChildDevice returns the child device for given parent port and onu id |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2204 | func (dh *DeviceHandler) GetChildDevice(ctx context.Context, parentPort, onuID uint32) (*voltha.Device, error) { |
| 2205 | logger.Debugw(ctx, "getchilddevice", |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2206 | log.Fields{"pon-port": parentPort, |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2207 | "onu-id": onuID, |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2208 | "device-id": dh.device.Id}) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2209 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2210 | onuDevice, err := dh.getChildDeviceFromCore(ctx, &ca.ChildDeviceFilter{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2211 | ParentId: dh.device.Id, |
| 2212 | OnuId: onuID, |
| 2213 | ParentPortNo: parentPort, |
| 2214 | }) |
| 2215 | |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 2216 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2217 | return nil, olterrors.NewErrNotFound("onu-device", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2218 | "intf-id": parentPort, |
| 2219 | "onu-id": onuID}, err) |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 2220 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2221 | logger.Debugw(ctx, "successfully-received-child-device-from-core", log.Fields{"child-device-id": onuDevice.Id, "child-device-sn": onuDevice.SerialNumber}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2222 | return onuDevice, nil |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2223 | } |
| 2224 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2225 | // SendPacketInToCore sends packet-in to core |
| 2226 | // For this, it calls SendPacketIn of the core-proxy which uses a device specific topic to send the request. |
| 2227 | // The adapter handling the device creates a device specific topic |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2228 | func (dh *DeviceHandler) SendPacketInToCore(ctx context.Context, logicalPort uint32, packetPayload []byte) error { |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2229 | if logger.V(log.DebugLevel) { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2230 | logger.Debugw(ctx, "send-packet-in-to-core", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2231 | "port": logicalPort, |
| 2232 | "packet": hex.EncodeToString(packetPayload), |
| 2233 | "device-id": dh.device.Id, |
| 2234 | }) |
| 2235 | } |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2236 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2237 | if err := dh.sendPacketToCore(ctx, &ca.PacketIn{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2238 | DeviceId: dh.device.Id, |
| 2239 | Port: logicalPort, |
| 2240 | Packet: packetPayload, |
| 2241 | }); err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2242 | return olterrors.NewErrCommunication("packet-send-failed", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2243 | "source": "adapter", |
| 2244 | "destination": "core", |
| 2245 | "device-id": dh.device.Id, |
| 2246 | "logical-port": logicalPort, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2247 | "packet": hex.EncodeToString(packetPayload)}, err) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2248 | } |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2249 | if logger.V(log.DebugLevel) { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2250 | logger.Debugw(ctx, "sent-packet-in-to-core-successfully", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2251 | "packet": hex.EncodeToString(packetPayload), |
| 2252 | "device-id": dh.device.Id, |
| 2253 | }) |
| 2254 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2255 | return nil |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2256 | } |
| 2257 | |
| Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 2258 | // UpdatePmConfig updates the pm metrics. |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2259 | func (dh *DeviceHandler) UpdatePmConfig(ctx context.Context, pmConfigs *voltha.PmConfigs) { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2260 | logger.Infow(ctx, "update-pm-configs", log.Fields{"device-id": dh.device.Id, "pm-configs": pmConfigs}) |
| Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 2261 | |
| 2262 | if pmConfigs.DefaultFreq != dh.metrics.ToPmConfigs().DefaultFreq { |
| 2263 | dh.metrics.UpdateFrequency(pmConfigs.DefaultFreq) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2264 | logger.Debugf(ctx, "frequency-updated") |
| Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 2265 | } |
| 2266 | |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2267 | if !pmConfigs.Grouped { |
| Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 2268 | metrics := dh.metrics.GetSubscriberMetrics() |
| 2269 | for _, m := range pmConfigs.Metrics { |
| 2270 | metrics[m.Name].Enabled = m.Enabled |
| Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 2271 | } |
| 2272 | } |
| 2273 | } |
| 2274 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2275 | func (dh *DeviceHandler) handleFlows(ctx context.Context, device *voltha.Device, flows *of.FlowChanges, flowMetadata *of.FlowMetadata) []error { |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2276 | var err error |
| Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2277 | var errorsList []error |
| 2278 | |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2279 | if dh.getDeviceDeletionInProgressFlag() { |
| 2280 | // The device itself is going to be reset as part of deletion. So nothing to be done. |
| 2281 | logger.Infow(ctx, "device-deletion-in-progress--not-handling-flows-or-groups", log.Fields{"device-id": device.Id}) |
| 2282 | return nil |
| 2283 | } |
| 2284 | |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 2285 | if flows != nil { |
| Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2286 | for _, flow := range flows.ToRemove.Items { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2287 | intfID := dh.getIntfIDFromFlow(flow) |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2288 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2289 | logger.Debugw(ctx, "removing-flow", |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2290 | log.Fields{"device-id": device.Id, |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2291 | "intfId": intfID, |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2292 | "flowToRemove": flow}) |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2293 | if flow_utils.HasGroup(flow) { |
| 2294 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, flow, nil, McastFlowOrGroupRemove) |
| 2295 | } else { |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2296 | if dh.flowMgr == nil || dh.flowMgr[intfID] == nil { |
| 2297 | err = fmt.Errorf("flow-manager-uninitialized-%v", device.Id) |
| 2298 | } else { |
| 2299 | err = dh.flowMgr[intfID].RouteFlowToOnuChannel(ctx, flow, false, nil) |
| 2300 | } |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2301 | } |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2302 | if err != nil { |
| Elia Battiston | 2aaf434 | 2022-02-07 15:16:38 +0100 | [diff] [blame] | 2303 | if werr, ok := err.(olterrors.WrappedError); ok && status.Code(werr.Unwrap()) == codes.NotFound { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2304 | // The flow we want to remove is not there, there is no need to throw an error |
| Elia Battiston | 2aaf434 | 2022-02-07 15:16:38 +0100 | [diff] [blame] | 2305 | logger.Warnw(ctx, "flow-to-remove-not-found", |
| 2306 | log.Fields{ |
| 2307 | "ponIf": intfID, |
| 2308 | "flowToRemove": flow, |
| 2309 | "error": err, |
| 2310 | }) |
| 2311 | } else { |
| 2312 | errorsList = append(errorsList, err) |
| 2313 | } |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2314 | } |
| Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2315 | } |
| Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2316 | |
| 2317 | for _, flow := range flows.ToAdd.Items { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2318 | intfID := dh.getIntfIDFromFlow(flow) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2319 | logger.Debugw(ctx, "adding-flow", |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2320 | log.Fields{"device-id": device.Id, |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2321 | "ponIf": intfID, |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2322 | "flowToAdd": flow}) |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2323 | if flow_utils.HasGroup(flow) { |
| 2324 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, flow, nil, McastFlowOrGroupAdd) |
| 2325 | } else { |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2326 | if dh.flowMgr == nil || dh.flowMgr[intfID] == nil { |
| Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 2327 | // The flow manager module could be uninitialized if the flow arrives too soon before the device has reconciled fully |
| 2328 | logger.Errorw(ctx, "flow-manager-uninitialized", log.Fields{"device-id": device.Id}) |
| 2329 | err = fmt.Errorf("flow-manager-uninitialized-%v", device.Id) |
| 2330 | } else { |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2331 | err = dh.flowMgr[intfID].RouteFlowToOnuChannel(ctx, flow, true, flowMetadata) |
| Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 2332 | } |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2333 | } |
| Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2334 | if err != nil { |
| 2335 | errorsList = append(errorsList, err) |
| 2336 | } |
| Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2337 | } |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 2338 | } |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2339 | |
| Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 2340 | return errorsList |
| 2341 | } |
| 2342 | |
| 2343 | func (dh *DeviceHandler) handleGroups(ctx context.Context, groups *of.FlowGroupChanges) []error { |
| 2344 | var err error |
| 2345 | var errorsList []error |
| 2346 | |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2347 | if dh.getDeviceDeletionInProgressFlag() { |
| 2348 | // The device itself is going to be reset as part of deletion. So nothing to be done. |
| 2349 | logger.Infow(ctx, "device-deletion-in-progress--not-handling-flows-or-groups", log.Fields{"device-id": dh.device.Id}) |
| 2350 | return nil |
| 2351 | } |
| 2352 | |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2353 | // Whether we need to synchronize multicast group adds and modifies like flow add and delete needs to be investigated |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2354 | if groups != nil { |
| 2355 | for _, group := range groups.ToAdd.Items { |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2356 | // err = dh.groupMgr.AddGroup(ctx, group) |
| 2357 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, nil, group, McastFlowOrGroupAdd) |
| Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2358 | if err != nil { |
| 2359 | errorsList = append(errorsList, err) |
| 2360 | } |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2361 | } |
| 2362 | for _, group := range groups.ToUpdate.Items { |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2363 | // err = dh.groupMgr.ModifyGroup(ctx, group) |
| 2364 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, nil, group, McastFlowOrGroupModify) |
| Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2365 | if err != nil { |
| 2366 | errorsList = append(errorsList, err) |
| 2367 | } |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2368 | } |
| Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 2369 | for _, group := range groups.ToRemove.Items { |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2370 | // err = dh.groupMgr.DeleteGroup(ctx, group) |
| 2371 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, nil, group, McastFlowOrGroupRemove) |
| Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 2372 | if err != nil { |
| 2373 | errorsList = append(errorsList, err) |
| 2374 | } |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2375 | } |
| 2376 | } |
| Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 2377 | |
| 2378 | return errorsList |
| 2379 | } |
| 2380 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2381 | // UpdateFlowsIncrementally updates the device flow |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2382 | func (dh *DeviceHandler) UpdateFlowsIncrementally(ctx context.Context, device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges, flowMetadata *of.FlowMetadata) error { |
| Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 2383 | var errorsList []error |
| Girish Gowdra | 950326e | 2021-11-05 12:43:24 -0700 | [diff] [blame] | 2384 | |
| 2385 | if dh.getDeviceDeletionInProgressFlag() { |
| 2386 | // The device itself is going to be reset as part of deletion. So nothing to be done. |
| 2387 | logger.Infow(ctx, "device-deletion-in-progress--not-handling-flows-or-groups", log.Fields{"device-id": device.Id}) |
| 2388 | return nil |
| 2389 | } |
| nikesh.krishnan | 0897d47 | 2023-09-05 18:35:08 +0530 | [diff] [blame] | 2390 | if dh.transitionMap.currentDeviceState != deviceStateUp { |
| 2391 | logger.Error(ctx, "device-is-not-up--not-handling-flows-or-groups", log.Fields{"device-id": device.Id, "current-device-state": dh.transitionMap.currentDeviceState}) |
| 2392 | return fmt.Errorf("device-is-not-up--not-handling-flows-or-groups") |
| 2393 | } |
| Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 2394 | logger.Debugw(ctx, "received-incremental-flowupdate-in-device-handler", log.Fields{"device-id": device.Id, "flows": flows, "groups": groups, "flowMetadata": flowMetadata}) |
| 2395 | errorsList = append(errorsList, dh.handleFlows(ctx, device, flows, flowMetadata)...) |
| 2396 | errorsList = append(errorsList, dh.handleGroups(ctx, groups)...) |
| Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2397 | if len(errorsList) > 0 { |
| 2398 | return fmt.Errorf("errors-installing-flows-groups, errors:%v", errorsList) |
| 2399 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2400 | logger.Debugw(ctx, "updated-flows-incrementally-successfully", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 2401 | return nil |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2402 | } |
| Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2403 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2404 | // DisableDevice disables the given device |
| 2405 | // It marks the following for the given device: |
| 2406 | // Device-Handler Admin-State : down |
| 2407 | // Device Port-State: UNKNOWN |
| 2408 | // Device Oper-State: UNKNOWN |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2409 | func (dh *DeviceHandler) DisableDevice(ctx context.Context, device *voltha.Device) error { |
| Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 2410 | /* On device disable ,admin state update has to be done prior sending request to agent since |
| 2411 | the indication thread may processes invalid indications of ONU and OLT*/ |
| Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 2412 | if dh.Client != nil { |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 2413 | if _, err := dh.Client.DisableOlt(log.WithSpanFromContext(context.Background(), ctx), new(oop.Empty)); err != nil { |
| Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 2414 | if e, ok := status.FromError(err); ok && e.Code() == codes.Internal { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2415 | return olterrors.NewErrAdapter("olt-disable-failed", log.Fields{"device-id": device.Id}, err) |
| Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 2416 | } |
| Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2417 | } |
| Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 2418 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2419 | logger.Debugw(ctx, "olt-disabled", log.Fields{"device-id": device.Id}) |
| Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 2420 | /* Discovered ONUs entries need to be cleared , since on device disable the child devices goes to |
| Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 2421 | UNREACHABLE state which needs to be configured again*/ |
| Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 2422 | |
| 2423 | dh.discOnus = sync.Map{} |
| 2424 | dh.onus = sync.Map{} |
| 2425 | |
| Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 2426 | dh.lockDevice.RLock() |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2427 | // stopping the stats collector |
| Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 2428 | if dh.isCollectorActive { |
| 2429 | dh.stopCollector <- true |
| 2430 | } |
| 2431 | dh.lockDevice.RUnlock() |
| Thomas Lee S | 85f3731 | 2020-04-03 17:06:12 +0530 | [diff] [blame] | 2432 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2433 | go dh.notifyChildDevices(ctx, "unreachable") |
| Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2434 | cloned := proto.Clone(device).(*voltha.Device) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2435 | // Update device Admin state |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2436 | dh.device = cloned |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2437 | |
| kdarapu | 1afeceb | 2020-02-12 01:38:09 -0500 | [diff] [blame] | 2438 | // Update the all pon ports state on that device to disable and NNI remains active as NNI remains active in openolt agent. |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2439 | if err := dh.updatePortsStateInCore(ctx, &ca.PortStateFilter{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2440 | DeviceId: cloned.Id, |
| 2441 | PortTypeFilter: ^uint32(1 << voltha.Port_PON_OLT), |
| 2442 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2443 | }); err != nil { |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 2444 | return olterrors.NewErrAdapter("ports-state-update-failed", log.Fields{"device-id": device.Id}, err) |
| Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2445 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2446 | logger.Debugw(ctx, "disable-device-end", log.Fields{"device-id": device.Id}) |
| Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2447 | return nil |
| 2448 | } |
| 2449 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2450 | func (dh *DeviceHandler) notifyChildDevices(ctx context.Context, state string) { |
| Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2451 | // Update onu state as unreachable in onu adapter |
| 2452 | onuInd := oop.OnuIndication{} |
| Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2453 | onuInd.OperState = state |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2454 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2455 | // get the child device for the parent device |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2456 | onuDevices, err := dh.getChildDevicesFromCore(ctx, dh.device.Id) |
| Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2457 | if err != nil { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2458 | logger.Errorw(ctx, "failed-to-get-child-devices-information", log.Fields{"device-id": dh.device.Id, "err": err}) |
| Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2459 | } |
| 2460 | if onuDevices != nil { |
| 2461 | for _, onuDevice := range onuDevices.Items { |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2462 | err := dh.sendOnuIndicationToChildAdapter(ctx, onuDevice.AdapterEndpoint, &ia.OnuIndicationMessage{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2463 | DeviceId: onuDevice.Id, |
| 2464 | OnuIndication: &onuInd, |
| 2465 | }) |
| Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2466 | if err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2467 | logger.Errorw(ctx, "failed-to-send-inter-adapter-message", log.Fields{"OnuInd": onuInd, |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2468 | "From Adapter": dh.openOLT.config.AdapterEndpoint, "DeviceType": onuDevice.Type, "device-id": onuDevice.Id}) |
| Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2469 | } |
| Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2470 | } |
| 2471 | } |
| Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2472 | } |
| 2473 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2474 | // ReenableDevice re-enables the olt device after disable |
| 2475 | // It marks the following for the given device: |
| 2476 | // Device-Handler Admin-State : up |
| 2477 | // Device Port-State: ACTIVE |
| 2478 | // Device Oper-State: ACTIVE |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2479 | func (dh *DeviceHandler) ReenableDevice(ctx context.Context, device *voltha.Device) error { |
| nikesh.krishnan | e363ace | 2023-02-28 03:12:38 +0530 | [diff] [blame] | 2480 | if dh.Client != nil { |
| 2481 | if _, err := dh.Client.ReenableOlt(log.WithSpanFromContext(context.Background(), ctx), new(oop.Empty)); err != nil { |
| 2482 | if e, ok := status.FromError(err); ok && e.Code() == codes.Internal { |
| 2483 | return olterrors.NewErrAdapter("olt-reenable-failed", log.Fields{"device-id": dh.device.Id}, err) |
| 2484 | } |
| Abhilash Laxmeshwar | 5b302e1 | 2020-01-09 15:15:14 +0530 | [diff] [blame] | 2485 | } |
| nikesh.krishnan | e363ace | 2023-02-28 03:12:38 +0530 | [diff] [blame] | 2486 | } else { |
| 2487 | return olterrors.NewErrAdapter("olt-reenable-failed", log.Fields{"device-id": dh.device.Id}, errors.New("nil device client")) |
| Abhilash Laxmeshwar | 5b302e1 | 2020-01-09 15:15:14 +0530 | [diff] [blame] | 2488 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2489 | logger.Debug(ctx, "olt-reenabled") |
| Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2490 | |
| Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2491 | // Update the all ports state on that device to enable |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2492 | ports, err := dh.listDevicePortsFromCore(ctx, device.Id) |
| Mahir Gunyel | e5e807a | 2021-10-22 11:33:25 -0700 | [diff] [blame] | 2493 | var retError error |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 2494 | if err != nil { |
| Mahir Gunyel | e5e807a | 2021-10-22 11:33:25 -0700 | [diff] [blame] | 2495 | retError = olterrors.NewErrAdapter("list-ports-failed", log.Fields{"device-id": device.Id}, err) |
| 2496 | } else { |
| 2497 | if err := dh.disableAdminDownPorts(ctx, ports.Items); err != nil { |
| 2498 | retError = olterrors.NewErrAdapter("port-status-update-failed-after-olt-reenable", log.Fields{"device": device}, err) |
| 2499 | } |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 2500 | } |
| Mahir Gunyel | e5e807a | 2021-10-22 11:33:25 -0700 | [diff] [blame] | 2501 | if retError == nil { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2502 | // Update the device oper status as ACTIVE |
| Mahir Gunyel | e5e807a | 2021-10-22 11:33:25 -0700 | [diff] [blame] | 2503 | device.OperStatus = voltha.OperStatus_ACTIVE |
| 2504 | } else { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2505 | // Update the device oper status as FAILED |
| Mahir Gunyel | e5e807a | 2021-10-22 11:33:25 -0700 | [diff] [blame] | 2506 | device.OperStatus = voltha.OperStatus_FAILED |
| Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2507 | } |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 2508 | dh.device = device |
| Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2509 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2510 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2511 | DeviceId: device.Id, |
| 2512 | OperStatus: device.OperStatus, |
| 2513 | ConnStatus: device.ConnectStatus, |
| 2514 | }); err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2515 | return olterrors.NewErrAdapter("state-update-failed", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2516 | "device-id": device.Id, |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 2517 | "connect-status": device.ConnectStatus, |
| 2518 | "oper-status": device.OperStatus}, err) |
| Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2519 | } |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2520 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2521 | logger.Debugw(ctx, "reenabledevice-end", log.Fields{"device-id": device.Id}) |
| Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2522 | |
| Mahir Gunyel | e5e807a | 2021-10-22 11:33:25 -0700 | [diff] [blame] | 2523 | return retError |
| Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2524 | } |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2525 | |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2526 | func (dh *DeviceHandler) clearUNIData(ctx context.Context, onu *rsrcMgr.OnuGemInfo) error { |
| Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2527 | var uniID uint32 |
| 2528 | var err error |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2529 | var errs []error |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2530 | for _, port := range onu.UniPorts { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2531 | uniID = plt.UniIDFromPortNum(port) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2532 | logger.Debugw(ctx, "clearing-resource-data-for-uni-port", log.Fields{"port": port, "uni-id": uniID}) |
| A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2533 | /* Delete tech-profile instance from the KV store */ |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2534 | if dh.flowMgr == nil || dh.flowMgr[onu.IntfID] == nil { |
| 2535 | logger.Debugw(ctx, "failed-to-remove-tech-profile-instance-for-onu-no-flowmng", log.Fields{"onu-id": onu.OnuID}) |
| 2536 | } else { |
| 2537 | if err = dh.flowMgr[onu.IntfID].DeleteTechProfileInstances(ctx, onu.IntfID, onu.OnuID, uniID); err != nil { |
| 2538 | logger.Debugw(ctx, "failed-to-remove-tech-profile-instance-for-onu", log.Fields{"onu-id": onu.OnuID}) |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2539 | errs = append(errs, err) |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2540 | } |
| Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2541 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2542 | logger.Debugw(ctx, "deleted-tech-profile-instance-for-onu", log.Fields{"onu-id": onu.OnuID}) |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2543 | tpIDList := dh.resourceMgr[onu.IntfID].GetTechProfileIDForOnu(ctx, onu.OnuID, uniID) |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2544 | for _, tpID := range tpIDList { |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2545 | if err = dh.resourceMgr[onu.IntfID].RemoveMeterInfoForOnu(ctx, "upstream", onu.OnuID, uniID, tpID); err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2546 | logger.Debugw(ctx, "failed-to-remove-meter-id-for-onu-upstream", log.Fields{"onu-id": onu.OnuID}) |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2547 | errs = append(errs, err) |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2548 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2549 | logger.Debugw(ctx, "removed-meter-id-for-onu-upstream", log.Fields{"onu-id": onu.OnuID}) |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2550 | if err = dh.resourceMgr[onu.IntfID].RemoveMeterInfoForOnu(ctx, "downstream", onu.OnuID, uniID, tpID); err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2551 | logger.Debugw(ctx, "failed-to-remove-meter-id-for-onu-downstream", log.Fields{"onu-id": onu.OnuID}) |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2552 | errs = append(errs, err) |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2553 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2554 | logger.Debugw(ctx, "removed-meter-id-for-onu-downstream", log.Fields{"onu-id": onu.OnuID}) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2555 | } |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2556 | dh.resourceMgr[onu.IntfID].FreePONResourcesForONU(ctx, onu.OnuID, uniID) |
| 2557 | if err = dh.resourceMgr[onu.IntfID].RemoveTechProfileIDsForOnu(ctx, onu.OnuID, uniID); err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2558 | logger.Debugw(ctx, "failed-to-remove-tech-profile-id-for-onu", log.Fields{"onu-id": onu.OnuID}) |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2559 | errs = append(errs, err) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2560 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2561 | logger.Debugw(ctx, "removed-tech-profile-id-for-onu", log.Fields{"onu-id": onu.OnuID}) |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2562 | if err = dh.resourceMgr[onu.IntfID].DeletePacketInGemPortForOnu(ctx, onu.OnuID, port); err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2563 | logger.Debugw(ctx, "failed-to-remove-gemport-pkt-in", log.Fields{"intfid": onu.IntfID, "onuid": onu.OnuID, "uniId": uniID}) |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2564 | errs = append(errs, err) |
| A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2565 | } |
| Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2566 | } |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2567 | if len(errs) > 0 { |
| 2568 | return olterrors.NewErrAdapter(fmt.Errorf("one-or-more-error-during-clear-uni-data, errors:%v", |
| 2569 | errs).Error(), log.Fields{"device-id": dh.device.Id}, nil) |
| 2570 | } |
| Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2571 | return nil |
| 2572 | } |
| 2573 | |
| Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2574 | // DeleteDevice deletes the device instance from openolt handler array. Also clears allocated resource manager resources. Also reboots the OLT hardware! |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2575 | func (dh *DeviceHandler) DeleteDevice(ctx context.Context, device *voltha.Device) error { |
| Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 2576 | logger.Debugw(ctx, "function-entry-delete-device", log.Fields{"device-id": dh.device.Id}) |
| Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2577 | /* Clear the KV store data associated with the all the UNI ports |
| 2578 | This clears up flow data and also resource map data for various |
| 2579 | other pon resources like alloc_id and gemport_id |
| 2580 | */ |
| Girish Gowdra | 950326e | 2021-11-05 12:43:24 -0700 | [diff] [blame] | 2581 | |
| 2582 | dh.setDeviceDeletionInProgressFlag(true) |
| Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 2583 | dh.StopAllFlowRoutines(ctx) |
| Girish Gowdra | 950326e | 2021-11-05 12:43:24 -0700 | [diff] [blame] | 2584 | |
| Himani Chawla | 49a5d56 | 2020-11-25 11:53:44 +0530 | [diff] [blame] | 2585 | dh.lockDevice.RLock() |
| Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 2586 | // Stop the Stats collector |
| 2587 | if dh.isCollectorActive { |
| 2588 | dh.stopCollector <- true |
| 2589 | } |
| 2590 | // stop the heartbeat check routine |
| 2591 | if dh.isHeartbeatCheckActive { |
| 2592 | dh.stopHeartbeatCheck <- true |
| 2593 | } |
| Himani Chawla | 49a5d56 | 2020-11-25 11:53:44 +0530 | [diff] [blame] | 2594 | // Stop the read indication only if it the routine is active |
| 2595 | if dh.isReadIndicationRoutineActive { |
| 2596 | dh.stopIndications <- true |
| 2597 | } |
| 2598 | dh.lockDevice.RUnlock() |
| Akash Soni | 5c76e27 | 2024-01-15 04:09:24 +0530 | [diff] [blame] | 2599 | |
| 2600 | err := dh.cleanupDeviceResources(ctx) |
| 2601 | if err != nil { |
| 2602 | logger.Errorw(ctx, "could-not-remove-device-from-KV-store", log.Fields{"device-id": dh.device.Id, "err": err}) |
| 2603 | } else { |
| 2604 | logger.Debugw(ctx, "successfully-removed-device-from-Resource-manager-KV-store", log.Fields{"device-id": dh.device.Id}) |
| 2605 | } |
| 2606 | |
| Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 2607 | dh.removeOnuIndicationChannels(ctx) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2608 | // Reset the state |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2609 | if dh.Client != nil { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2610 | if _, err = dh.Client.Reboot(ctx, new(oop.Empty)); err != nil { |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2611 | go func() { |
| 2612 | failureReason := fmt.Sprintf("Failed to reboot during device delete request with error: %s", err.Error()) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2613 | if err1 := dh.eventMgr.oltRebootFailedEvent(ctx, dh.device.Id, failureReason, time.Now().Unix()); err1 != nil { |
| 2614 | logger.Errorw(ctx, "on-olt-reboot-failed", log.Fields{"device-id": dh.device.Id, "err": err1}) |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2615 | } |
| 2616 | }() |
| 2617 | logger.Errorw(ctx, "olt-reboot-failed", log.Fields{"device-id": dh.device.Id, "err": err}) |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2618 | } |
| 2619 | } |
| Girish Gowdra | b1caa44 | 2020-10-19 12:24:39 -0700 | [diff] [blame] | 2620 | // There is no need to update the core about operation status and connection status of the OLT. |
| 2621 | // The OLT is getting deleted anyway and the core might have already cleared the OLT device from its DB. |
| 2622 | // So any attempt to update the operation status and connection status of the OLT will result in core throwing an error back, |
| 2623 | // because the device does not exist in DB. |
| Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 2624 | |
| khenaidoo | 7eb2d67 | 2021-10-22 19:08:50 -0400 | [diff] [blame] | 2625 | // Stop the adapter grpc clients for that parent device |
| 2626 | dh.deleteAdapterClients(ctx) |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2627 | return err |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2628 | } |
| Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 2629 | |
| 2630 | // StopAllFlowRoutines stops all flow routines |
| 2631 | func (dh *DeviceHandler) StopAllFlowRoutines(ctx context.Context) { |
| 2632 | var wg sync.WaitGroup |
| 2633 | wg.Add(1) // for the mcast routine below to finish |
| 2634 | go dh.StopAllMcastHandlerRoutines(ctx, &wg) |
| 2635 | for _, flMgr := range dh.flowMgr { |
| 2636 | if flMgr != nil { |
| 2637 | wg.Add(1) // for the flow handler routine below to finish |
| 2638 | go flMgr.StopAllFlowHandlerRoutines(ctx, &wg) |
| 2639 | } |
| 2640 | } |
| 2641 | if !dh.waitForTimeoutOrCompletion(&wg, time.Second*30) { |
| 2642 | logger.Warnw(ctx, "timed out waiting for stopping flow and group handlers", log.Fields{"deviceID": dh.device.Id}) |
| 2643 | } else { |
| 2644 | logger.Infow(ctx, "all flow and group handlers shutdown gracefully", log.Fields{"deviceID": dh.device.Id}) |
| 2645 | } |
| 2646 | } |
| 2647 | |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2648 | func (dh *DeviceHandler) cleanupDeviceResources(ctx context.Context) error { |
| 2649 | var errs []error |
| Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 2650 | if dh.resourceMgr != nil { |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2651 | var ponPort uint32 |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2652 | for ponPort = 0; ponPort < dh.totalPonPorts; ponPort++ { |
| yasin sapli | 9e4c509 | 2022-02-01 13:52:33 +0000 | [diff] [blame] | 2653 | onuGemData := dh.resourceMgr[ponPort].GetOnuGemInfoList(ctx) |
| Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 2654 | for i, onu := range onuGemData { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2655 | logger.Debugw(ctx, "onu-data", log.Fields{"onu": onu}) |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2656 | if err := dh.clearUNIData(ctx, &onuGemData[i]); err != nil { |
| 2657 | errs = append(errs, err) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2658 | } |
| 2659 | } |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2660 | if err := dh.resourceMgr[ponPort].DeleteAllFlowIDsForGemForIntf(ctx); err != nil { |
| 2661 | errs = append(errs, err) |
| 2662 | } |
| 2663 | if err := dh.resourceMgr[ponPort].DeleteAllOnuGemInfoForIntf(ctx); err != nil { |
| 2664 | errs = append(errs, err) |
| 2665 | } |
| 2666 | if err := dh.resourceMgr[ponPort].DeleteMcastQueueForIntf(ctx); err != nil { |
| 2667 | errs = append(errs, err) |
| 2668 | } |
| Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 2669 | if err := dh.resourceMgr[ponPort].Delete(ctx, ponPort); err != nil { |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2670 | errs = append(errs, err) |
| Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 2671 | } |
| Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2672 | } |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2673 | } |
| 2674 | // Clean up NNI manager's data |
| 2675 | if err := dh.resourceMgr[dh.totalPonPorts].DeleteAllFlowIDsForGemForIntf(ctx); err != nil { |
| 2676 | errs = append(errs, err) |
| Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 2677 | } |
| A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2678 | |
| Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 2679 | dh.CloseKVClient(ctx) |
| 2680 | |
| Girish Gowdra | 0f3190e | 2022-02-11 14:18:28 -0800 | [diff] [blame] | 2681 | // Take one final sweep at cleaning up KV store for the OLT device |
| 2682 | // Clean everything at <base-path-prefix>/openolt/<device-id> |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2683 | if err := dh.kvStore.DeleteWithPrefix(ctx, ""); err != nil { |
| 2684 | errs = append(errs, err) |
| Girish Gowdra | 0f3190e | 2022-02-11 14:18:28 -0800 | [diff] [blame] | 2685 | } |
| 2686 | |
| Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2687 | /*Delete ONU map for the device*/ |
| Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 2688 | dh.onus.Range(func(key interface{}, value interface{}) bool { |
| 2689 | dh.onus.Delete(key) |
| 2690 | return true |
| 2691 | }) |
| 2692 | |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2693 | /*Delete discovered ONU map for the device*/ |
| 2694 | dh.discOnus.Range(func(key interface{}, value interface{}) bool { |
| 2695 | dh.discOnus.Delete(key) |
| 2696 | return true |
| 2697 | }) |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2698 | if len(errs) > 0 { |
| 2699 | return olterrors.NewErrAdapter(fmt.Errorf("one-or-more-error-during-device-delete, errors:%v", |
| 2700 | errs).Error(), log.Fields{"device-id": dh.device.Id}, nil) |
| 2701 | } |
| 2702 | return nil |
| Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2703 | } |
| 2704 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2705 | // RebootDevice reboots the given device |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2706 | func (dh *DeviceHandler) RebootDevice(ctx context.Context, device *voltha.Device) error { |
| nikesh.krishnan | e363ace | 2023-02-28 03:12:38 +0530 | [diff] [blame] | 2707 | if dh.Client != nil { |
| 2708 | if _, err := dh.Client.Reboot(log.WithSpanFromContext(context.Background(), ctx), new(oop.Empty)); err != nil { |
| 2709 | return olterrors.NewErrAdapter("olt-reboot-failed", log.Fields{"device-id": dh.device.Id}, err) |
| 2710 | } |
| 2711 | } else { |
| 2712 | return olterrors.NewErrAdapter("olt-reboot-failed", log.Fields{"device-id": dh.device.Id}, errors.New("nil device client")) |
| Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 2713 | } |
| nikesh.krishnan | e363ace | 2023-02-28 03:12:38 +0530 | [diff] [blame] | 2714 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2715 | logger.Debugw(ctx, "rebooted-device-successfully", log.Fields{"device-id": device.Id}) |
| Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 2716 | return nil |
| 2717 | } |
| 2718 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2719 | func (dh *DeviceHandler) handlePacketIndication(ctx context.Context, packetIn *oop.PacketIndication) error { |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2720 | if logger.V(log.DebugLevel) { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2721 | logger.Debugw(ctx, "received-packet-in", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2722 | "packet-indication": *packetIn, |
| 2723 | "device-id": dh.device.Id, |
| 2724 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 2725 | }) |
| 2726 | } |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2727 | if dh.flowMgr == nil || dh.flowMgr[packetIn.IntfId] == nil { |
| 2728 | return olterrors.NewErrNotFound("flow-manager", log.Fields{"intf-id": packetIn.IntfId, "packet": hex.EncodeToString(packetIn.Pkt)}, nil) |
| 2729 | } |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2730 | logicalPortNum, err := dh.flowMgr[packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, packetIn) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2731 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2732 | return olterrors.NewErrNotFound("logical-port", log.Fields{"packet": hex.EncodeToString(packetIn.Pkt)}, err) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2733 | } |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2734 | if logger.V(log.DebugLevel) { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2735 | logger.Debugw(ctx, "sending-packet-in-to-core", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2736 | "logical-port-num": logicalPortNum, |
| 2737 | "device-id": dh.device.Id, |
| 2738 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 2739 | }) |
| 2740 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2741 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2742 | if err := dh.sendPacketToCore(ctx, &ca.PacketIn{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2743 | DeviceId: dh.device.Id, |
| 2744 | Port: logicalPortNum, |
| 2745 | Packet: packetIn.Pkt, |
| 2746 | }); err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2747 | return olterrors.NewErrCommunication("send-packet-in", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2748 | "destination": "core", |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2749 | "source": dh.device.Type, |
| Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 2750 | "device-id": dh.device.Id, |
| 2751 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 2752 | }, err) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2753 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2754 | |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2755 | if logger.V(log.DebugLevel) { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2756 | logger.Debugw(ctx, "success-sending-packet-in-to-core!", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2757 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 2758 | "device-id": dh.device.Id, |
| 2759 | }) |
| 2760 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2761 | return nil |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2762 | } |
| 2763 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2764 | // PacketOutNNI sends packet-out from VOLTHA to OLT on the NNI provided |
| 2765 | func (dh *DeviceHandler) PacketOutNNI(ctx context.Context, egressPortNo uint32, packet *of.OfpPacketOut) error { |
| 2766 | nniIntfID, err := plt.IntfIDFromNniPortNum(ctx, uint32(egressPortNo)) |
| 2767 | if err != nil { |
| 2768 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 2769 | "egress-nni-port": egressPortNo, |
| 2770 | "device-id": dh.device.Id, |
| 2771 | }, err) |
| 2772 | } |
| 2773 | uplinkPkt := oop.UplinkPacket{IntfId: nniIntfID, Pkt: packet.Data} |
| 2774 | |
| 2775 | if logger.V(log.DebugLevel) { |
| 2776 | logger.Debugw(ctx, "sending-packet-to-nni", log.Fields{ |
| 2777 | "uplink-pkt": uplinkPkt, |
| 2778 | "packet": hex.EncodeToString(packet.Data), |
| 2779 | "device-id": dh.device.Id, |
| 2780 | }) |
| 2781 | } |
| 2782 | |
| 2783 | if _, err := dh.Client.UplinkPacketOut(ctx, &uplinkPkt); err != nil { |
| 2784 | return olterrors.NewErrCommunication("packet-out-to-nni", log.Fields{ |
| 2785 | "packet": hex.EncodeToString(packet.Data), |
| 2786 | "device-id": dh.device.Id, |
| 2787 | }, err) |
| 2788 | } |
| 2789 | return nil |
| 2790 | } |
| 2791 | |
| 2792 | // PacketOutUNI sends packet-out from VOLTHA to OLT on the UNI provided |
| 2793 | func (dh *DeviceHandler) PacketOutUNI(ctx context.Context, egressPortNo uint32, packet *of.OfpPacketOut) error { |
| 2794 | outerEthType := (uint16(packet.Data[12]) << 8) | uint16(packet.Data[13]) |
| 2795 | innerEthType := (uint16(packet.Data[16]) << 8) | uint16(packet.Data[17]) |
| 2796 | if outerEthType == 0x8942 || outerEthType == 0x88cc { |
| 2797 | // Do not packet-out lldp packets on uni port. |
| 2798 | // ONOS has no clue about uni/nni ports, it just packets out on all |
| 2799 | // available ports on the Logical Switch. It should not be interested |
| 2800 | // in the UNI links. |
| 2801 | logger.Debugw(ctx, "dropping-lldp-packet-out-on-uni", log.Fields{ |
| 2802 | "device-id": dh.device.Id, |
| 2803 | }) |
| 2804 | return nil |
| 2805 | } |
| 2806 | if outerEthType == 0x88a8 || outerEthType == 0x8100 { |
| 2807 | if innerEthType == 0x8100 { |
| 2808 | // q-in-q 802.1ad or 802.1q double tagged packet. |
| 2809 | // slice out the outer tag. |
| 2810 | packet.Data = append(packet.Data[:12], packet.Data[16:]...) |
| 2811 | if logger.V(log.DebugLevel) { |
| 2812 | logger.Debugw(ctx, "packet-now-single-tagged", log.Fields{ |
| 2813 | "packet-data": hex.EncodeToString(packet.Data), |
| 2814 | "device-id": dh.device.Id, |
| 2815 | }) |
| 2816 | } |
| 2817 | } |
| 2818 | } |
| 2819 | intfID := plt.IntfIDFromUniPortNum(uint32(egressPortNo)) |
| 2820 | onuID := plt.OnuIDFromPortNum(uint32(egressPortNo)) |
| 2821 | uniID := plt.UniIDFromPortNum(uint32(egressPortNo)) |
| 2822 | var gemPortID uint32 |
| 2823 | err := olterrors.NewErrNotFound("no-flow-manager-found-for-packet-out", log.Fields{"device-id": dh.device.Id}, nil).(error) |
| 2824 | if dh.flowMgr != nil && dh.flowMgr[intfID] != nil { |
| 2825 | gemPortID, err = dh.flowMgr[intfID].GetPacketOutGemPortID(ctx, intfID, onuID, uint32(egressPortNo), packet.Data) |
| 2826 | } |
| 2827 | if err != nil { |
| 2828 | // In this case the openolt agent will receive the gemPortID as 0. |
| 2829 | // The agent tries to retrieve the gemPortID in this case. |
| 2830 | // This may not always succeed at the agent and packetOut may fail. |
| 2831 | logger.Errorw(ctx, "failed-to-retrieve-gemport-id-for-packet-out", log.Fields{ |
| 2832 | "intf-id": intfID, |
| 2833 | "onu-id": onuID, |
| 2834 | "uni-id": uniID, |
| 2835 | "packet": hex.EncodeToString(packet.Data), |
| 2836 | "device-id": dh.device.Id, |
| 2837 | "error": err, |
| 2838 | }) |
| 2839 | } |
| 2840 | |
| 2841 | onuPkt := oop.OnuPacket{IntfId: intfID, OnuId: onuID, PortNo: uint32(egressPortNo), GemportId: gemPortID, Pkt: packet.Data} |
| 2842 | if logger.V(log.DebugLevel) { |
| 2843 | logger.Debugw(ctx, "sending-packet-to-onu", log.Fields{ |
| 2844 | "egress-port-no": egressPortNo, |
| 2845 | "intf-id": intfID, |
| 2846 | "onu-id": onuID, |
| 2847 | "uni-id": uniID, |
| 2848 | "gem-port-id": gemPortID, |
| 2849 | "packet": hex.EncodeToString(packet.Data), |
| 2850 | "device-id": dh.device.Id, |
| 2851 | }) |
| 2852 | } |
| 2853 | |
| 2854 | if _, err := dh.Client.OnuPacketOut(ctx, &onuPkt); err != nil { |
| 2855 | return olterrors.NewErrCommunication("packet-out-send", log.Fields{ |
| 2856 | "source": "adapter", |
| 2857 | "destination": "onu", |
| 2858 | "egress-port-number": egressPortNo, |
| 2859 | "intf-id": intfID, |
| 2860 | "oni-id": onuID, |
| 2861 | "uni-id": uniID, |
| 2862 | "gem-port-id": gemPortID, |
| 2863 | "packet": hex.EncodeToString(packet.Data), |
| 2864 | "device-id": dh.device.Id, |
| 2865 | }, err) |
| 2866 | } |
| 2867 | return nil |
| 2868 | } |
| 2869 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2870 | // PacketOut sends packet-out from VOLTHA to OLT on the egress port provided |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2871 | func (dh *DeviceHandler) PacketOut(ctx context.Context, egressPortNo uint32, packet *of.OfpPacketOut) error { |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2872 | if logger.V(log.DebugLevel) { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2873 | logger.Debugw(ctx, "incoming-packet-out", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2874 | "device-id": dh.device.Id, |
| 2875 | "egress-port-no": egressPortNo, |
| 2876 | "pkt-length": len(packet.Data), |
| 2877 | "packet": hex.EncodeToString(packet.Data), |
| 2878 | }) |
| 2879 | } |
| Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 2880 | |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2881 | egressPortType := plt.IntfIDToPortTypeName(uint32(egressPortNo)) |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2882 | var err error |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2883 | switch egressPortType { |
| 2884 | case voltha.Port_ETHERNET_UNI: |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2885 | err = dh.PacketOutUNI(ctx, egressPortNo, packet) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2886 | case voltha.Port_ETHERNET_NNI: |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2887 | err = dh.PacketOutNNI(ctx, egressPortNo, packet) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2888 | default: |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2889 | logger.Warnw(ctx, "packet-out-to-this-interface-type-not-implemented", log.Fields{ |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2890 | "egress-port-no": egressPortNo, |
| Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 2891 | "egressPortType": egressPortType, |
| 2892 | "packet": hex.EncodeToString(packet.Data), |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2893 | "device-id": dh.device.Id, |
| Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 2894 | }) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2895 | } |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2896 | return err |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2897 | } |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 2898 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2899 | func (dh *DeviceHandler) formOnuKey(intfID, onuID uint32) string { |
| 2900 | return "" + strconv.Itoa(int(intfID)) + "." + strconv.Itoa(int(onuID)) |
| Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 2901 | } |
| Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2902 | |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2903 | func startHeartbeatCheck(ctx context.Context, dh *DeviceHandler) { |
| Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 2904 | defer func() { |
| 2905 | dh.lockDevice.Lock() |
| 2906 | dh.isHeartbeatCheckActive = false |
| 2907 | dh.lockDevice.Unlock() |
| 2908 | }() |
| 2909 | |
| 2910 | dh.lockDevice.Lock() |
| 2911 | dh.isHeartbeatCheckActive = true |
| 2912 | dh.lockDevice.Unlock() |
| 2913 | |
| Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2914 | // start the heartbeat check towards the OLT. |
| 2915 | var timerCheck *time.Timer |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2916 | dh.heartbeatSignature = dh.getHeartbeatSignature(ctx) |
| Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2917 | |
| 2918 | for { |
| 2919 | heartbeatTimer := time.NewTimer(dh.openOLT.HeartbeatCheckInterval) |
| 2920 | select { |
| 2921 | case <-heartbeatTimer.C: |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 2922 | ctxWithTimeout, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.openOLT.GrpcTimeoutInterval) |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2923 | if heartBeat, err := dh.Client.HeartbeatCheck(ctxWithTimeout, new(oop.Empty)); err != nil { |
| Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2924 | logger.Warnw(ctx, "heartbeat-failed", log.Fields{"device-id": dh.device.Id}) |
| Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2925 | if timerCheck == nil { |
| 2926 | // start a after func, when expired will update the state to the core |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2927 | timerCheck = time.AfterFunc(dh.openOLT.HeartbeatFailReportInterval, func() { dh.updateStateUnreachable(ctx) }) |
| Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2928 | } |
| 2929 | } else { |
| 2930 | if timerCheck != nil { |
| 2931 | if timerCheck.Stop() { |
| Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2932 | logger.Debugw(ctx, "got-heartbeat-within-timeout", log.Fields{"device-id": dh.device.Id}) |
| Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2933 | } |
| 2934 | timerCheck = nil |
| 2935 | } |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2936 | if dh.heartbeatSignature == 0 || dh.heartbeatSignature == heartBeat.HeartbeatSignature { |
| 2937 | if dh.heartbeatSignature == 0 { |
| 2938 | // First time the signature will be 0, update the signture to DB when not found. |
| 2939 | dh.updateHeartbeatSignature(ctx, heartBeat.HeartbeatSignature) |
| 2940 | dh.heartbeatSignature = heartBeat.HeartbeatSignature |
| 2941 | } |
| 2942 | logger.Infow(ctx, "heartbeat signature", log.Fields{"sign": dh.heartbeatSignature}) |
| 2943 | |
| 2944 | dh.lockDevice.RLock() |
| 2945 | // Stop the read indication only if it the routine is active |
| 2946 | // The read indication would have already stopped due to failure on the gRPC stream following OLT going unreachable |
| 2947 | // Sending message on the 'stopIndication' channel again will cause the readIndication routine to immediately stop |
| 2948 | // on next execution of the readIndication routine. |
| 2949 | if !dh.isReadIndicationRoutineActive { |
| 2950 | // Start reading indications |
| 2951 | go func() { |
| 2952 | if err = dh.readIndications(ctx); err != nil { |
| 2953 | _ = olterrors.NewErrAdapter("indication-read-failure", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| 2954 | } |
| 2955 | }() |
| 2956 | } |
| 2957 | dh.lockDevice.RUnlock() |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2958 | } else { |
| 2959 | logger.Warn(ctx, "Heartbeat signature changed, OLT is rebooted. Cleaningup resources.") |
| 2960 | dh.updateHeartbeatSignature(ctx, heartBeat.HeartbeatSignature) |
| 2961 | dh.heartbeatSignature = heartBeat.HeartbeatSignature |
| 2962 | go dh.updateStateRebooted(ctx) |
| 2963 | } |
| Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2964 | } |
| 2965 | cancel() |
| 2966 | case <-dh.stopHeartbeatCheck: |
| Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2967 | logger.Debugw(ctx, "stopping-heartbeat-check", log.Fields{"device-id": dh.device.Id}) |
| Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2968 | return |
| 2969 | } |
| 2970 | } |
| 2971 | } |
| 2972 | |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2973 | func (dh *DeviceHandler) updateStateUnreachable(ctx context.Context) { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2974 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2975 | if err != nil || device == nil { |
| Girish Gowdra | b1caa44 | 2020-10-19 12:24:39 -0700 | [diff] [blame] | 2976 | // One case where we have seen core returning an error for GetDevice call is after OLT device delete. |
| 2977 | // After OLT delete, the adapter asks for OLT to reboot. When OLT is rebooted, shortly we loose heartbeat. |
| 2978 | // The 'startHeartbeatCheck' then asks the device to be marked unreachable towards the core, but the core |
| 2979 | // has already deleted the device and returns error. In this particular scenario, it is Ok because any necessary |
| 2980 | // cleanup in the adapter was already done during DeleteDevice API handler routine. |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2981 | _ = olterrors.NewErrNotFound("device", log.Fields{"device-id": dh.device.Id}, err).Log() |
| Girish Gowdra | b1caa44 | 2020-10-19 12:24:39 -0700 | [diff] [blame] | 2982 | // Immediately return, otherwise accessing a null 'device' struct would cause panic |
| 2983 | return |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2984 | } |
| Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2985 | |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2986 | logger.Warnw(ctx, "update-state-unreachable", log.Fields{"device-id": dh.device.Id, "connect-status": device.ConnectStatus, |
| Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2987 | "admin-state": device.AdminState, "oper-status": device.OperStatus}) |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2988 | if device.ConnectStatus == voltha.ConnectStatus_REACHABLE { |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2989 | if err = dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2990 | DeviceId: dh.device.Id, |
| 2991 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2992 | ConnStatus: voltha.ConnectStatus_UNREACHABLE, |
| 2993 | }); err != nil { |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2994 | _ = olterrors.NewErrAdapter("device-state-update-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2995 | } |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2996 | /* |
| 2997 | if err = dh.updatePortsStateInCore(ctx, &ca.PortStateFilter{ |
| 2998 | DeviceId: dh.device.Id, |
| 2999 | PortTypeFilter: 0, |
| 3000 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 3001 | }); err != nil { |
| 3002 | _ = olterrors.NewErrAdapter("port-update-failed", log.Fields{"device-id": dh.device.Id}, err).Log() |
| 3003 | } |
| 3004 | */ |
| Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 3005 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3006 | // raise olt communication failure event |
| Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 3007 | raisedTs := time.Now().Unix() |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3008 | cloned := proto.Clone(device).(*voltha.Device) |
| 3009 | cloned.ConnectStatus = voltha.ConnectStatus_UNREACHABLE |
| 3010 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 3011 | dh.device = cloned // update local copy of the device |
| 3012 | go dh.eventMgr.oltCommunicationEvent(ctx, cloned, raisedTs) |
| Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 3013 | |
| Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 3014 | dh.lockDevice.RLock() |
| Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 3015 | // Stop the Stats collector |
| 3016 | if dh.isCollectorActive { |
| 3017 | dh.stopCollector <- true |
| 3018 | } |
| 3019 | // stop the heartbeat check routine |
| 3020 | if dh.isHeartbeatCheckActive { |
| 3021 | dh.stopHeartbeatCheck <- true |
| 3022 | } |
| Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 3023 | // Stop the read indication only if it the routine is active |
| 3024 | // The read indication would have already stopped due to failure on the gRPC stream following OLT going unreachable |
| 3025 | // Sending message on the 'stopIndication' channel again will cause the readIndication routine to immediately stop |
| 3026 | // on next execution of the readIndication routine. |
| 3027 | if dh.isReadIndicationRoutineActive { |
| 3028 | dh.stopIndications <- true |
| 3029 | } |
| 3030 | dh.lockDevice.RUnlock() |
| Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 3031 | dh.transitionMap.Handle(ctx, DeviceInit) |
| Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 3032 | } |
| 3033 | } |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3034 | |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3035 | func (dh *DeviceHandler) updateStateRebooted(ctx context.Context) { |
| 3036 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
| 3037 | if err != nil || device == nil { |
| 3038 | // One case where we have seen core returning an error for GetDevice call is after OLT device delete. |
| 3039 | // After OLT delete, the adapter asks for OLT to reboot. When OLT is rebooted, shortly we loose heartbeat. |
| 3040 | // The 'startHeartbeatCheck' then asks the device to be marked unreachable towards the core, but the core |
| 3041 | // has already deleted the device and returns error. In this particular scenario, it is Ok because any necessary |
| 3042 | // cleanup in the adapter was already done during DeleteDevice API handler routine. |
| 3043 | _ = olterrors.NewErrNotFound("device", log.Fields{"device-id": dh.device.Id}, err).Log() |
| 3044 | // Immediately return, otherwise accessing a null 'device' struct would cause panic |
| 3045 | return |
| 3046 | } |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3047 | // Starting the cleanup process |
| Mahir Gunyel | 701df86 | 2023-09-07 16:16:04 -0700 | [diff] [blame] | 3048 | dh.setDeviceDeletionInProgressFlag(true) |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3049 | |
| 3050 | logger.Warnw(ctx, "update-state-rebooted", log.Fields{"device-id": dh.device.Id, "connect-status": device.ConnectStatus, |
| 3051 | "admin-state": device.AdminState, "oper-status": device.OperStatus, "conn-status": voltha.ConnectStatus_UNREACHABLE}) |
| bseeniva | d1c984b | 2025-01-09 12:54:44 +0530 | [diff] [blame] | 3052 | // First, stop the read indication and heartbeat check routines to prevent any delay |
| 3053 | // in cleanup, which could cause the heartbeat routine to restart the read indication. |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3054 | dh.lockDevice.RLock() |
| 3055 | // Stop the read indication only if it the routine is active |
| 3056 | // The read indication would have already stopped due to failure on the gRPC stream following OLT going unreachable |
| 3057 | // Sending message on the 'stopIndication' channel again will cause the readIndication routine to immediately stop |
| 3058 | // on next execution of the readIndication routine. |
| 3059 | if dh.isReadIndicationRoutineActive { |
| 3060 | dh.stopIndications <- true |
| 3061 | } |
| 3062 | dh.lockDevice.RUnlock() |
| 3063 | |
| bseeniva | d1c984b | 2025-01-09 12:54:44 +0530 | [diff] [blame] | 3064 | if err = dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| 3065 | DeviceId: dh.device.Id, |
| 3066 | OperStatus: voltha.OperStatus_REBOOTED, |
| 3067 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 3068 | }); err != nil { |
| 3069 | _ = olterrors.NewErrAdapter("device-state-update-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| 3070 | } |
| 3071 | |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3072 | //raise olt communication failure event |
| 3073 | raisedTs := time.Now().Unix() |
| 3074 | cloned := proto.Clone(device).(*voltha.Device) |
| 3075 | cloned.ConnectStatus = voltha.ConnectStatus_UNREACHABLE |
| 3076 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 3077 | dh.device = cloned // update local copy of the device |
| 3078 | go dh.eventMgr.oltCommunicationEvent(ctx, cloned, raisedTs) |
| 3079 | |
| Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 3080 | if err := dh.cleanupDeviceResources(ctx); err != nil { |
| 3081 | logger.Errorw(ctx, "failure-in-cleanup-device-resources", log.Fields{"device-id": dh.device.Id, "err": err}) |
| 3082 | } else { |
| 3083 | logger.Debugw(ctx, "removed-device-from-Resource-manager-KV-store", log.Fields{"device-id": dh.device.Id}) |
| 3084 | } |
| Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 3085 | |
| 3086 | dh.lockDevice.RLock() |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3087 | // Stop the Stats collector |
| Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 3088 | if dh.isCollectorActive { |
| 3089 | dh.stopCollector <- true |
| 3090 | } |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3091 | // stop the heartbeat check routine |
| Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 3092 | if dh.isHeartbeatCheckActive { |
| 3093 | dh.stopHeartbeatCheck <- true |
| 3094 | } |
| 3095 | dh.lockDevice.RUnlock() |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3096 | |
| Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 3097 | dh.StopAllFlowRoutines(ctx) |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3098 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3099 | // reset adapter reconcile flag |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3100 | dh.adapterPreviouslyConnected = false |
| 3101 | for { |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3102 | childDevices, err := dh.getChildDevicesFromCore(ctx, dh.device.Id) |
| 3103 | if err != nil || childDevices == nil { |
| 3104 | logger.Errorw(ctx, "Failed to get child devices from core", log.Fields{"deviceID": dh.device.Id}) |
| 3105 | continue |
| 3106 | } |
| 3107 | if len(childDevices.Items) == 0 { |
| 3108 | logger.Infow(ctx, "All childDevices cleared from core, proceed with device init", log.Fields{"deviceID": dh.device.Id}) |
| 3109 | break |
| 3110 | } else { |
| 3111 | logger.Warn(ctx, "Not all child devices are cleared, continuing to wait") |
| 3112 | time.Sleep(5 * time.Second) |
| 3113 | } |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3114 | } |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3115 | // Cleanup completed , reset the flag |
| Mahir Gunyel | 701df86 | 2023-09-07 16:16:04 -0700 | [diff] [blame] | 3116 | dh.setDeviceDeletionInProgressFlag(false) |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3117 | logger.Infow(ctx, "cleanup complete after reboot , moving to init", log.Fields{"deviceID": device.Id}) |
| 3118 | dh.transitionMap.Handle(ctx, DeviceInit) |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3119 | } |
| 3120 | |
| balaji.nagarajan | 68f56e8 | 2025-07-04 15:16:01 +0530 | [diff] [blame] | 3121 | // EnableOnuSerialNumber to enable onu serial number |
| 3122 | func (dh *DeviceHandler) EnableOnuSerialNumber(ctx context.Context, device *voltha.OnuSerialNumberOnOLTPon) error { |
| 3123 | logger.Debugw(ctx, "enable-onu-serial-number", log.Fields{"Device": dh.device, "onu-serial-number": device.SerialNumber, "port": device.Port.PortNo}) |
| 3124 | onuSerialNumber := device.SerialNumber |
| 3125 | |
| 3126 | // fetch interfaceid from PortNo |
| 3127 | ponID := plt.PortNoToIntfID(device.Port.GetPortNo(), voltha.Port_PON_OLT) |
| 3128 | |
| 3129 | sn, err := dh.deStringifySerialNumber(onuSerialNumber) |
| 3130 | if err != nil { |
| 3131 | return olterrors.NewErrAdapter("failed-to-destringify-serial-number", |
| 3132 | log.Fields{ |
| 3133 | "devicer-id": dh.device.Id, |
| 3134 | "serial-number": onuSerialNumber}, err).Log() |
| 3135 | } |
| 3136 | |
| 3137 | onuIntf := &oop.InterfaceOnuSerialNumber{ |
| 3138 | IntfId: ponID, |
| 3139 | OnuSerialNumber: sn, |
| 3140 | } |
| 3141 | _, err = dh.Client.EnableOnuSerialNumber(ctx, onuIntf) |
| 3142 | |
| 3143 | if err != nil { |
| 3144 | logger.Errorw(ctx, "failed to enable onu serial number", log.Fields{"onudev": onuSerialNumber, "error": err}) |
| 3145 | return olterrors.NewErrAdapter("onu-serial-number-enable-failed", log.Fields{ |
| 3146 | "device-id": dh.device.Id, |
| 3147 | "onu-serial-number": onuSerialNumber}, err) |
| 3148 | } |
| 3149 | return nil |
| 3150 | } |
| 3151 | |
| 3152 | // DisableOnuSerialNumber to disable onu serial number |
| 3153 | func (dh *DeviceHandler) DisableOnuSerialNumber(ctx context.Context, device *voltha.OnuSerialNumberOnOLTPon) error { |
| 3154 | logger.Debugw(ctx, "disable-onu-serial-number", log.Fields{"Device": dh.device, "onu-serial-number": device.SerialNumber, "port": device.Port.PortNo}) |
| 3155 | onuSerialNumber := device.SerialNumber |
| 3156 | ponID := plt.PortNoToIntfID(device.Port.GetPortNo(), voltha.Port_PON_OLT) |
| 3157 | sn, err := dh.deStringifySerialNumber(onuSerialNumber) |
| 3158 | if err != nil { |
| 3159 | return olterrors.NewErrAdapter("failed-to-destringify-serial-number", |
| 3160 | log.Fields{ |
| 3161 | "devicer-id": dh.device.Id, |
| 3162 | "serial-number": onuSerialNumber}, err).Log() |
| 3163 | } |
| 3164 | |
| 3165 | onuIntf := &oop.InterfaceOnuSerialNumber{ |
| 3166 | OnuSerialNumber: sn, |
| 3167 | IntfId: ponID, |
| 3168 | } |
| 3169 | _, err = dh.Client.DisableOnuSerialNumber(ctx, onuIntf) |
| 3170 | |
| 3171 | if err != nil { |
| 3172 | logger.Errorw(ctx, "failed to disable onu serial number", log.Fields{"onudev": onuSerialNumber, "error": err}) |
| 3173 | return olterrors.NewErrAdapter("onu-serial-number-disable-failed", log.Fields{ |
| 3174 | "device-id": dh.device.Id, |
| 3175 | "onu-serial-number": onuSerialNumber}, err) |
| 3176 | } |
| 3177 | return nil |
| 3178 | } |
| 3179 | |
| 3180 | // EnableOnu to enable onu |
| 3181 | func (dh *DeviceHandler) EnableOnu(ctx context.Context, device *voltha.Device) error { |
| 3182 | logger.Debugw(ctx, "enable-onu", log.Fields{"Device": dh.device, "onu-serial-number": device.SerialNumber}) |
| 3183 | onuSerialNumber := device.SerialNumber |
| 3184 | InCacheOnuDev := dh.getChildDevice(ctx, onuSerialNumber, dh.device.ParentPortNo) |
| 3185 | if InCacheOnuDev == nil { |
| 3186 | logger.Errorw(ctx, "failed to get child device from cache", log.Fields{"onudev": onuSerialNumber}) |
| 3187 | return olterrors.NewErrAdapter("failed to get child device from cache", log.Fields{ |
| 3188 | "device-id": dh.device.Id, |
| 3189 | "onu-serial-number": onuSerialNumber}, nil) |
| 3190 | } |
| 3191 | logger.Debugw(ctx, "successfully-received-child-device-from-cache", log.Fields{"child-device-intfid": InCacheOnuDev.intfID, "child-device-sn": InCacheOnuDev.serialNumber, "child-onuid": InCacheOnuDev.onuID}) |
| 3192 | |
| 3193 | sn, err := dh.deStringifySerialNumber(onuSerialNumber) |
| 3194 | if err != nil { |
| 3195 | return olterrors.NewErrAdapter("failed-to-destringify-serial-number", |
| 3196 | log.Fields{ |
| 3197 | "device-id": dh.device.Id, |
| 3198 | "serial-number": onuSerialNumber}, err).Log() |
| 3199 | } |
| 3200 | |
| 3201 | onuIntf := &oop.InterfaceOnuSerialNumber{ |
| 3202 | OnuSerialNumber: sn, |
| 3203 | IntfId: InCacheOnuDev.intfID, |
| 3204 | } |
| 3205 | onuIntfReq := &oop.InterfaceOnuSerialNumberOnuId{ |
| 3206 | OnuId: InCacheOnuDev.onuID, |
| 3207 | IntfIdSerialNum: onuIntf, |
| 3208 | } |
| 3209 | _, err = dh.Client.EnableOnu(ctx, onuIntfReq) |
| 3210 | |
| 3211 | if err != nil { |
| 3212 | logger.Errorw(ctx, "failed to enable onu ", log.Fields{"onudev": onuSerialNumber, "error": err}) |
| 3213 | return olterrors.NewErrAdapter("onu-enable-failed", log.Fields{ |
| 3214 | "olt-device-id": dh.device.Id, |
| 3215 | "onu-serial-number": onuSerialNumber}, err) |
| 3216 | } |
| 3217 | return nil |
| 3218 | } |
| 3219 | |
| 3220 | // DisableOnu to disable onu |
| 3221 | func (dh *DeviceHandler) DisableOnu(ctx context.Context, device *voltha.Device) error { |
| 3222 | logger.Debugw(ctx, "disable-onu", log.Fields{"Device": dh.device, "onu-serial-number": device.SerialNumber}) |
| 3223 | onuSerialNumber := device.SerialNumber |
| 3224 | InCacheOnuDev := dh.getChildDevice(ctx, onuSerialNumber, dh.device.ParentPortNo) |
| 3225 | if InCacheOnuDev == nil { |
| 3226 | logger.Errorw(ctx, "failed to get child device from cache", log.Fields{"onudev": onuSerialNumber}) |
| 3227 | return olterrors.NewErrAdapter("failed to get child device from cache", log.Fields{ |
| 3228 | "device-id": dh.device.Id, |
| 3229 | "onu-serial-number": onuSerialNumber}, nil) |
| 3230 | } |
| 3231 | logger.Debugw(ctx, "successfully-received-child-device-from-cache", log.Fields{"child-device-intfid": InCacheOnuDev.intfID, "child-device-sn": InCacheOnuDev.serialNumber, "child-onuid": InCacheOnuDev.onuID}) |
| 3232 | |
| 3233 | sn, err := dh.deStringifySerialNumber(onuSerialNumber) |
| 3234 | if err != nil { |
| 3235 | return olterrors.NewErrAdapter("failed-to-destringify-serial-number", |
| 3236 | log.Fields{ |
| 3237 | "device-id": dh.device.Id, |
| 3238 | "serial-number": onuSerialNumber}, err).Log() |
| 3239 | } |
| 3240 | |
| 3241 | onuIntf := &oop.InterfaceOnuSerialNumber{ |
| 3242 | OnuSerialNumber: sn, |
| 3243 | IntfId: InCacheOnuDev.intfID, |
| 3244 | } |
| 3245 | onuIntfReq := &oop.InterfaceOnuSerialNumberOnuId{ |
| 3246 | OnuId: InCacheOnuDev.onuID, |
| 3247 | IntfIdSerialNum: onuIntf, |
| 3248 | } |
| 3249 | _, err = dh.Client.DisableOnu(ctx, onuIntfReq) |
| 3250 | |
| 3251 | if err != nil { |
| 3252 | logger.Errorw(ctx, "failed to disable onu ", log.Fields{"onudev": onuSerialNumber, "error": err}) |
| 3253 | return olterrors.NewErrAdapter("onu-disable-failed", log.Fields{ |
| 3254 | "olt-device-id": dh.device.Id, |
| 3255 | "onu-serial-number": onuSerialNumber}, err) |
| 3256 | } |
| 3257 | return nil |
| 3258 | } |
| 3259 | |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3260 | // EnablePort to enable Pon interface |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3261 | func (dh *DeviceHandler) EnablePort(ctx context.Context, port *voltha.Port) error { |
| 3262 | logger.Debugw(ctx, "enable-port", log.Fields{"Device": dh.device, "port": port}) |
| 3263 | return dh.modifyPhyPort(ctx, port, true) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | // DisablePort to disable pon interface |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3267 | func (dh *DeviceHandler) DisablePort(ctx context.Context, port *voltha.Port) error { |
| 3268 | logger.Debugw(ctx, "disable-port", log.Fields{"Device": dh.device, "port": port}) |
| 3269 | return dh.modifyPhyPort(ctx, port, false) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3270 | } |
| 3271 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3272 | // modifyPhyPort is common function to enable and disable the port. parm :enablePort, true to enablePort and false to disablePort. |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3273 | func (dh *DeviceHandler) modifyPhyPort(ctx context.Context, port *voltha.Port, enablePort bool) error { |
| 3274 | logger.Infow(ctx, "modifyPhyPort", log.Fields{"port": port, "Enable": enablePort, "device-id": dh.device.Id}) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3275 | if port.GetType() == voltha.Port_ETHERNET_NNI { |
| 3276 | // Bug is opened for VOL-2505 to support NNI disable feature. |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3277 | logger.Infow(ctx, "voltha-supports-single-nni-hence-disable-of-nni-not-allowed", |
| Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 3278 | log.Fields{"device": dh.device, "port": port}) |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3279 | return olterrors.NewErrAdapter("illegal-port-request", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3280 | "port-type": port.GetType, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3281 | "enable-state": enablePort}, nil) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3282 | } |
| 3283 | // fetch interfaceid from PortNo |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3284 | ponID := plt.PortNoToIntfID(port.GetPortNo(), voltha.Port_PON_OLT) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3285 | ponIntf := &oop.Interface{IntfId: ponID} |
| 3286 | var operStatus voltha.OperStatus_Types |
| 3287 | if enablePort { |
| 3288 | operStatus = voltha.OperStatus_ACTIVE |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3289 | out, err := dh.Client.EnablePonIf(ctx, ponIntf) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3290 | |
| 3291 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3292 | return olterrors.NewErrAdapter("pon-port-enable-failed", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3293 | "device-id": dh.device.Id, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3294 | "port": port}, err) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3295 | } |
| 3296 | // updating interface local cache for collecting stats |
| Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 3297 | dh.activePorts.Store(ponID, true) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3298 | logger.Infow(ctx, "enabled-pon-port", log.Fields{"out": out, "device-id": dh.device, "Port": port}) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3299 | } else { |
| 3300 | operStatus = voltha.OperStatus_UNKNOWN |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3301 | out, err := dh.Client.DisablePonIf(ctx, ponIntf) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3302 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3303 | return olterrors.NewErrAdapter("pon-port-disable-failed", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3304 | "device-id": dh.device.Id, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3305 | "port": port}, err) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3306 | } |
| 3307 | // updating interface local cache for collecting stats |
| Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 3308 | dh.activePorts.Store(ponID, false) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3309 | logger.Infow(ctx, "disabled-pon-port", log.Fields{"out": out, "device-id": dh.device, "Port": port}) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3310 | } |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3311 | if err := dh.updatePortStateInCore(ctx, &ca.PortState{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3312 | DeviceId: dh.device.Id, |
| 3313 | PortType: voltha.Port_PON_OLT, |
| 3314 | PortNo: port.PortNo, |
| 3315 | OperStatus: operStatus, |
| 3316 | }); err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3317 | return olterrors.NewErrAdapter("port-state-update-failed", log.Fields{ |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 3318 | "device-id": dh.device.Id, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3319 | "port": port.PortNo}, err) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3320 | } |
| 3321 | return nil |
| 3322 | } |
| 3323 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3324 | // disableAdminDownPorts disables the ports, if the corresponding port Adminstate is disabled on reboot and Renable device. |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 3325 | func (dh *DeviceHandler) disableAdminDownPorts(ctx context.Context, ports []*voltha.Port) error { |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3326 | // Disable the port and update the oper_port_status to core |
| 3327 | // if the Admin state of the port is disabled on reboot and re-enable device. |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 3328 | for _, port := range ports { |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3329 | if port.AdminState == common.AdminState_DISABLED { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3330 | if err := dh.DisablePort(ctx, port); err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3331 | return olterrors.NewErrAdapter("port-disable-failed", log.Fields{ |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 3332 | "device-id": dh.device.Id, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3333 | "port": port}, err) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3334 | } |
| 3335 | } |
| 3336 | } |
| 3337 | return nil |
| 3338 | } |
| 3339 | |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3340 | // populateActivePorts to populate activePorts map |
| Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 3341 | func (dh *DeviceHandler) populateActivePorts(ctx context.Context, ports []*voltha.Port) { |
| 3342 | logger.Infow(ctx, "populateActivePorts", log.Fields{"device-id": dh.device.Id}) |
| 3343 | for _, port := range ports { |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3344 | if port.Type == voltha.Port_ETHERNET_NNI { |
| 3345 | if port.OperStatus == voltha.OperStatus_ACTIVE { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3346 | dh.activePorts.Store(plt.PortNoToIntfID(port.PortNo, voltha.Port_ETHERNET_NNI), true) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3347 | } else { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3348 | dh.activePorts.Store(plt.PortNoToIntfID(port.PortNo, voltha.Port_ETHERNET_NNI), false) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3349 | } |
| 3350 | } |
| 3351 | if port.Type == voltha.Port_PON_OLT { |
| 3352 | if port.OperStatus == voltha.OperStatus_ACTIVE { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3353 | dh.activePorts.Store(plt.PortNoToIntfID(port.PortNo, voltha.Port_PON_OLT), true) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3354 | } else { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3355 | dh.activePorts.Store(plt.PortNoToIntfID(port.PortNo, voltha.Port_PON_OLT), false) |
| kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3356 | } |
| 3357 | } |
| 3358 | } |
| 3359 | } |
| Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 3360 | |
| 3361 | // ChildDeviceLost deletes ONU and clears pon resources related to it. |
| Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 3362 | func (dh *DeviceHandler) ChildDeviceLost(ctx context.Context, pPortNo uint32, onuID uint32, onuSn string) error { |
| divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 3363 | logger.Debugw(ctx, "child-device-lost", log.Fields{"parent-device-id": dh.device.Id}) |
| Girish Gowdra | b4c3330 | 2022-03-18 15:07:38 -0700 | [diff] [blame] | 3364 | if dh.getDeviceDeletionInProgressFlag() { |
| 3365 | // Given that the OLT device itself is getting deleted, everything will be cleaned up in the DB and the OLT |
| 3366 | // will reboot, so everything will be reset on the pOLT too. |
| 3367 | logger.Infow(ctx, "olt-device-delete-in-progress-not-handling-child-device-lost", |
| 3368 | log.Fields{"parent-device-id": dh.device.Id, "pon-port": pPortNo, "onuID": onuID, "onuSN": onuSn}) |
| 3369 | return nil |
| 3370 | } |
| Sridhar Ravindra | 92c9b0d | 2025-01-16 00:15:54 +0530 | [diff] [blame] | 3371 | |
| 3372 | if dh.transitionMap.currentDeviceState != deviceStateUp { |
| 3373 | logger.Warnw(ctx, "device-is-not-up--not-handling-child-device-lost", log.Fields{"device-id": dh.device.Id, "current-device-state": dh.transitionMap.currentDeviceState}) |
| 3374 | return fmt.Errorf("device-is-not-up--not-handling-child-device-lost") |
| 3375 | } |
| 3376 | |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3377 | intfID := plt.PortNoToIntfID(pPortNo, voltha.Port_PON_OLT) |
| Girish Gowdra | 89ae6d8 | 2020-05-28 23:40:53 -0700 | [diff] [blame] | 3378 | onuKey := dh.formOnuKey(intfID, onuID) |
| Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 3379 | |
| Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 3380 | var sn *oop.SerialNumber |
| 3381 | var err error |
| Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 3382 | if sn, err = dh.deStringifySerialNumber(onuSn); err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3383 | return olterrors.NewErrAdapter("failed-to-destringify-serial-number", |
| Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 3384 | log.Fields{ |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 3385 | "devicer-id": dh.device.Id, |
| Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 3386 | "serial-number": onuSn}, err).Log() |
| Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 3387 | } |
| Girish Gowdra | 89ae6d8 | 2020-05-28 23:40:53 -0700 | [diff] [blame] | 3388 | |
| Girish Gowdra | 89ae6d8 | 2020-05-28 23:40:53 -0700 | [diff] [blame] | 3389 | onu := &oop.Onu{IntfId: intfID, OnuId: onuID, SerialNumber: sn} |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3390 | // clear PON resources associated with ONU |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3391 | onuGem, err := dh.resourceMgr[intfID].GetOnuGemInfo(ctx, onuID) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3392 | if err != nil || onuGem == nil || onuGem.OnuID != onuID { |
| 3393 | logger.Warnw(ctx, "failed-to-get-onu-info-for-pon-port", log.Fields{ |
| 3394 | "device-id": dh.device.Id, |
| 3395 | "intf-id": intfID, |
| 3396 | "onuID": onuID, |
| 3397 | "err": err}) |
| 3398 | } else { |
| 3399 | logger.Debugw(ctx, "onu-data", log.Fields{"onu": onu}) |
| yasin sapli | e87d4bd | 2021-12-06 09:04:03 +0000 | [diff] [blame] | 3400 | // Delete flows from device before schedulers and queue |
| 3401 | // Clear flowids for gem cache. |
| 3402 | removedFlows := []uint64{} |
| 3403 | for _, gem := range onuGem.GemPorts { |
| 3404 | if flowIDs, err := dh.resourceMgr[intfID].GetFlowIDsForGem(ctx, gem); err == nil { |
| 3405 | for _, flowID := range flowIDs { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3406 | // multiple gem port can have the same flow id |
| 3407 | // it is better to send only one flowRemove request to the agent |
| yasin sapli | e87d4bd | 2021-12-06 09:04:03 +0000 | [diff] [blame] | 3408 | var alreadyRemoved bool |
| 3409 | for _, removedFlowID := range removedFlows { |
| 3410 | if removedFlowID == flowID { |
| 3411 | logger.Debugw(ctx, "flow-is-already-removed-due-to-another-gem", log.Fields{"flowID": flowID}) |
| 3412 | alreadyRemoved = true |
| 3413 | break |
| 3414 | } |
| 3415 | } |
| 3416 | if !alreadyRemoved { |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3417 | dh.removeFlowFromDevice(ctx, flowID, intfID) |
| yasin sapli | e87d4bd | 2021-12-06 09:04:03 +0000 | [diff] [blame] | 3418 | removedFlows = appendUnique64bit(removedFlows, flowID) |
| 3419 | } |
| 3420 | } |
| 3421 | } |
| 3422 | _ = dh.resourceMgr[intfID].DeleteFlowIDsForGem(ctx, gem) |
| 3423 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3424 | if err := dh.clearUNIData(ctx, onuGem); err != nil { |
| 3425 | logger.Warnw(ctx, "failed-to-clear-uni-data-for-onu", log.Fields{ |
| 3426 | "device-id": dh.device.Id, |
| 3427 | "onu-device": onu, |
| 3428 | "err": err}) |
| 3429 | } |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3430 | if err := dh.resourceMgr[intfID].DelOnuGemInfo(ctx, onuID); err != nil { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3431 | logger.Warnw(ctx, "persistence-update-onu-gem-info-failed", log.Fields{ |
| 3432 | "intf-id": intfID, |
| 3433 | "onu-device": onu, |
| 3434 | "onu-gem": onuGem, |
| 3435 | "err": err}) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3436 | // Not returning error on cleanup. |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3437 | } |
| 3438 | logger.Debugw(ctx, "removed-onu-gem-info", log.Fields{"intf": intfID, "onu-device": onu, "onugem": onuGem}) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3439 | } |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3440 | dh.resourceMgr[intfID].FreeonuID(ctx, []uint32{onuID}) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3441 | dh.onus.Delete(onuKey) |
| 3442 | dh.discOnus.Delete(onuSn) |
| 3443 | |
| 3444 | // Now clear the ONU on the OLT |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 3445 | if _, err := dh.Client.DeleteOnu(log.WithSpanFromContext(context.Background(), ctx), onu); err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3446 | return olterrors.NewErrAdapter("failed-to-delete-onu", log.Fields{ |
| Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 3447 | "device-id": dh.device.Id, |
| Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 3448 | "onu-id": onuID}, err).Log() |
| 3449 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3450 | |
| Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 3451 | return nil |
| 3452 | } |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3453 | func (dh *DeviceHandler) removeFlowFromDevice(ctx context.Context, flowID uint64, intfID uint32) { |
| 3454 | flow := &oop.Flow{FlowId: flowID} |
| 3455 | if dh.flowMgr == nil || dh.flowMgr[intfID] == nil { |
| 3456 | logger.Warnw(ctx, "failed-to-get-flow-mgr-to-remove-flow-from-device", log.Fields{ |
| 3457 | "device-id": dh.device.Id}) |
| 3458 | } else { |
| 3459 | if err := dh.flowMgr[intfID].removeFlowFromDevice(ctx, flow, flowID); err != nil { |
| 3460 | logger.Warnw(ctx, "failed-to-remove-flow-from-device", log.Fields{ |
| 3461 | "device-id": dh.device.Id, |
| 3462 | "err": err}) |
| 3463 | } |
| 3464 | } |
| 3465 | } |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3466 | |
| 3467 | func getInPortFromFlow(flow *of.OfpFlowStats) uint32 { |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3468 | for _, field := range flow_utils.GetOfbFields(flow) { |
| 3469 | if field.Type == flow_utils.IN_PORT { |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3470 | return field.GetPort() |
| 3471 | } |
| 3472 | } |
| 3473 | return InvalidPort |
| 3474 | } |
| 3475 | |
| 3476 | func getOutPortFromFlow(flow *of.OfpFlowStats) uint32 { |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3477 | for _, action := range flow_utils.GetActions(flow) { |
| 3478 | if action.Type == flow_utils.OUTPUT { |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3479 | if out := action.GetOutput(); out != nil { |
| 3480 | return out.GetPort() |
| 3481 | } |
| 3482 | } |
| 3483 | } |
| 3484 | return InvalidPort |
| 3485 | } |
| 3486 | |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3487 | func getPorts(flow *of.OfpFlowStats) (uint32, uint32) { |
| 3488 | inPort := getInPortFromFlow(flow) |
| 3489 | outPort := getOutPortFromFlow(flow) |
| 3490 | |
| 3491 | if inPort == InvalidPort || outPort == InvalidPort { |
| 3492 | return inPort, outPort |
| 3493 | } |
| 3494 | |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3495 | if isControllerFlow := plt.IsControllerBoundFlow(outPort); isControllerFlow { |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3496 | /* Get UNI port/ IN Port from tunnel ID field for upstream controller bound flows */ |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3497 | if portType := plt.IntfIDToPortTypeName(inPort); portType == voltha.Port_PON_OLT { |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3498 | if uniPort := flow_utils.GetChildPortFromTunnelId(flow); uniPort != 0 { |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3499 | return uniPort, outPort |
| 3500 | } |
| 3501 | } |
| 3502 | } else { |
| 3503 | // Downstream flow from NNI to PON port , Use tunnel ID as new OUT port / UNI port |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3504 | if portType := plt.IntfIDToPortTypeName(outPort); portType == voltha.Port_PON_OLT { |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3505 | if uniPort := flow_utils.GetChildPortFromTunnelId(flow); uniPort != 0 { |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3506 | return inPort, uniPort |
| 3507 | } |
| 3508 | // Upstream flow from PON to NNI port , Use tunnel ID as new IN port / UNI port |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3509 | } else if portType := plt.IntfIDToPortTypeName(inPort); portType == voltha.Port_PON_OLT { |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3510 | if uniPort := flow_utils.GetChildPortFromTunnelId(flow); uniPort != 0 { |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3511 | return uniPort, outPort |
| 3512 | } |
| 3513 | } |
| 3514 | } |
| 3515 | |
| 3516 | return InvalidPort, InvalidPort |
| 3517 | } |
| Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 3518 | |
| 3519 | func extractOmciTransactionID(omciPkt []byte) uint16 { |
| 3520 | if len(omciPkt) > 3 { |
| 3521 | d := omciPkt[0:2] |
| 3522 | transid := binary.BigEndian.Uint16(d) |
| 3523 | return transid |
| 3524 | } |
| 3525 | return 0 |
| 3526 | } |
| Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 3527 | |
| 3528 | // StoreOnuDevice stores the onu parameters to the local cache. |
| 3529 | func (dh *DeviceHandler) StoreOnuDevice(onuDevice *OnuDevice) { |
| 3530 | onuKey := dh.formOnuKey(onuDevice.intfID, onuDevice.onuID) |
| 3531 | dh.onus.Store(onuKey, onuDevice) |
| 3532 | } |
| Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 3533 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3534 | func (dh *DeviceHandler) getExtValue(ctx context.Context, device *voltha.Device, value extension.ValueType_Type) (*extension.ReturnValues, error) { |
| Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 3535 | var err error |
| Andrea Campanella | 9931ad6 | 2020-04-28 15:11:06 +0200 | [diff] [blame] | 3536 | var sn *oop.SerialNumber |
| Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3537 | var ID uint32 |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3538 | resp := new(extension.ReturnValues) |
| Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 3539 | valueparam := new(oop.ValueParam) |
| Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 3540 | ctx = log.WithSpanFromContext(context.Background(), ctx) |
| Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 3541 | logger.Infow(ctx, "getExtValue", log.Fields{"onu-id": device.Id, "pon-intf": device.ParentPortNo}) |
| Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 3542 | if sn, err = dh.deStringifySerialNumber(device.SerialNumber); err != nil { |
| 3543 | return nil, err |
| 3544 | } |
| 3545 | ID = device.ProxyAddress.GetOnuId() |
| 3546 | Onu := oop.Onu{IntfId: device.ParentPortNo, OnuId: ID, SerialNumber: sn} |
| 3547 | valueparam.Onu = &Onu |
| 3548 | valueparam.Value = value |
| 3549 | |
| 3550 | // This API is unsupported until agent patch is added |
| 3551 | resp.Unsupported = uint32(value) |
| 3552 | _ = ctx |
| 3553 | |
| 3554 | // Uncomment this code once agent changes are complete and tests |
| 3555 | /* |
| 3556 | resp, err = dh.Client.GetValue(ctx, valueparam) |
| 3557 | if err != nil { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3558 | logger.Errorw("error-while-getValue", log.Fields{"DeviceID": dh.device, "onu-id": onuid, "err": err}) |
| Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 3559 | return nil, err |
| 3560 | } |
| 3561 | */ |
| 3562 | |
| Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 3563 | logger.Infow(ctx, "get-ext-value", log.Fields{"resp": resp, "device-id": dh.device, "onu-id": device.Id, "pon-intf": device.ParentPortNo}) |
| Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 3564 | return resp, nil |
| 3565 | } |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 3566 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3567 | func (dh *DeviceHandler) getIntfIDFromFlow(flow *of.OfpFlowStats) uint32 { |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 3568 | // Default to NNI |
| 3569 | var intfID = dh.totalPonPorts |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 3570 | inPort, outPort := getPorts(flow) |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 3571 | if inPort != InvalidPort && outPort != InvalidPort { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3572 | _, intfID, _, _ = plt.ExtractAccessFromFlow(inPort, outPort) |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 3573 | } |
| 3574 | return intfID |
| 3575 | } |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3576 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3577 | func (dh *DeviceHandler) getOnuIndicationChannel(intfID uint32) chan onuIndicationMsg { |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3578 | dh.perPonOnuIndicationChannelLock.Lock() |
| 3579 | if ch, ok := dh.perPonOnuIndicationChannel[intfID]; ok { |
| 3580 | dh.perPonOnuIndicationChannelLock.Unlock() |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3581 | return ch.indicationChannel |
| 3582 | } |
| 3583 | channels := onuIndicationChannels{ |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3584 | // We create a buffered channel here to avoid calling function to be blocked |
| 3585 | // in case of multiple indications from the ONUs, |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3586 | //especially in the case where indications are buffered in OLT. |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3587 | indicationChannel: make(chan onuIndicationMsg, 500), |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3588 | stopChannel: make(chan struct{}), |
| 3589 | } |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3590 | dh.perPonOnuIndicationChannel[intfID] = channels |
| 3591 | dh.perPonOnuIndicationChannelLock.Unlock() |
| 3592 | go dh.onuIndicationsRoutine(&channels) |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3593 | return channels.indicationChannel |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3594 | } |
| 3595 | |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3596 | func (dh *DeviceHandler) removeOnuIndicationChannels(ctx context.Context) { |
| 3597 | logger.Debug(ctx, "remove-onu-indication-channels", log.Fields{"device-id": dh.device.Id}) |
| 3598 | dh.perPonOnuIndicationChannelLock.Lock() |
| 3599 | defer dh.perPonOnuIndicationChannelLock.Unlock() |
| 3600 | for _, v := range dh.perPonOnuIndicationChannel { |
| 3601 | close(v.stopChannel) |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3602 | } |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3603 | dh.perPonOnuIndicationChannel = make(map[uint32]onuIndicationChannels) |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3604 | } |
| 3605 | |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3606 | func (dh *DeviceHandler) putOnuIndicationToChannel(ctx context.Context, indication *oop.Indication, intfID uint32) { |
| 3607 | ind := onuIndicationMsg{ |
| 3608 | ctx: ctx, |
| 3609 | indication: indication, |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3610 | } |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3611 | logger.Debugw(ctx, "put-onu-indication-to-channel", log.Fields{"indication": indication, "intfID": intfID}) |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3612 | // Send the onuIndication on the ONU channel |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3613 | dh.getOnuIndicationChannel(intfID) <- ind |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3614 | } |
| 3615 | |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3616 | func (dh *DeviceHandler) onuIndicationsRoutine(onuChannels *onuIndicationChannels) { |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3617 | for { |
| 3618 | select { |
| 3619 | // process one indication per onu, before proceeding to the next one |
| 3620 | case onuInd := <-onuChannels.indicationChannel: |
| Andrea Campanella | 46b0140 | 2021-11-15 16:58:05 -0800 | [diff] [blame] | 3621 | indication := *(proto.Clone(onuInd.indication)).(*oop.Indication) |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3622 | logger.Debugw(onuInd.ctx, "calling-indication", log.Fields{"device-id": dh.device.Id, |
| Andrea Campanella | 46b0140 | 2021-11-15 16:58:05 -0800 | [diff] [blame] | 3623 | "ind": indication}) |
| 3624 | switch indication.Data.(type) { |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3625 | case *oop.Indication_OnuInd: |
| Andrea Campanella | 46b0140 | 2021-11-15 16:58:05 -0800 | [diff] [blame] | 3626 | if err := dh.onuIndication(onuInd.ctx, indication.GetOnuInd()); err != nil { |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3627 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{ |
| 3628 | "type": "onu-indication", |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3629 | "device-id": dh.device.Id}, err).Log() |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3630 | } |
| 3631 | case *oop.Indication_OnuDiscInd: |
| Andrea Campanella | 46b0140 | 2021-11-15 16:58:05 -0800 | [diff] [blame] | 3632 | if err := dh.onuDiscIndication(onuInd.ctx, indication.GetOnuDiscInd()); err != nil { |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3633 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{ |
| 3634 | "type": "onu-discovery", |
| Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3635 | "device-id": dh.device.Id}, err).Log() |
| Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3636 | } |
| 3637 | } |
| 3638 | case <-onuChannels.stopChannel: |
| 3639 | logger.Debugw(context.Background(), "stop-signal-received-for-onu-channel", log.Fields{"device-id": dh.device.Id}) |
| 3640 | close(onuChannels.indicationChannel) |
| 3641 | return |
| 3642 | } |
| 3643 | } |
| 3644 | } |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3645 | |
| 3646 | // RouteMcastFlowOrGroupMsgToChannel routes incoming mcast flow or group to a channel to be handled by the a specific |
| 3647 | // instance of mcastFlowOrGroupChannelHandlerRoutine meant to handle messages for that group. |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3648 | func (dh *DeviceHandler) RouteMcastFlowOrGroupMsgToChannel(ctx context.Context, flow *of.OfpFlowStats, group *of.OfpGroupEntry, action string) error { |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 3649 | if dh.getDeviceDeletionInProgressFlag() { |
| 3650 | // The device itself is going to be reset as part of deletion. So nothing to be done. |
| 3651 | logger.Infow(ctx, "device-deletion-in-progress--not-handling-flows-or-groups", log.Fields{"device-id": dh.device.Id}) |
| 3652 | return nil |
| 3653 | } |
| 3654 | |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3655 | // Step1 : Fill McastFlowOrGroupControlBlock |
| 3656 | // Step2 : Push the McastFlowOrGroupControlBlock to appropriate channel |
| 3657 | // Step3 : Wait on response channel for response |
| 3658 | // Step4 : Return error value |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3659 | startTime := time.Now() |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3660 | logger.Debugw(ctx, "process-flow-or-group", log.Fields{"flow": flow, "group": group, "action": action}) |
| 3661 | errChan := make(chan error) |
| 3662 | var groupID uint32 |
| 3663 | mcastFlowOrGroupCb := McastFlowOrGroupControlBlock{ |
| 3664 | ctx: ctx, |
| 3665 | flowOrGroupAction: action, |
| 3666 | flow: flow, |
| 3667 | group: group, |
| 3668 | errChan: &errChan, |
| 3669 | } |
| 3670 | if flow != nil { |
| 3671 | groupID = flow_utils.GetGroup(flow) |
| 3672 | } else if group != nil { |
| 3673 | groupID = group.Desc.GroupId |
| 3674 | } else { |
| 3675 | return errors.New("flow-and-group-both-nil") |
| 3676 | } |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3677 | mcastRoutineIdx := groupID % MaxNumOfGroupHandlerChannels |
| 3678 | if dh.mcastHandlerRoutineActive[mcastRoutineIdx] { |
| 3679 | // Derive the appropriate go routine to handle the request by a simple module operation. |
| 3680 | // There are only MaxNumOfGroupHandlerChannels number of channels to handle the mcast flow or group |
| 3681 | dh.incomingMcastFlowOrGroup[groupID%MaxNumOfGroupHandlerChannels] <- mcastFlowOrGroupCb |
| 3682 | // Wait for handler to return error value |
| 3683 | err := <-errChan |
| 3684 | logger.Debugw(ctx, "process-flow-or-group--received-resp", log.Fields{"err": err, "totalTimeInSeconds": time.Since(startTime).Milliseconds()}) |
| 3685 | return err |
| 3686 | } |
| 3687 | logger.Errorw(ctx, "mcast handler routine not active for onu", log.Fields{"mcastRoutineIdx": mcastRoutineIdx}) |
| 3688 | return fmt.Errorf("mcast-handler-routine-not-active-for-index-%v", mcastRoutineIdx) |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3689 | } |
| 3690 | |
| 3691 | // mcastFlowOrGroupChannelHandlerRoutine routine to handle incoming mcast flow/group message |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3692 | func (dh *DeviceHandler) mcastFlowOrGroupChannelHandlerRoutine(routineIndex int, mcastFlowOrGroupChannel chan McastFlowOrGroupControlBlock, stopHandler chan bool) { |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3693 | for { |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3694 | select { |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3695 | // block on the channel to receive an incoming mcast flow/group |
| 3696 | // process the flow completely before proceeding to handle the next flow |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3697 | case mcastFlowOrGroupCb := <-mcastFlowOrGroupChannel: |
| 3698 | if mcastFlowOrGroupCb.flow != nil { |
| 3699 | if mcastFlowOrGroupCb.flowOrGroupAction == McastFlowOrGroupAdd { |
| 3700 | logger.Debugw(mcastFlowOrGroupCb.ctx, "adding-mcast-flow", |
| 3701 | log.Fields{"device-id": dh.device.Id, |
| 3702 | "flowToAdd": mcastFlowOrGroupCb.flow}) |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3703 | err := olterrors.NewErrNotFound("no-flow-manager-found-to-add-mcast-flow", log.Fields{"device-id": dh.device.Id}, nil).(error) |
| 3704 | // The mcast flow is not unique to any particular PON port, so it is OK to default to first non nil PON |
| 3705 | for _, flMgr := range dh.flowMgr { |
| 3706 | if flMgr != nil { |
| 3707 | err = flMgr.AddFlow(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.flow, nil) |
| 3708 | break |
| 3709 | } |
| 3710 | } |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3711 | // Pass the return value over the return channel |
| 3712 | *mcastFlowOrGroupCb.errChan <- err |
| 3713 | } else { // flow remove |
| 3714 | logger.Debugw(mcastFlowOrGroupCb.ctx, "removing-mcast-flow", |
| 3715 | log.Fields{"device-id": dh.device.Id, |
| 3716 | "flowToRemove": mcastFlowOrGroupCb.flow}) |
| Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3717 | // The mcast flow is not unique to any particular PON port, so it is OK to default to first non nil PON |
| 3718 | err := olterrors.NewErrNotFound("no-flow-manager-found-to-remove-mcast-flow", log.Fields{"device-id": dh.device.Id}, nil).(error) |
| 3719 | for _, flMgr := range dh.flowMgr { |
| 3720 | if flMgr != nil { |
| 3721 | err = flMgr.RemoveFlow(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.flow) |
| 3722 | break |
| 3723 | } |
| 3724 | } |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3725 | // Pass the return value over the return channel |
| 3726 | *mcastFlowOrGroupCb.errChan <- err |
| 3727 | } |
| 3728 | } else { // mcast group |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3729 | switch mcastFlowOrGroupCb.flowOrGroupAction { |
| 3730 | case McastFlowOrGroupAdd: |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3731 | logger.Debugw(mcastFlowOrGroupCb.ctx, "adding-mcast-group", |
| 3732 | log.Fields{"device-id": dh.device.Id, |
| 3733 | "groupToAdd": mcastFlowOrGroupCb.group}) |
| 3734 | err := dh.groupMgr.AddGroup(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.group) |
| 3735 | // Pass the return value over the return channel |
| 3736 | *mcastFlowOrGroupCb.errChan <- err |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3737 | case McastFlowOrGroupModify: // group modify |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3738 | logger.Debugw(mcastFlowOrGroupCb.ctx, "modifying-mcast-group", |
| 3739 | log.Fields{"device-id": dh.device.Id, |
| 3740 | "groupToModify": mcastFlowOrGroupCb.group}) |
| 3741 | err := dh.groupMgr.ModifyGroup(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.group) |
| 3742 | // Pass the return value over the return channel |
| 3743 | *mcastFlowOrGroupCb.errChan <- err |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3744 | default: // group remove |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3745 | logger.Debugw(mcastFlowOrGroupCb.ctx, "removing-mcast-group", |
| 3746 | log.Fields{"device-id": dh.device.Id, |
| 3747 | "groupToRemove": mcastFlowOrGroupCb.group}) |
| 3748 | err := dh.groupMgr.DeleteGroup(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.group) |
| 3749 | // Pass the return value over the return channel |
| 3750 | *mcastFlowOrGroupCb.errChan <- err |
| 3751 | } |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3752 | } |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3753 | case <-stopHandler: |
| 3754 | dh.mcastHandlerRoutineActive[routineIndex] = false |
| 3755 | return |
| Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3756 | } |
| 3757 | } |
| 3758 | } |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3759 | |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3760 | // StopAllMcastHandlerRoutines stops all flow handler routines. Call this when device is being rebooted or deleted |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 3761 | func (dh *DeviceHandler) StopAllMcastHandlerRoutines(ctx context.Context, wg *sync.WaitGroup) { |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3762 | for i, v := range dh.stopMcastHandlerRoutine { |
| 3763 | if dh.mcastHandlerRoutineActive[i] { |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 3764 | select { |
| 3765 | case v <- true: |
| 3766 | case <-time.After(time.Second * 5): |
| 3767 | logger.Warnw(ctx, "timeout stopping mcast handler routine", log.Fields{"idx": i, "deviceID": dh.device.Id}) |
| 3768 | } |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3769 | } |
| 3770 | } |
| Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 3771 | |
| 3772 | if dh.incomingMcastFlowOrGroup != nil { |
| 3773 | for k := range dh.incomingMcastFlowOrGroup { |
| 3774 | if dh.incomingMcastFlowOrGroup[k] != nil { |
| 3775 | dh.incomingMcastFlowOrGroup[k] = nil |
| 3776 | } |
| 3777 | } |
| 3778 | dh.incomingMcastFlowOrGroup = nil |
| 3779 | } |
| 3780 | |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 3781 | wg.Done() |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3782 | logger.Debug(ctx, "stopped all mcast handler routines") |
| 3783 | } |
| 3784 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3785 | // nolint: unparam |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3786 | func (dh *DeviceHandler) getOltPortCounters(ctx context.Context, oltPortInfo *extension.GetOltPortCounters) *extension.SingleGetValueResponse { |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3787 | singleValResp := extension.SingleGetValueResponse{ |
| 3788 | Response: &extension.GetValueResponse{ |
| 3789 | Response: &extension.GetValueResponse_PortCoutners{ |
| 3790 | PortCoutners: &extension.GetOltPortCountersResponse{}, |
| 3791 | }, |
| 3792 | }, |
| 3793 | } |
| 3794 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3795 | errResp := func(status extension.GetValueResponse_Status, reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3796 | return &extension.SingleGetValueResponse{ |
| 3797 | Response: &extension.GetValueResponse{ |
| 3798 | Status: status, |
| 3799 | ErrReason: reason, |
| 3800 | }, |
| 3801 | } |
| 3802 | } |
| 3803 | |
| 3804 | if oltPortInfo.PortType != extension.GetOltPortCounters_Port_ETHERNET_NNI && |
| 3805 | oltPortInfo.PortType != extension.GetOltPortCounters_Port_PON_OLT { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3806 | // send error response |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3807 | logger.Debugw(ctx, "getOltPortCounters invalid portType", log.Fields{"oltPortInfo": oltPortInfo.PortType}) |
| 3808 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_PORT_TYPE) |
| 3809 | } |
| 3810 | statIndChn := make(chan bool, 1) |
| 3811 | dh.portStats.RegisterForStatIndication(ctx, portStatsType, statIndChn, oltPortInfo.PortNo, oltPortInfo.PortType) |
| 3812 | defer dh.portStats.DeRegisterFromStatIndication(ctx, portStatsType, statIndChn) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3813 | // request openOlt agent to send the the port statistics indication |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3814 | |
| 3815 | go func() { |
| 3816 | _, err := dh.Client.CollectStatistics(ctx, new(oop.Empty)) |
| 3817 | if err != nil { |
| 3818 | logger.Errorw(ctx, "getOltPortCounters CollectStatistics failed ", log.Fields{"err": err}) |
| 3819 | } |
| 3820 | }() |
| 3821 | select { |
| 3822 | case <-statIndChn: |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3823 | // indication received for ports stats |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3824 | logger.Debugw(ctx, "getOltPortCounters recvd statIndChn", log.Fields{"oltPortInfo": oltPortInfo}) |
| 3825 | case <-time.After(oltPortInfoTimeout * time.Second): |
| 3826 | logger.Debugw(ctx, "getOltPortCounters timeout happened", log.Fields{"oltPortInfo": oltPortInfo}) |
| 3827 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_TIMEOUT) |
| 3828 | case <-ctx.Done(): |
| 3829 | logger.Debugw(ctx, "getOltPortCounters ctx Done ", log.Fields{"oltPortInfo": oltPortInfo}) |
| 3830 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_TIMEOUT) |
| 3831 | } |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3832 | switch oltPortInfo.PortType { |
| 3833 | case extension.GetOltPortCounters_Port_ETHERNET_NNI: |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3834 | // get nni stats |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3835 | intfID := plt.PortNoToIntfID(oltPortInfo.PortNo, voltha.Port_ETHERNET_NNI) |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3836 | logger.Debugw(ctx, "getOltPortCounters intfID ", log.Fields{"intfID": intfID}) |
| 3837 | cmnni := dh.portStats.collectNNIMetrics(intfID) |
| 3838 | if cmnni == nil { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3839 | // TODO define the error reason |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3840 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 3841 | } |
| 3842 | dh.portStats.updateGetOltPortCountersResponse(ctx, &singleValResp, cmnni) |
| 3843 | return &singleValResp |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3844 | case extension.GetOltPortCounters_Port_PON_OLT: |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3845 | // get pon stats |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3846 | intfID := plt.PortNoToIntfID(oltPortInfo.PortNo, voltha.Port_PON_OLT) |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3847 | if val, ok := dh.activePorts.Load(intfID); ok && val == true { |
| 3848 | cmpon := dh.portStats.collectPONMetrics(intfID) |
| 3849 | if cmpon == nil { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3850 | // TODO define the error reason |
| kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3851 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 3852 | } |
| 3853 | dh.portStats.updateGetOltPortCountersResponse(ctx, &singleValResp, cmpon) |
| 3854 | return &singleValResp |
| 3855 | } |
| 3856 | } |
| 3857 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 3858 | } |
| Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 3859 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3860 | //nolint:unparam |
| Akash Soni | 3bcf5e0 | 2024-12-03 08:01:48 +0530 | [diff] [blame] | 3861 | func (dh *DeviceHandler) getOltOffloadStats(ctx context.Context, oltPortInfo *extension.GetOffloadedAppsStatisticsRequest) *extension.SingleGetValueResponse { |
| Akash Soni | 3bcf5e0 | 2024-12-03 08:01:48 +0530 | [diff] [blame] | 3862 | singleValResp := extension.SingleGetValueResponse{ |
| 3863 | Response: &extension.GetValueResponse{ |
| 3864 | Status: extension.GetValueResponse_OK, |
| 3865 | Response: &extension.GetValueResponse_OffloadedAppsStats{ |
| 3866 | OffloadedAppsStats: &extension.GetOffloadedAppsStatisticsResponse{}, |
| 3867 | }, |
| 3868 | }, |
| 3869 | } |
| 3870 | |
| 3871 | return &singleValResp |
| 3872 | } |
| 3873 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3874 | //nolint:unparam |
| Akash Soni | 3c75ad7 | 2024-12-23 12:09:48 +0530 | [diff] [blame] | 3875 | func (dh *DeviceHandler) setOltOffload(ctx context.Context, congig *extension.AppOffloadConfig) *extension.SingleSetValueResponse { |
| Akash Soni | 3c75ad7 | 2024-12-23 12:09:48 +0530 | [diff] [blame] | 3876 | singleValResp := extension.SingleSetValueResponse{ |
| 3877 | Response: &extension.SetValueResponse{ |
| 3878 | Status: extension.SetValueResponse_OK, |
| 3879 | }, |
| 3880 | } |
| 3881 | |
| 3882 | return &singleValResp |
| 3883 | } |
| 3884 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3885 | //nolint:unparam |
| Akash Soni | 3c75ad7 | 2024-12-23 12:09:48 +0530 | [diff] [blame] | 3886 | func (dh *DeviceHandler) setOnuOffload(ctx context.Context, config *extension.AppOffloadOnuConfig) *extension.SingleSetValueResponse { |
| Akash Soni | 3bcf5e0 | 2024-12-03 08:01:48 +0530 | [diff] [blame] | 3887 | singleValResp := extension.SingleSetValueResponse{ |
| 3888 | Response: &extension.SetValueResponse{ |
| 3889 | Status: extension.SetValueResponse_OK, |
| 3890 | }, |
| 3891 | } |
| 3892 | |
| 3893 | return &singleValResp |
| 3894 | } |
| 3895 | |
| Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 3896 | func (dh *DeviceHandler) getOnuPonCounters(ctx context.Context, onuPonInfo *extension.GetOnuCountersRequest) *extension.SingleGetValueResponse { |
| Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 3897 | singleValResp := extension.SingleGetValueResponse{ |
| 3898 | Response: &extension.GetValueResponse{ |
| 3899 | Response: &extension.GetValueResponse_OnuPonCounters{ |
| 3900 | OnuPonCounters: &extension.GetOnuCountersResponse{}, |
| 3901 | }, |
| 3902 | }, |
| 3903 | } |
| 3904 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3905 | errResp := func(status extension.GetValueResponse_Status, reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 3906 | return &extension.SingleGetValueResponse{ |
| 3907 | Response: &extension.GetValueResponse{ |
| 3908 | Status: status, |
| 3909 | ErrReason: reason, |
| 3910 | }, |
| 3911 | } |
| 3912 | } |
| 3913 | intfID := onuPonInfo.IntfId |
| 3914 | onuID := onuPonInfo.OnuId |
| 3915 | onuKey := dh.formOnuKey(intfID, onuID) |
| 3916 | |
| 3917 | if _, ok := dh.onus.Load(onuKey); !ok { |
| 3918 | logger.Errorw(ctx, "get-onui-pon-counters-request-invalid-request-received", log.Fields{"intfID": intfID, "onuID": onuID}) |
| 3919 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE) |
| 3920 | } |
| 3921 | logger.Debugw(ctx, "get-onui-pon-counters-request-received", log.Fields{"intfID": intfID, "onuID": onuID}) |
| 3922 | cmnni := dh.portStats.collectOnDemandOnuStats(ctx, intfID, onuID) |
| 3923 | if cmnni == nil { |
| 3924 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 3925 | } |
| 3926 | dh.portStats.updateGetOnuPonCountersResponse(ctx, &singleValResp, cmnni) |
| 3927 | return &singleValResp |
| Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 3928 | } |
| Gamze Abaka | 85e9a14 | 2021-05-26 13:41:39 +0000 | [diff] [blame] | 3929 | |
| Akash Reddy Kankanala | c6b6ca1 | 2025-06-12 14:26:57 +0530 | [diff] [blame] | 3930 | func (dh *DeviceHandler) CheckOnuGemInfo(ctx context.Context, intfID uint32, onuID uint32) (*rsrcMgr.OnuGemInfo, error) { |
| 3931 | onuGemInfo, err := dh.resourceMgr[intfID].GetOnuGemInfo(ctx, onuID) |
| 3932 | if err != nil { |
| 3933 | logger.Errorw(ctx, "Unable to find onuGemInfo", log.Fields{"onuID": onuID}) |
| 3934 | return nil, err |
| 3935 | } |
| 3936 | if onuGemInfo != nil { |
| 3937 | if len(onuGemInfo.UniPorts) == 0 { |
| 3938 | logger.Errorw(ctx, "No uniports present for the ONU", log.Fields{"onuID": onuID}) |
| 3939 | return nil, err |
| 3940 | } |
| 3941 | logger.Debugw(ctx, "Received onuGemInfo", log.Fields{"onuID": onuID, "onuGemInfo": onuGemInfo}) |
| 3942 | return onuGemInfo, nil |
| 3943 | } |
| 3944 | logger.Errorw(ctx, "Received nil onuGemInfo", log.Fields{"onuID": onuID}) |
| 3945 | return nil, fmt.Errorf("onuGemInfo received as null, onuID : %d", onuID) |
| 3946 | } |
| 3947 | |
| 3948 | func (dh *DeviceHandler) getAllocGemStats(ctx context.Context, intfID uint32, onuID uint32, onuGemInfo *rsrcMgr.OnuGemInfo, singleValResp *extension.SingleGetValueResponse) error { |
| 3949 | var err error |
| 3950 | var allocStats *oop.OnuAllocIdStatistics |
| 3951 | var onuGemStats *oop.GemPortStatistics |
| 3952 | for _, uni := range onuGemInfo.UniPorts { |
| 3953 | uniID := plt.UniIDFromPortNum(uni) |
| 3954 | uniPath := getUniPortPath(dh.device.Id, intfID, int32(onuID), int32(uniID)) |
| 3955 | tpIDs := dh.resourceMgr[intfID].GetTechProfileIDForOnu(ctx, onuID, uniID) |
| 3956 | if len(tpIDs) == 0 { |
| 3957 | logger.Errorw(ctx, "No TPIDs present for the Uni", log.Fields{"onuID": onuID, "uniPort": uni}) |
| 3958 | continue |
| 3959 | } |
| 3960 | for _, tpId := range tpIDs { |
| 3961 | tpPath := dh.flowMgr[intfID].getTPpath(ctx, uniPath, uint32(tpId)) |
| 3962 | techProfileInstance, _ := dh.flowMgr[intfID].techprofile.GetTPInstance(ctx, tpPath) |
| 3963 | onuStatsFromOlt := extension.OnuAllocGemStatsFromOltResponse{} |
| 3964 | if techProfileInstance != nil { |
| 3965 | switch tpInst := techProfileInstance.(type) { |
| 3966 | case *tp_pb.TechProfileInstance: |
| 3967 | allocId := tpInst.UsScheduler.AllocId |
| 3968 | onuAllocPkt := oop.OnuPacket{IntfId: intfID, OnuId: onuID, AllocId: allocId} |
| 3969 | allocStats, err = dh.Client.GetAllocIdStatistics(ctx, &onuAllocPkt) |
| 3970 | if err != nil { |
| 3971 | logger.Errorw(ctx, "Error received from openolt for GetAllocIdStatistics", log.Fields{"onuID": onuID, "AllodId": allocId, "Error": err}) |
| 3972 | return err |
| 3973 | } |
| 3974 | allocIdInfo := extension.OnuAllocIdInfoFromOlt{} |
| 3975 | allocIdInfo.AllocId = allocStats.AllocId |
| 3976 | allocIdInfo.RxBytes = allocStats.RxBytes |
| 3977 | |
| 3978 | onuStatsFromOlt.AllocIdInfo = &allocIdInfo |
| 3979 | |
| 3980 | gemPorts := tpInst.UpstreamGemPortAttributeList |
| 3981 | for _, gem := range gemPorts { |
| 3982 | onuGemPkt := oop.OnuPacket{IntfId: intfID, OnuId: onuID, GemportId: gem.GemportId} |
| 3983 | onuGemStats, err = dh.Client.GetGemPortStatistics(ctx, &onuGemPkt) |
| 3984 | if err != nil { |
| 3985 | logger.Errorw(ctx, "Error received from openolt for GetGemPortStatistics", log.Fields{"onuID": onuID, "GemPortId": gem.GemportId, "Error": err}) |
| 3986 | return err |
| 3987 | } |
| 3988 | gemStatsInfo := extension.OnuGemPortInfoFromOlt{} |
| 3989 | gemStatsInfo.GemId = onuGemStats.GemportId |
| 3990 | gemStatsInfo.RxBytes = onuGemStats.RxBytes |
| 3991 | gemStatsInfo.RxPackets = onuGemStats.RxPackets |
| 3992 | gemStatsInfo.TxBytes = onuGemStats.TxBytes |
| 3993 | gemStatsInfo.TxPackets = onuGemStats.TxPackets |
| 3994 | |
| 3995 | onuStatsFromOlt.GemPortInfo = append(onuStatsFromOlt.GemPortInfo, &gemStatsInfo) |
| 3996 | } |
| 3997 | singleValResp.Response.GetOnuStatsFromOltResponse().AllocGemStatsInfo = append(singleValResp.Response.GetOnuStatsFromOltResponse().AllocGemStatsInfo, &onuStatsFromOlt) |
| 3998 | |
| 3999 | default: |
| 4000 | logger.Errorw(ctx, "Invalid Techprofile type received", log.Fields{"onuID": onuID, "TpId": tpId}) |
| 4001 | return err |
| 4002 | } |
| 4003 | } else { |
| 4004 | logger.Errorw(ctx, "No TpInstance found for the TpID", log.Fields{"onuID": onuID, "TpId": tpId}) |
| 4005 | continue |
| 4006 | } |
| 4007 | } |
| 4008 | } |
| 4009 | return err |
| 4010 | } |
| 4011 | |
| 4012 | //nolint:unparam |
| 4013 | func (dh *DeviceHandler) getOnuStatsFromOlt(ctx context.Context, onuInfo *extension.GetOnuStatsFromOltRequest, onuDevice *voltha.Device) *extension.SingleGetValueResponse { |
| 4014 | singleValResp := extension.SingleGetValueResponse{ |
| 4015 | Response: &extension.GetValueResponse{ |
| 4016 | Status: extension.GetValueResponse_OK, |
| 4017 | Response: &extension.GetValueResponse_OnuStatsFromOltResponse{ |
| 4018 | OnuStatsFromOltResponse: &extension.GetOnuStatsFromOltResponse{}, |
| 4019 | }, |
| 4020 | }, |
| 4021 | } |
| 4022 | errResp := func(status extension.GetValueResponse_Status, |
| 4023 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 4024 | return &extension.SingleGetValueResponse{ |
| 4025 | Response: &extension.GetValueResponse{ |
| 4026 | Status: status, |
| 4027 | ErrReason: reason, |
| 4028 | }, |
| 4029 | } |
| 4030 | } |
| 4031 | |
| 4032 | var intfID, onuID uint32 |
| 4033 | if onuDevice != nil { |
| 4034 | onuID = onuDevice.ProxyAddress.OnuId |
| 4035 | intfID = plt.PortNoToIntfID(onuDevice.ParentPortNo, voltha.Port_PON_OLT) |
| 4036 | } |
| 4037 | |
| 4038 | onuKey := dh.formOnuKey(intfID, onuID) |
| 4039 | if _, ok := dh.onus.Load(onuKey); !ok { |
| 4040 | logger.Errorw(ctx, "getOnuStatsFromOlt request received for invalid device", log.Fields{"deviceId": onuDevice.Id, "intfID": intfID, "onuID": onuID}) |
| 4041 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE) |
| 4042 | } |
| 4043 | logger.Debugw(ctx, "getOnuStatsFromOlt request received", log.Fields{"intfID": intfID, "onuID": onuID}) |
| 4044 | |
| 4045 | onuGemInfo, err := dh.CheckOnuGemInfo(ctx, intfID, onuID) |
| 4046 | if err == nil { |
| 4047 | err = dh.getAllocGemStats(ctx, intfID, onuID, onuGemInfo, &singleValResp) |
| 4048 | if err != nil { |
| 4049 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 4050 | } |
| 4051 | } else { |
| 4052 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE) |
| 4053 | } |
| 4054 | return &singleValResp |
| 4055 | } |
| 4056 | |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 4057 | func (dh *DeviceHandler) getOnuInfo(ctx context.Context, intfID uint32, onuID *uint32) (*oop.OnuInfo, error) { |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 4058 | Onu := oop.Onu{IntfId: intfID, OnuId: *onuID} |
| 4059 | OnuInfo, err := dh.Client.GetOnuInfo(ctx, &Onu) |
| 4060 | if err != nil { |
| 4061 | return nil, err |
| 4062 | } |
| 4063 | return OnuInfo, nil |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | func (dh *DeviceHandler) getIntfInfo(ctx context.Context, intfID uint32) (*oop.PonIntfInfo, error) { |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 4067 | Intf := oop.Interface{IntfId: intfID} |
| 4068 | IntfInfo, err := dh.Client.GetPonInterfaceInfo(ctx, &Intf) |
| 4069 | if err != nil { |
| 4070 | return nil, err |
| 4071 | } |
| 4072 | return IntfInfo, nil |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 4073 | } |
| 4074 | |
| Gamze Abaka | 85e9a14 | 2021-05-26 13:41:39 +0000 | [diff] [blame] | 4075 | func (dh *DeviceHandler) getRxPower(ctx context.Context, rxPowerRequest *extension.GetRxPowerRequest) *extension.SingleGetValueResponse { |
| Gamze Abaka | 85e9a14 | 2021-05-26 13:41:39 +0000 | [diff] [blame] | 4076 | Onu := oop.Onu{IntfId: rxPowerRequest.IntfId, OnuId: rxPowerRequest.OnuId} |
| 4077 | rxPower, err := dh.Client.GetPonRxPower(ctx, &Onu) |
| 4078 | if err != nil { |
| 4079 | logger.Errorw(ctx, "error-while-getting-rx-power", log.Fields{"Onu": Onu, "err": err}) |
| 4080 | return generateSingleGetValueErrorResponse(err) |
| 4081 | } |
| 4082 | return &extension.SingleGetValueResponse{ |
| 4083 | Response: &extension.GetValueResponse{ |
| 4084 | Status: extension.GetValueResponse_OK, |
| 4085 | Response: &extension.GetValueResponse_RxPower{ |
| 4086 | RxPower: &extension.GetRxPowerResponse{ |
| 4087 | IntfId: rxPowerRequest.IntfId, |
| 4088 | OnuId: rxPowerRequest.OnuId, |
| 4089 | Status: rxPower.Status, |
| 4090 | FailReason: rxPower.FailReason.String(), |
| 4091 | RxPower: rxPower.RxPowerMeanDbm, |
| 4092 | }, |
| 4093 | }, |
| 4094 | }, |
| 4095 | } |
| 4096 | } |
| 4097 | |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4098 | func (dh *DeviceHandler) getPONRxPower(ctx context.Context, OltRxPowerRequest *extension.GetOltRxPowerRequest) *extension.SingleGetValueResponse { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 4099 | errResp := func(status extension.GetValueResponse_Status, reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4100 | return &extension.SingleGetValueResponse{ |
| 4101 | Response: &extension.GetValueResponse{ |
| 4102 | Status: status, |
| 4103 | ErrReason: reason, |
| 4104 | }, |
| 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | resp := extension.SingleGetValueResponse{ |
| 4109 | Response: &extension.GetValueResponse{ |
| 4110 | Status: extension.GetValueResponse_OK, |
| 4111 | Response: &extension.GetValueResponse_OltRxPower{ |
| 4112 | OltRxPower: &extension.GetOltRxPowerResponse{}, |
| 4113 | }, |
| 4114 | }, |
| 4115 | } |
| 4116 | |
| 4117 | logger.Debugw(ctx, "getPONRxPower", log.Fields{"portLabel": OltRxPowerRequest.PortLabel, "OnuSerialNumber": OltRxPowerRequest.OnuSn, "device-id": dh.device.Id}) |
| 4118 | portLabel := OltRxPowerRequest.PortLabel |
| 4119 | serialNumber := OltRxPowerRequest.OnuSn |
| 4120 | |
| 4121 | portInfo := strings.Split(portLabel, "-") |
| 4122 | portNumber, err := strconv.ParseUint(portInfo[1], 10, 32) |
| 4123 | |
| 4124 | if err != nil { |
| 4125 | logger.Errorw(ctx, "getPONRxPower invalid portNumber ", log.Fields{"oltPortNumber": portInfo[1]}) |
| 4126 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_REQ_TYPE) |
| 4127 | } |
| 4128 | |
| 4129 | if portInfo[0] != "pon" { |
| 4130 | logger.Errorw(ctx, "getPONRxPower invalid portType", log.Fields{"oltPortType": portInfo[0]}) |
| 4131 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_PORT_TYPE) |
| 4132 | } |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4133 | |
| 4134 | if serialNumber != "" { |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4135 | onuDev := dh.getChildDevice(ctx, serialNumber, (uint32)(portNumber)) |
| 4136 | if onuDev != nil { |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4137 | Onu := oop.Onu{IntfId: uint32(portNumber), OnuId: onuDev.onuID} |
| 4138 | rxPower, err := dh.Client.GetPonRxPower(ctx, &Onu) |
| 4139 | if err != nil { |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4140 | logger.Errorw(ctx, "error-while-getting-rx-power", log.Fields{"Onu": Onu, "err": err}) |
| 4141 | return generateSingleGetValueErrorResponse(err) |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4142 | } |
| 4143 | |
| 4144 | rxPowerValue := extension.RxPower{} |
| 4145 | rxPowerValue.OnuSn = onuDev.serialNumber |
| 4146 | rxPowerValue.Status = rxPower.GetStatus() |
| 4147 | rxPowerValue.RxPower = rxPower.GetRxPowerMeanDbm() |
| 4148 | rxPowerValue.FailReason = rxPower.GetFailReason().String() |
| 4149 | |
| 4150 | resp.Response.GetOltRxPower().RxPower = append(resp.Response.GetOltRxPower().RxPower, &rxPowerValue) |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4151 | } else { |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4152 | logger.Errorw(ctx, "getPONRxPower invalid Device", log.Fields{"portLabel": portLabel, "serialNumber": serialNumber}) |
| 4153 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE) |
| 4154 | } |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4155 | } else { |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4156 | dh.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool { |
| praneeth kumar nalmas | b234f23 | 2023-11-29 12:50:46 +0530 | [diff] [blame] | 4157 | if onuInCache.(*OnuDevice).intfID == (uint32)(portNumber) { |
| praneeth kumar nalmas | b234f23 | 2023-11-29 12:50:46 +0530 | [diff] [blame] | 4158 | Onu := oop.Onu{IntfId: (uint32)(portNumber), OnuId: onuInCache.(*OnuDevice).onuID} |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4159 | rxPower, err := dh.Client.GetPonRxPower(ctx, &Onu) |
| 4160 | if err != nil { |
| 4161 | logger.Errorw(ctx, "error-while-getting-rx-power, however considering to proceed further with other ONUs on PON", log.Fields{"Onu": Onu, "err": err}) |
| 4162 | } else { |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4163 | rxPowerValue := extension.RxPower{} |
| 4164 | rxPowerValue.OnuSn = onuInCache.(*OnuDevice).serialNumber |
| 4165 | rxPowerValue.Status = rxPower.GetStatus() |
| 4166 | rxPowerValue.RxPower = rxPower.GetRxPowerMeanDbm() |
| 4167 | rxPowerValue.FailReason = rxPower.GetFailReason().String() |
| 4168 | |
| 4169 | resp.Response.GetOltRxPower().RxPower = append(resp.Response.GetOltRxPower().RxPower, &rxPowerValue) |
| 4170 | } |
| praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 4171 | } |
| 4172 | logger.Infow(ctx, "getPONRxPower response ", log.Fields{"Response": resp}) |
| 4173 | return true |
| 4174 | }) |
| 4175 | } |
| 4176 | logger.Infow(ctx, "getPONRxPower response ", log.Fields{"Response": resp}) |
| 4177 | return &resp |
| 4178 | } |
| 4179 | |
| Akash Reddy Kankanala | d9ec482 | 2025-06-10 22:59:53 +0530 | [diff] [blame] | 4180 | func (dh *DeviceHandler) getPonPortStats(ctx context.Context, ponStatsRequest *extension.GetPonStatsRequest) *extension.SingleGetValueResponse { |
| 4181 | errResp := func(status extension.GetValueResponse_Status, |
| 4182 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 4183 | return &extension.SingleGetValueResponse{ |
| 4184 | Response: &extension.GetValueResponse{ |
| 4185 | Status: status, |
| 4186 | ErrReason: reason, |
| 4187 | }, |
| 4188 | } |
| 4189 | } |
| 4190 | |
| 4191 | resp := extension.SingleGetValueResponse{ |
| 4192 | Response: &extension.GetValueResponse{ |
| 4193 | Status: extension.GetValueResponse_OK, |
| 4194 | Response: &extension.GetValueResponse_OltPonStatsResponse{ |
| 4195 | OltPonStatsResponse: &extension.GetPonStatsResponse{}, |
| 4196 | }, |
| 4197 | }, |
| 4198 | } |
| 4199 | |
| 4200 | portLabel := ponStatsRequest.GetPortLabel() |
| 4201 | logger.Debugw(ctx, "getPonPortStats", log.Fields{"portLabel": portLabel, "device-id": dh.device.Id}) |
| 4202 | |
| 4203 | portInfo := strings.Split(portLabel, "-") |
| 4204 | portNumber, err := strconv.ParseUint(portInfo[1], 10, 32) |
| 4205 | |
| 4206 | if err != nil { |
| 4207 | logger.Errorw(ctx, "getPonPortStats invalid portNumber ", log.Fields{"oltPortNumber": portInfo[1]}) |
| 4208 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_REQ_TYPE) |
| 4209 | } |
| 4210 | |
| 4211 | if portInfo[0] != "pon" { |
| 4212 | logger.Errorw(ctx, "getPonPortStats invalid portType", log.Fields{"oltPortType": portInfo[0]}) |
| 4213 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_PORT_TYPE) |
| 4214 | } |
| 4215 | |
| 4216 | Interface := oop.Interface{IntfId: uint32(portNumber)} |
| 4217 | ponStats, err := dh.Client.GetPonPortStatistics(ctx, &Interface) |
| 4218 | if err != nil { |
| 4219 | logger.Errorw(ctx, "error-while-getting-pon-port-stats", log.Fields{"IntfId": portNumber, "err": err}) |
| 4220 | return generateSingleGetValueErrorResponse(err) |
| 4221 | } |
| 4222 | |
| 4223 | ponPortStats := resp.Response.GetOltPonStatsResponse() |
| 4224 | ponPortStats.PonPort = uint32(portNumber) |
| 4225 | ponPortStats.PortStatistics = ponStats |
| 4226 | |
| 4227 | logger.Infow(ctx, "getPonPortStats response ", log.Fields{"Response": resp}) |
| 4228 | return &resp |
| 4229 | } |
| 4230 | |
| 4231 | func (dh *DeviceHandler) getNniPortStats(ctx context.Context, nniStatsRequest *extension.GetNNIStatsRequest) *extension.SingleGetValueResponse { |
| 4232 | errResp := func(status extension.GetValueResponse_Status, |
| 4233 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 4234 | return &extension.SingleGetValueResponse{ |
| 4235 | Response: &extension.GetValueResponse{ |
| 4236 | Status: status, |
| 4237 | ErrReason: reason, |
| 4238 | }, |
| 4239 | } |
| 4240 | } |
| 4241 | |
| 4242 | resp := extension.SingleGetValueResponse{ |
| 4243 | Response: &extension.GetValueResponse{ |
| 4244 | Status: extension.GetValueResponse_OK, |
| 4245 | Response: &extension.GetValueResponse_OltNniStatsResponse{ |
| 4246 | OltNniStatsResponse: &extension.GetNNIStatsResponse{}, |
| 4247 | }, |
| 4248 | }, |
| 4249 | } |
| 4250 | |
| 4251 | portLabel := nniStatsRequest.GetPortLabel() |
| 4252 | logger.Debugw(ctx, "getNniPortStats", log.Fields{"portLabel": portLabel, "device-id": dh.device.Id}) |
| 4253 | |
| 4254 | portInfo := strings.Split(portLabel, "-") |
| 4255 | portNumber, err := strconv.ParseUint(portInfo[1], 10, 32) |
| 4256 | |
| 4257 | if err != nil { |
| 4258 | logger.Errorw(ctx, "getNniPortStats invalid portNumber ", log.Fields{"oltPortNumber": portInfo[1]}) |
| 4259 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_REQ_TYPE) |
| 4260 | } |
| 4261 | |
| 4262 | if portInfo[0] != "nni" { |
| 4263 | logger.Errorw(ctx, "getNniPortStats invalid portType", log.Fields{"oltPortType": portInfo[0]}) |
| 4264 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_PORT_TYPE) |
| 4265 | } |
| 4266 | |
| 4267 | Interface := oop.Interface{IntfId: uint32(portNumber)} |
| 4268 | nniStats, err := dh.Client.GetNniPortStatistics(ctx, &Interface) |
| 4269 | if err != nil { |
| 4270 | logger.Errorw(ctx, "error-while-getting-nni-port-stats", log.Fields{"PortNo": portNumber, "err": err}) |
| 4271 | return generateSingleGetValueErrorResponse(err) |
| 4272 | } |
| 4273 | |
| 4274 | nniPortStats := resp.Response.GetOltNniStatsResponse() |
| 4275 | nniPortStats.NniPort = uint32(portNumber) |
| 4276 | nniPortStats.PortStatistics = nniStats |
| 4277 | |
| 4278 | logger.Infow(ctx, "getNniPortStats response ", log.Fields{"Response": resp}) |
| 4279 | return &resp |
| 4280 | } |
| 4281 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 4282 | // nolint: unparam |
| Gamze Abaka | 85e9a14 | 2021-05-26 13:41:39 +0000 | [diff] [blame] | 4283 | func generateSingleGetValueErrorResponse(err error) *extension.SingleGetValueResponse { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 4284 | errResp := func(status extension.GetValueResponse_Status, reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| Gamze Abaka | 85e9a14 | 2021-05-26 13:41:39 +0000 | [diff] [blame] | 4285 | return &extension.SingleGetValueResponse{ |
| 4286 | Response: &extension.GetValueResponse{ |
| 4287 | Status: status, |
| 4288 | ErrReason: reason, |
| 4289 | }, |
| 4290 | } |
| 4291 | } |
| 4292 | |
| 4293 | if err != nil { |
| 4294 | if e, ok := status.FromError(err); ok { |
| 4295 | switch e.Code() { |
| 4296 | case codes.Internal: |
| 4297 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 4298 | case codes.DeadlineExceeded: |
| 4299 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_TIMEOUT) |
| 4300 | case codes.Unimplemented: |
| 4301 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_UNSUPPORTED) |
| 4302 | case codes.NotFound: |
| 4303 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE) |
| 4304 | } |
| 4305 | } |
| 4306 | } |
| 4307 | |
| 4308 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_REASON_UNDEFINED) |
| 4309 | } |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4310 | |
| 4311 | /* |
| 4312 | Helper functions to communicate with Core |
| 4313 | */ |
| 4314 | |
| 4315 | func (dh *DeviceHandler) getDeviceFromCore(ctx context.Context, deviceID string) (*voltha.Device, error) { |
| 4316 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4317 | if err != nil || cClient == nil { |
| 4318 | return nil, err |
| 4319 | } |
| 4320 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4321 | defer cancel() |
| 4322 | return cClient.GetDevice(subCtx, &common.ID{Id: deviceID}) |
| 4323 | } |
| 4324 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4325 | func (dh *DeviceHandler) getChildDeviceFromCore(ctx context.Context, childDeviceFilter *ca.ChildDeviceFilter) (*voltha.Device, error) { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4326 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4327 | if err != nil || cClient == nil { |
| 4328 | return nil, err |
| 4329 | } |
| 4330 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4331 | defer cancel() |
| 4332 | return cClient.GetChildDevice(subCtx, childDeviceFilter) |
| 4333 | } |
| 4334 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4335 | func (dh *DeviceHandler) updateDeviceStateInCore(ctx context.Context, deviceStateFilter *ca.DeviceStateFilter) error { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4336 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4337 | if err != nil || cClient == nil { |
| 4338 | return err |
| 4339 | } |
| 4340 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4341 | defer cancel() |
| 4342 | _, err = cClient.DeviceStateUpdate(subCtx, deviceStateFilter) |
| 4343 | return err |
| 4344 | } |
| 4345 | |
| 4346 | func (dh *DeviceHandler) getChildDevicesFromCore(ctx context.Context, deviceID string) (*voltha.Devices, error) { |
| 4347 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4348 | if err != nil || cClient == nil { |
| 4349 | return nil, err |
| 4350 | } |
| 4351 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4352 | defer cancel() |
| 4353 | return cClient.GetChildDevices(subCtx, &common.ID{Id: deviceID}) |
| 4354 | } |
| 4355 | |
| 4356 | func (dh *DeviceHandler) listDevicePortsFromCore(ctx context.Context, deviceID string) (*voltha.Ports, error) { |
| 4357 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4358 | if err != nil || cClient == nil { |
| 4359 | return nil, err |
| 4360 | } |
| 4361 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4362 | defer cancel() |
| 4363 | return cClient.ListDevicePorts(subCtx, &common.ID{Id: deviceID}) |
| 4364 | } |
| 4365 | |
| 4366 | func (dh *DeviceHandler) updateDeviceInCore(ctx context.Context, device *voltha.Device) error { |
| 4367 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4368 | if err != nil || cClient == nil { |
| 4369 | return err |
| 4370 | } |
| 4371 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4372 | defer cancel() |
| 4373 | _, err = cClient.DeviceUpdate(subCtx, device) |
| 4374 | return err |
| 4375 | } |
| 4376 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4377 | func (dh *DeviceHandler) sendChildDeviceDetectedToCore(ctx context.Context, deviceDiscoveryInfo *ca.DeviceDiscovery) (*voltha.Device, error) { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4378 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4379 | if err != nil || cClient == nil { |
| 4380 | return nil, err |
| 4381 | } |
| 4382 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4383 | defer cancel() |
| 4384 | return cClient.ChildDeviceDetected(subCtx, deviceDiscoveryInfo) |
| 4385 | } |
| 4386 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4387 | func (dh *DeviceHandler) sendPacketToCore(ctx context.Context, pkt *ca.PacketIn) error { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4388 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4389 | if err != nil || cClient == nil { |
| 4390 | return err |
| 4391 | } |
| 4392 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4393 | defer cancel() |
| 4394 | _, err = cClient.SendPacketIn(subCtx, pkt) |
| 4395 | return err |
| 4396 | } |
| 4397 | |
| 4398 | func (dh *DeviceHandler) createPortInCore(ctx context.Context, port *voltha.Port) error { |
| 4399 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4400 | if err != nil || cClient == nil { |
| 4401 | return err |
| 4402 | } |
| 4403 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4404 | defer cancel() |
| 4405 | _, err = cClient.PortCreated(subCtx, port) |
| 4406 | return err |
| 4407 | } |
| 4408 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4409 | func (dh *DeviceHandler) updatePortsStateInCore(ctx context.Context, portFilter *ca.PortStateFilter) error { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4410 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4411 | if err != nil || cClient == nil { |
| 4412 | return err |
| 4413 | } |
| 4414 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4415 | defer cancel() |
| 4416 | _, err = cClient.PortsStateUpdate(subCtx, portFilter) |
| 4417 | return err |
| 4418 | } |
| 4419 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4420 | func (dh *DeviceHandler) updatePortStateInCore(ctx context.Context, portState *ca.PortState) error { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4421 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4422 | if err != nil || cClient == nil { |
| 4423 | return err |
| 4424 | } |
| 4425 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4426 | defer cancel() |
| 4427 | _, err = cClient.PortStateUpdate(subCtx, portState) |
| 4428 | return err |
| 4429 | } |
| 4430 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4431 | func (dh *DeviceHandler) getPortFromCore(ctx context.Context, portFilter *ca.PortFilter) (*voltha.Port, error) { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4432 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4433 | if err != nil || cClient == nil { |
| 4434 | return nil, err |
| 4435 | } |
| 4436 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4437 | defer cancel() |
| 4438 | return cClient.GetDevicePort(subCtx, portFilter) |
| 4439 | } |
| 4440 | |
| nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 4441 | func (dh *DeviceHandler) getAllPortsFromCore(ctx context.Context, portFilter *ca.PortFilter) (*voltha.Ports, error) { |
| 4442 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4443 | if err != nil || cClient == nil { |
| 4444 | return nil, err |
| 4445 | } |
| 4446 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4447 | defer cancel() |
| 4448 | return cClient.GetPorts(subCtx, portFilter) |
| 4449 | } |
| 4450 | |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4451 | /* |
| 4452 | Helper functions to communicate with child adapter |
| 4453 | */ |
| 4454 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4455 | func (dh *DeviceHandler) sendOmciIndicationToChildAdapter(ctx context.Context, childEndpoint string, response *ia.OmciMessage) error { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4456 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 4457 | if err != nil || aClient == nil { |
| 4458 | return err |
| 4459 | } |
| 4460 | logger.Debugw(ctx, "sending-omci-response", log.Fields{"response": response, "child-endpoint": childEndpoint}) |
| 4461 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4462 | defer cancel() |
| 4463 | _, err = aClient.OmciIndication(subCtx, response) |
| 4464 | return err |
| 4465 | } |
| 4466 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4467 | func (dh *DeviceHandler) sendOnuIndicationToChildAdapter(ctx context.Context, childEndpoint string, onuInd *ia.OnuIndicationMessage) error { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4468 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 4469 | if err != nil || aClient == nil { |
| 4470 | return err |
| 4471 | } |
| 4472 | logger.Debugw(ctx, "sending-onu-indication", log.Fields{"onu-indication": onuInd, "child-endpoint": childEndpoint}) |
| 4473 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4474 | defer cancel() |
| 4475 | _, err = aClient.OnuIndication(subCtx, onuInd) |
| 4476 | return err |
| 4477 | } |
| 4478 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4479 | func (dh *DeviceHandler) sendDeleteTContToChildAdapter(ctx context.Context, childEndpoint string, tContInfo *ia.DeleteTcontMessage) error { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4480 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 4481 | if err != nil || aClient == nil { |
| 4482 | return err |
| 4483 | } |
| 4484 | logger.Debugw(ctx, "sending-delete-tcont", log.Fields{"tcont": tContInfo, "child-endpoint": childEndpoint}) |
| 4485 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4486 | defer cancel() |
| 4487 | _, err = aClient.DeleteTCont(subCtx, tContInfo) |
| 4488 | return err |
| 4489 | } |
| 4490 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4491 | func (dh *DeviceHandler) sendDeleteGemPortToChildAdapter(ctx context.Context, childEndpoint string, gemPortInfo *ia.DeleteGemPortMessage) error { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4492 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 4493 | if err != nil || aClient == nil { |
| 4494 | return err |
| 4495 | } |
| 4496 | logger.Debugw(ctx, "sending-delete-gem-port", log.Fields{"gem-port-info": gemPortInfo, "child-endpoint": childEndpoint}) |
| 4497 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4498 | defer cancel() |
| 4499 | _, err = aClient.DeleteGemPort(subCtx, gemPortInfo) |
| 4500 | return err |
| 4501 | } |
| 4502 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4503 | func (dh *DeviceHandler) sendDownloadTechProfileToChildAdapter(ctx context.Context, childEndpoint string, tpDownloadInfo *ia.TechProfileDownloadMessage) error { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4504 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 4505 | if err != nil || aClient == nil { |
| 4506 | return err |
| 4507 | } |
| 4508 | logger.Debugw(ctx, "sending-tech-profile-download", log.Fields{"tp-download-info": tpDownloadInfo, "child-endpoint": childEndpoint}) |
| 4509 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4510 | defer cancel() |
| 4511 | _, err = aClient.DownloadTechProfile(subCtx, tpDownloadInfo) |
| 4512 | return err |
| 4513 | } |
| 4514 | |
| 4515 | /* |
| 4516 | Helper functions for remote communication |
| 4517 | */ |
| 4518 | |
| 4519 | // TODO: Use a connection tracker such that the adapter connection is stopped when the last device that adapter |
| 4520 | // supports is deleted |
| 4521 | func (dh *DeviceHandler) setupChildInterAdapterClient(ctx context.Context, endpoint string) error { |
| 4522 | logger.Infow(ctx, "setting-child-adapter-connection", log.Fields{"child-endpoint": endpoint}) |
| 4523 | |
| 4524 | dh.lockChildAdapterClients.Lock() |
| 4525 | defer dh.lockChildAdapterClients.Unlock() |
| 4526 | if _, ok := dh.childAdapterClients[endpoint]; ok { |
| 4527 | // Already set |
| 4528 | return nil |
| 4529 | } |
| 4530 | |
| 4531 | // Setup child's adapter grpc connection |
| 4532 | var err error |
| khenaidoo | 27e7ac9 | 2021-12-08 14:43:09 -0500 | [diff] [blame] | 4533 | if dh.childAdapterClients[endpoint], err = vgrpc.NewClient( |
| 4534 | dh.cfg.AdapterEndpoint, |
| 4535 | endpoint, |
| khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 4536 | "onu_inter_adapter_service.OnuInterAdapterService", |
| 4537 | dh.onuInterAdapterRestarted, |
| 4538 | vgrpc.ClientContextData(dh.device.Id)); err != nil { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4539 | logger.Errorw(ctx, "grpc-client-not-created", log.Fields{"error": err, "endpoint": endpoint}) |
| 4540 | return err |
| 4541 | } |
| nikesh.krishnan | d981254 | 2023-08-01 18:31:39 +0530 | [diff] [blame] | 4542 | retryCodes := []codes.Code{ |
| 4543 | codes.Unavailable, // server is currently unavailable |
| 4544 | codes.DeadlineExceeded, // deadline for the operation was exceeded |
| 4545 | } |
| 4546 | backoffCtxOption := grpc_retry.WithBackoff(grpc_retry.BackoffLinearWithJitter(dh.cfg.PerRPCRetryTimeout, 0.2)) |
| 4547 | grpcRetryOptions := grpc_retry.UnaryClientInterceptor(grpc_retry.WithMax(dh.cfg.MaxRetries), grpc_retry.WithPerRetryTimeout(dh.cfg.PerRPCRetryTimeout), grpc_retry.WithCodes(retryCodes...), backoffCtxOption) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4548 | |
| nikesh.krishnan | d981254 | 2023-08-01 18:31:39 +0530 | [diff] [blame] | 4549 | go dh.childAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), dh.getOnuInterAdapterServiceClientHandler, grpcRetryOptions) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4550 | // Wait until we have a connection to the child adapter. |
| 4551 | // Unlimited retries or until context expires |
| 4552 | subCtx := log.WithSpanFromContext(context.TODO(), ctx) |
| 4553 | backoff := vgrpc.NewBackoff(dh.cfg.MinBackoffRetryDelay, dh.cfg.MaxBackoffRetryDelay, 0) |
| 4554 | for { |
| 4555 | client, err := dh.childAdapterClients[endpoint].GetOnuInterAdapterServiceClient() |
| 4556 | if err == nil && client != nil { |
| 4557 | logger.Infow(subCtx, "connected-to-child-adapter", log.Fields{"child-endpoint": endpoint}) |
| 4558 | break |
| 4559 | } |
| 4560 | logger.Warnw(subCtx, "connection-to-child-adapter-not-ready", log.Fields{"error": err, "child-endpoint": endpoint}) |
| 4561 | // Backoff |
| 4562 | if err = backoff.Backoff(subCtx); err != nil { |
| 4563 | logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "child-endpoint": endpoint}) |
| 4564 | break |
| 4565 | } |
| 4566 | } |
| 4567 | return nil |
| 4568 | } |
| 4569 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4570 | func (dh *DeviceHandler) getChildAdapterServiceClient(endpoint string) (onu_inter_adapter_service.OnuInterAdapterServiceClient, error) { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4571 | // First check from cache |
| 4572 | dh.lockChildAdapterClients.RLock() |
| 4573 | if cgClient, ok := dh.childAdapterClients[endpoint]; ok { |
| 4574 | dh.lockChildAdapterClients.RUnlock() |
| 4575 | return cgClient.GetOnuInterAdapterServiceClient() |
| 4576 | } |
| 4577 | dh.lockChildAdapterClients.RUnlock() |
| 4578 | |
| 4579 | // Set the child connection - can occur on restarts |
| 4580 | ctx, cancel := context.WithTimeout(context.Background(), dh.cfg.RPCTimeout) |
| 4581 | err := dh.setupChildInterAdapterClient(ctx, endpoint) |
| 4582 | cancel() |
| 4583 | if err != nil { |
| 4584 | return nil, err |
| 4585 | } |
| 4586 | |
| 4587 | // Get the child client now |
| 4588 | dh.lockChildAdapterClients.RLock() |
| 4589 | defer dh.lockChildAdapterClients.RUnlock() |
| 4590 | if cgClient, ok := dh.childAdapterClients[endpoint]; ok { |
| 4591 | return cgClient.GetOnuInterAdapterServiceClient() |
| 4592 | } |
| 4593 | return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint) |
| 4594 | } |
| 4595 | |
| 4596 | func (dh *DeviceHandler) deleteAdapterClients(ctx context.Context) { |
| 4597 | dh.lockChildAdapterClients.Lock() |
| 4598 | defer dh.lockChildAdapterClients.Unlock() |
| 4599 | for key, client := range dh.childAdapterClients { |
| 4600 | client.Stop(ctx) |
| 4601 | delete(dh.childAdapterClients, key) |
| 4602 | } |
| 4603 | } |
| 4604 | |
| khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 4605 | // TODO: Any action the adapter needs to do following a onu adapter inter adapter service restart? |
| 4606 | func (dh *DeviceHandler) onuInterAdapterRestarted(ctx context.Context, endPoint string) error { |
| 4607 | logger.Warnw(ctx, "onu-inter-adapter-service-reconnected", log.Fields{"endpoint": endPoint}) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4608 | return nil |
| 4609 | } |
| 4610 | |
| khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 4611 | // getOnuInterAdapterServiceClientHandler is used to setup the remote gRPC service |
| 4612 | func (dh *DeviceHandler) getOnuInterAdapterServiceClientHandler(ctx context.Context, conn *grpc.ClientConn) interface{} { |
| 4613 | if conn == nil { |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4614 | return nil |
| 4615 | } |
| khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 4616 | return onu_inter_adapter_service.NewOnuInterAdapterServiceClient(conn) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4617 | } |
| Girish Gowdra | 950326e | 2021-11-05 12:43:24 -0700 | [diff] [blame] | 4618 | |
| 4619 | func (dh *DeviceHandler) setDeviceDeletionInProgressFlag(flag bool) { |
| 4620 | dh.lockDevice.Lock() |
| 4621 | defer dh.lockDevice.Unlock() |
| 4622 | dh.isDeviceDeletionInProgress = flag |
| 4623 | } |
| 4624 | |
| 4625 | func (dh *DeviceHandler) getDeviceDeletionInProgressFlag() bool { |
| 4626 | dh.lockDevice.RLock() |
| 4627 | defer dh.lockDevice.RUnlock() |
| 4628 | return dh.isDeviceDeletionInProgress |
| 4629 | } |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 4630 | |
| 4631 | // waitForTimeoutOrCompletion waits for the waitgroup for the specified max timeout. |
| 4632 | // Returns false if waiting timed out. |
| 4633 | func (dh *DeviceHandler) waitForTimeoutOrCompletion(wg *sync.WaitGroup, timeout time.Duration) bool { |
| 4634 | c := make(chan struct{}) |
| 4635 | go func() { |
| 4636 | defer close(c) |
| 4637 | wg.Wait() |
| 4638 | }() |
| 4639 | select { |
| 4640 | case <-c: |
| 4641 | return true // completed normally |
| 4642 | case <-time.After(timeout): |
| 4643 | return false // timed out |
| 4644 | } |
| 4645 | } |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 4646 | |
| 4647 | func (dh *DeviceHandler) updateHeartbeatSignature(ctx context.Context, signature uint32) { |
| 4648 | val, err := json.Marshal(signature) |
| 4649 | if err != nil { |
| 4650 | logger.Error(ctx, "failed-to-marshal") |
| 4651 | return |
| 4652 | } |
| 4653 | if err = dh.kvStore.Put(ctx, heartbeatPath, val); err != nil { |
| 4654 | logger.Error(ctx, "failed-to-store-hearbeat-signature") |
| 4655 | } |
| 4656 | } |
| 4657 | |
| 4658 | func (dh *DeviceHandler) getHeartbeatSignature(ctx context.Context) uint32 { |
| 4659 | var signature uint32 |
| 4660 | |
| 4661 | Value, er := dh.kvStore.Get(ctx, heartbeatPath) |
| 4662 | if er == nil { |
| 4663 | if Value != nil { |
| 4664 | Val, er := kvstore.ToByte(Value.Value) |
| 4665 | if er != nil { |
| 4666 | logger.Errorw(ctx, "Failed to convert into byte array", log.Fields{"err": er}) |
| 4667 | return signature |
| 4668 | } |
| 4669 | if er = json.Unmarshal(Val, &signature); er != nil { |
| 4670 | logger.Error(ctx, "Failed to unmarshal signature", log.Fields{"err": er}) |
| 4671 | return signature |
| 4672 | } |
| 4673 | } |
| 4674 | } |
| 4675 | return signature |
| 4676 | } |