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" |
| 60 | "github.com/opencord/voltha-protos/v5/go/voltha" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 61 | "google.golang.org/grpc" |
nikesh.krishnan | d981254 | 2023-08-01 18:31:39 +0530 | [diff] [blame] | 62 | codes "google.golang.org/grpc/codes" |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 63 | "google.golang.org/grpc/status" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 64 | ) |
| 65 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 66 | // Constants for number of retries and for timeout |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 67 | const ( |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 68 | InvalidPort = 0xffffffff |
| 69 | MaxNumOfGroupHandlerChannels = 256 |
| 70 | |
| 71 | McastFlowOrGroupAdd = "McastFlowOrGroupAdd" |
| 72 | McastFlowOrGroupModify = "McastFlowOrGroupModify" |
| 73 | McastFlowOrGroupRemove = "McastFlowOrGroupRemove" |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 74 | oltPortInfoTimeout = 3 |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 75 | |
| 76 | defaultPortSpeedMbps = 1000 |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 77 | heartbeatPath = "heartbeat" |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 78 | ) |
| 79 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 80 | // DeviceHandler will interact with the OLT device. |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 81 | type DeviceHandler struct { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 82 | cm *config.ConfigManager |
| 83 | device *voltha.Device |
| 84 | cfg *conf.AdapterFlags |
| 85 | coreClient *vgrpc.Client |
| 86 | childAdapterClients map[string]*vgrpc.Client |
| 87 | lockChildAdapterClients sync.RWMutex |
| 88 | EventProxy eventif.EventProxy |
| 89 | openOLT *OpenOLT |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 90 | exitChannel chan struct{} |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 91 | lockDevice sync.RWMutex |
| 92 | Client oop.OpenoltClient |
| 93 | transitionMap *TransitionMap |
| 94 | clientCon *grpc.ClientConn |
| 95 | flowMgr []*OpenOltFlowMgr |
| 96 | groupMgr *OpenOltGroupMgr |
| 97 | eventMgr *OpenOltEventMgr |
| 98 | resourceMgr []*rsrcMgr.OpenOltResourceMgr |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 99 | kvStore *db.Backend // backend kv store connection handle |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 100 | |
| 101 | deviceInfo *oop.DeviceInfo |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 102 | |
Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 103 | // discOnus (map[onuSn]bool) contains a list of ONUs that have been discovered, indexed by ONU SerialNumber. |
| 104 | // if the value is true that means the OnuDiscovery indication |
| 105 | // is currently being processed and thus we can ignore concurrent requests |
| 106 | // if it's false it means the processing has completed and we shouldn't be receiving a new indication |
| 107 | // if we do it means something went wrong and we need to retry |
Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 108 | discOnus sync.Map |
| 109 | onus sync.Map |
| 110 | portStats *OpenOltStatisticsMgr |
| 111 | metrics *pmmetrics.PmMetrics |
| 112 | stopCollector chan bool |
Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 113 | isCollectorActive bool |
Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 114 | stopHeartbeatCheck chan bool |
Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 115 | isHeartbeatCheckActive bool |
Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 116 | activePorts sync.Map |
| 117 | stopIndications chan bool |
| 118 | isReadIndicationRoutineActive bool |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 119 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 120 | totalPonPorts uint32 |
| 121 | perPonOnuIndicationChannel map[uint32]onuIndicationChannels |
| 122 | perPonOnuIndicationChannelLock sync.Mutex |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 123 | |
| 124 | // Slice of channels. Each channel in slice, index by (mcast-group-id modulo MaxNumOfGroupHandlerChannels) |
| 125 | // 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] | 126 | incomingMcastFlowOrGroup []chan McastFlowOrGroupControlBlock |
| 127 | stopMcastHandlerRoutine []chan bool |
| 128 | mcastHandlerRoutineActive []bool |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 129 | |
| 130 | adapterPreviouslyConnected bool |
| 131 | agentPreviouslyConnected bool |
Girish Gowdra | 950326e | 2021-11-05 12:43:24 -0700 | [diff] [blame] | 132 | |
| 133 | isDeviceDeletionInProgress bool |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 134 | heartbeatSignature uint32 |
Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 135 | prevOperStatus common.OperStatus_Types |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 138 | // OnuDevice represents ONU related info |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 139 | type OnuDevice struct { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 140 | deviceID string |
| 141 | deviceType string |
| 142 | serialNumber string |
| 143 | onuID uint32 |
| 144 | intfID uint32 |
| 145 | proxyDeviceID string |
| 146 | losRaised bool |
| 147 | rdiRaised bool |
| 148 | adapterEndpoint string |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 151 | type onuIndicationMsg struct { |
| 152 | ctx context.Context |
| 153 | indication *oop.Indication |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | type onuIndicationChannels struct { |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 157 | indicationChannel chan onuIndicationMsg |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 158 | stopChannel chan struct{} |
| 159 | } |
| 160 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 161 | // McastFlowOrGroupControlBlock is created per mcast flow/group add/modify/remove and pushed on the incomingMcastFlowOrGroup channel slice |
| 162 | // The McastFlowOrGroupControlBlock is then picked by the mcastFlowOrGroupChannelHandlerRoutine for further processing. |
| 163 | // There are MaxNumOfGroupHandlerChannels number of mcastFlowOrGroupChannelHandlerRoutine routines which monitor for any incoming mcast flow/group messages |
| 164 | // 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] | 165 | type McastFlowOrGroupControlBlock struct { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 166 | ctx context.Context // Flow/group handler context |
| 167 | flowOrGroupAction string // one of McastFlowOrGroupAdd, McastFlowOrGroupModify or McastFlowOrGroupDelete |
| 168 | flow *of.OfpFlowStats // Flow message (can be nil or valid flow) |
| 169 | group *of.OfpGroupEntry // Group message (can be nil or valid group) |
| 170 | errChan *chan error // channel to report the mcast Flow/group handling error |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 173 | var pmNames = []string{ |
| 174 | "rx_bytes", |
| 175 | "rx_packets", |
| 176 | "rx_mcast_packets", |
| 177 | "rx_bcast_packets", |
| 178 | "tx_bytes", |
| 179 | "tx_packets", |
| 180 | "tx_mcast_packets", |
| 181 | "tx_bcast_packets", |
| 182 | } |
| 183 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 184 | // NewOnuDevice creates a new Onu Device |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 185 | 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] | 186 | var device OnuDevice |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 187 | device.deviceID = devID |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 188 | device.deviceType = deviceTp |
| 189 | device.serialNumber = serialNum |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 190 | device.onuID = onuID |
| 191 | device.intfID = intfID |
| 192 | device.proxyDeviceID = proxyDevID |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 193 | device.losRaised = losRaised |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 194 | device.adapterEndpoint = adapterEndpoint |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 195 | return &device |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 196 | } |
| 197 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 198 | // NewDeviceHandler creates a new device handler |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 199 | 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] | 200 | var dh DeviceHandler |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 201 | ctx := context.Background() |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 202 | dh.cm = cm |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 203 | dh.coreClient = cc |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 204 | dh.EventProxy = ep |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 205 | cloned := (proto.Clone(device)).(*voltha.Device) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 206 | dh.device = cloned |
| 207 | dh.openOLT = adapter |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 208 | dh.exitChannel = make(chan struct{}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 209 | dh.lockDevice = sync.RWMutex{} |
Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 210 | dh.stopCollector = make(chan bool, 1) // TODO: Why buffered? |
| 211 | dh.stopHeartbeatCheck = make(chan bool, 1) // TODO: Why buffered? |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 212 | 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] | 213 | dh.activePorts = sync.Map{} |
Girish Gowdra | ae56c72 | 2021-11-22 14:31:11 -0800 | [diff] [blame] | 214 | dh.stopIndications = make(chan bool, 1) // TODO: Why buffered? |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 215 | dh.perPonOnuIndicationChannel = make(map[uint32]onuIndicationChannels) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 216 | dh.childAdapterClients = make(map[string]*vgrpc.Client) |
| 217 | dh.cfg = cfg |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 218 | 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] | 219 | if dh.kvStore == nil { |
| 220 | logger.Error(ctx, "Failed to setup KV store") |
| 221 | return nil |
| 222 | } |
| 223 | |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 224 | // Create a slice of buffered channels for handling concurrent mcast flow/group. |
| 225 | dh.incomingMcastFlowOrGroup = make([]chan McastFlowOrGroupControlBlock, MaxNumOfGroupHandlerChannels) |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 226 | dh.stopMcastHandlerRoutine = make([]chan bool, MaxNumOfGroupHandlerChannels) |
| 227 | dh.mcastHandlerRoutineActive = make([]bool, MaxNumOfGroupHandlerChannels) |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 228 | for i := range dh.incomingMcastFlowOrGroup { |
| 229 | dh.incomingMcastFlowOrGroup[i] = make(chan McastFlowOrGroupControlBlock, MaxNumOfGroupHandlerChannels) |
Girish Gowdra | ae56c72 | 2021-11-22 14:31:11 -0800 | [diff] [blame] | 230 | dh.stopMcastHandlerRoutine[i] = make(chan bool) |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 231 | // Spin up a go routine to handling incoming mcast flow/group (add/modify/remove). |
| 232 | // There will be MaxNumOfGroupHandlerChannels number of mcastFlowOrGroupChannelHandlerRoutine go routines. |
| 233 | // These routines will be blocked on the dh.incomingMcastFlowOrGroup[mcast-group-id modulo MaxNumOfGroupHandlerChannels] channel |
| 234 | // for incoming mcast flow/group to be processed serially. |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 235 | dh.mcastHandlerRoutineActive[i] = true |
| 236 | go dh.mcastFlowOrGroupChannelHandlerRoutine(i, dh.incomingMcastFlowOrGroup[i], dh.stopMcastHandlerRoutine[i]) |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 237 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 238 | //TODO initialize the support classes. |
| 239 | return &dh |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 240 | } |
| 241 | |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 242 | func newKVClient(ctx context.Context, storeType string, address string, timeout time.Duration) (kvstore.Client, error) { |
| 243 | logger.Infow(ctx, "kv-store-type", log.Fields{"store": storeType}) |
| 244 | switch storeType { |
| 245 | case "etcd": |
| 246 | return kvstore.NewEtcdClient(ctx, address, timeout, log.FatalLevel) |
Abhay Kumar | 9bcfeb2 | 2024-07-12 09:14:25 +0530 | [diff] [blame] | 247 | case "redis": |
| 248 | return kvstore.NewRedisClient(address, timeout, false) |
| 249 | case "redis-sentinel": |
| 250 | return kvstore.NewRedisClient(address, timeout, true) |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 251 | } |
| 252 | return nil, errors.New("unsupported-kv-store") |
| 253 | } |
| 254 | |
| 255 | // SetKVClient sets the KV client and return a kv backend |
| 256 | func SetKVClient(ctx context.Context, backend string, addr string, DeviceID string, basePathKvStore string) *db.Backend { |
| 257 | kvClient, err := newKVClient(ctx, backend, addr, rsrcMgr.KvstoreTimeout) |
| 258 | if err != nil { |
| 259 | logger.Fatalw(ctx, "Failed to init KV client\n", log.Fields{"err": err}) |
| 260 | return nil |
| 261 | } |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 262 | kvbackend := &db.Backend{ |
| 263 | Client: kvClient, |
| 264 | StoreType: backend, |
| 265 | Address: addr, |
| 266 | Timeout: rsrcMgr.KvstoreTimeout, |
| 267 | PathPrefix: fmt.Sprintf(rsrcMgr.BasePathKvStore, basePathKvStore, DeviceID)} |
| 268 | |
| 269 | return kvbackend |
| 270 | } |
| 271 | |
Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 272 | // CloseKVClient closes open KV clients |
| 273 | func (dh *DeviceHandler) CloseKVClient(ctx context.Context) { |
| 274 | if dh.resourceMgr != nil { |
| 275 | for _, rscMgr := range dh.resourceMgr { |
| 276 | if rscMgr != nil { |
| 277 | rscMgr.CloseKVClient(ctx) |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | if dh.flowMgr != nil { |
| 282 | for _, flMgr := range dh.flowMgr { |
| 283 | if flMgr != nil { |
| 284 | flMgr.CloseKVClient(ctx) |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 290 | // start save the device to the data model |
| 291 | func (dh *DeviceHandler) start(ctx context.Context) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 292 | dh.lockDevice.Lock() |
| 293 | defer dh.lockDevice.Unlock() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 294 | logger.Debugw(ctx, "starting-device-agent", log.Fields{"device": dh.device}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 295 | // Add the initial device to the local model |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 296 | logger.Debug(ctx, "device-agent-started") |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 297 | } |
| 298 | |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 299 | // Stop stops the device handler |
| 300 | func (dh *DeviceHandler) Stop(ctx context.Context) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 301 | dh.lockDevice.Lock() |
| 302 | defer dh.lockDevice.Unlock() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 303 | logger.Debug(ctx, "stopping-device-agent") |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 304 | close(dh.exitChannel) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 305 | |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 306 | // Delete (which will stop also) all grpc connections to the child adapters |
| 307 | dh.deleteAdapterClients(ctx) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 308 | logger.Debug(ctx, "device-agent-stopped") |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 309 | } |
| 310 | |
ssiddiqui | 04386ee | 2021-08-23 21:58:25 +0530 | [diff] [blame] | 311 | func (dh *DeviceHandler) getPonTechnology(intfID uint32) string { |
| 312 | for _, resourceRanges := range dh.deviceInfo.GetRanges() { |
| 313 | for _, pooledIntfID := range resourceRanges.GetIntfIds() { |
| 314 | if pooledIntfID == intfID { |
| 315 | return resourceRanges.GetTechnology() |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | return "" |
| 320 | } |
| 321 | |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 322 | func macifyIP(ip net.IP) string { |
| 323 | if len(ip) > 0 { |
| 324 | oct1 := strconv.FormatInt(int64(ip[12]), 16) |
| 325 | oct2 := strconv.FormatInt(int64(ip[13]), 16) |
| 326 | oct3 := strconv.FormatInt(int64(ip[14]), 16) |
| 327 | oct4 := strconv.FormatInt(int64(ip[15]), 16) |
| 328 | return fmt.Sprintf("00:00:%02v:%02v:%02v:%02v", oct1, oct2, oct3, oct4) |
| 329 | } |
| 330 | return "" |
| 331 | } |
| 332 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 333 | func generateMacFromHost(ctx context.Context, host string) (string, error) { |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 334 | var genmac string |
| 335 | var addr net.IP |
| 336 | var ips []string |
| 337 | var err error |
| 338 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 339 | logger.Debugw(ctx, "generating-mac-from-host", log.Fields{"host": host}) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 340 | |
| 341 | if addr = net.ParseIP(host); addr == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 342 | logger.Debugw(ctx, "looking-up-hostname", log.Fields{"host": host}) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 343 | |
| 344 | if ips, err = net.LookupHost(host); err == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 345 | logger.Debugw(ctx, "dns-result-ips", log.Fields{"ips": ips}) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 346 | if addr = net.ParseIP(ips[0]); addr == nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 347 | return "", olterrors.NewErrInvalidValue(log.Fields{"ip": ips[0]}, nil) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 348 | } |
| 349 | genmac = macifyIP(addr) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 350 | logger.Debugw(ctx, "using-ip-as-mac", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 351 | log.Fields{"host": ips[0], |
| 352 | "mac": genmac}) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 353 | return genmac, nil |
| 354 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 355 | 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] | 356 | } |
| 357 | |
| 358 | genmac = macifyIP(addr) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 359 | logger.Debugw(ctx, "using-ip-as-mac", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 360 | log.Fields{"host": host, |
| 361 | "mac": genmac}) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 362 | return genmac, nil |
| 363 | } |
| 364 | |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 365 | func macAddressToUint32Array(mac string) []uint32 { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 366 | slist := strings.Split(mac, ":") |
| 367 | result := make([]uint32, len(slist)) |
| 368 | var err error |
| 369 | var tmp int64 |
| 370 | for index, val := range slist { |
| 371 | if tmp, err = strconv.ParseInt(val, 16, 32); err != nil { |
| 372 | return []uint32{1, 2, 3, 4, 5, 6} |
| 373 | } |
| 374 | result[index] = uint32(tmp) |
| 375 | } |
| 376 | return result |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 377 | } |
| 378 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 379 | // 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] | 380 | func GetportLabel(portNum uint32, portType voltha.Port_PortType) (string, error) { |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 381 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 382 | switch portType { |
| 383 | case voltha.Port_ETHERNET_NNI: |
| 384 | return fmt.Sprintf("nni-%d", portNum), nil |
| 385 | case voltha.Port_PON_OLT: |
| 386 | return fmt.Sprintf("pon-%d", portNum), nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 387 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 388 | |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 389 | return "", olterrors.NewErrInvalidValue(log.Fields{"port-type": portType}, nil) |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 390 | } |
| 391 | |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 392 | func makeOfpPort(macAddress string, speedMbps uint32) *of.OfpPort { |
| 393 | if speedMbps == 0 { |
| 394 | //In case it was not set in the indication |
| 395 | //and no other value was provided |
| 396 | speedMbps = defaultPortSpeedMbps |
| 397 | } |
| 398 | |
| 399 | ofpPortSpeed := of.OfpPortFeatures_OFPPF_OTHER |
| 400 | switch speedMbps { |
| 401 | case 1000000: |
| 402 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_1TB_FD |
| 403 | case 100000: |
| 404 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_100GB_FD |
| 405 | case 40000: |
| 406 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_40GB_FD |
| 407 | case 10000: |
| 408 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_10GB_FD |
| 409 | case 1000: |
| 410 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_1GB_FD |
| 411 | case 100: |
| 412 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_100MB_FD |
| 413 | case 10: |
| 414 | ofpPortSpeed = of.OfpPortFeatures_OFPPF_10MB_FD |
| 415 | } |
| 416 | |
| 417 | capacity := uint32(ofpPortSpeed | of.OfpPortFeatures_OFPPF_FIBER) |
| 418 | |
| 419 | port := &of.OfpPort{ |
| 420 | HwAddr: macAddressToUint32Array(macAddress), |
| 421 | Config: 0, |
| 422 | State: uint32(of.OfpPortState_OFPPS_LIVE), |
| 423 | Curr: capacity, |
| 424 | Advertised: capacity, |
| 425 | Peer: capacity, |
| 426 | CurrSpeed: speedMbps * 1000, //kbps |
| 427 | MaxSpeed: speedMbps * 1000, //kbps |
| 428 | } |
| 429 | |
| 430 | return port |
| 431 | } |
| 432 | |
| 433 | 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] | 434 | var operStatus common.OperStatus_Types |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 435 | if state == "up" { |
| 436 | operStatus = voltha.OperStatus_ACTIVE |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 437 | //populating the intfStatus map |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 438 | dh.activePorts.Store(intfID, true) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 439 | } else { |
| 440 | operStatus = voltha.OperStatus_DISCOVERED |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 441 | dh.activePorts.Store(intfID, false) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 442 | } |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 443 | portNum := plt.IntfIDToPortNo(intfID, portType) |
Chaitrashree G S | c0878ec | 2020-05-21 04:59:53 -0400 | [diff] [blame] | 444 | label, err := GetportLabel(intfID, portType) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 445 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 446 | 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] | 447 | } |
Chaitrashree G S | ded0a83 | 2020-01-09 20:21:48 -0500 | [diff] [blame] | 448 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 449 | // Check if port exists |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 450 | port, err := dh.getPortFromCore(ctx, &ca.PortFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 451 | DeviceId: dh.device.Id, |
| 452 | Port: portNum, |
| 453 | }) |
| 454 | if err == nil && port.Type == portType { |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 455 | logger.Debug(ctx, "port-already-exists-updating-oper-status-of-port") |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 456 | err = dh.updatePortStateInCore(ctx, &ca.PortState{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 457 | DeviceId: dh.device.Id, |
| 458 | PortType: portType, |
| 459 | PortNo: portNum, |
| 460 | OperStatus: operStatus}) |
| 461 | if err != nil { |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 462 | return olterrors.NewErrAdapter("failed-to-update-port-state", log.Fields{ |
| 463 | "device-id": dh.device.Id, |
| 464 | "port-type": portType, |
| 465 | "port-number": portNum, |
| 466 | "oper-status": operStatus}, err).Log() |
Chaitrashree G S | ded0a83 | 2020-01-09 20:21:48 -0500 | [diff] [blame] | 467 | } |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 468 | return nil |
Chaitrashree G S | ded0a83 | 2020-01-09 20:21:48 -0500 | [diff] [blame] | 469 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 470 | |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 471 | // Now create Port |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 472 | port = &voltha.Port{ |
| 473 | DeviceId: dh.device.Id, |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 474 | PortNo: portNum, |
| 475 | Label: label, |
| 476 | Type: portType, |
| 477 | OperStatus: operStatus, |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 478 | OfpPort: makeOfpPort(dh.device.MacAddress, speedMbps), |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 479 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 480 | logger.Debugw(ctx, "sending-port-update-to-core", log.Fields{"port": port}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 481 | // 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] | 482 | err = dh.createPortInCore(ctx, port) |
| 483 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 484 | return olterrors.NewErrAdapter("error-creating-port", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 485 | "device-id": dh.device.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 486 | "port-type": portType}, err) |
Girish Gowdru | 1110ef2 | 2019-06-24 11:17:59 -0400 | [diff] [blame] | 487 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 488 | go dh.updateLocalDevice(ctx) |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 489 | return nil |
| 490 | } |
| 491 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 492 | func (dh *DeviceHandler) updateLocalDevice(ctx context.Context) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 493 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 494 | if err != nil || device == nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 495 | logger.Errorf(ctx, "device-not-found", log.Fields{"device-id": dh.device.Id}, err) |
| 496 | return |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 497 | } |
Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 498 | dh.lockDevice.Lock() |
| 499 | defer dh.lockDevice.Unlock() |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 500 | dh.device = device |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 501 | } |
| 502 | |
David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 503 | // nolint: gocyclo |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 504 | // readIndications to read the indications from the OLT device |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 505 | func (dh *DeviceHandler) readIndications(ctx context.Context) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 506 | 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] | 507 | defer func() { |
| 508 | dh.lockDevice.Lock() |
| 509 | dh.isReadIndicationRoutineActive = false |
Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 510 | 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] | 511 | dh.lockDevice.Unlock() |
| 512 | }() |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 513 | indications, err := dh.startOpenOltIndicationStream(ctx) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 514 | if err != nil { |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 515 | return err |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 516 | } |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 517 | |
David Bainbridge | f5879ca | 2019-12-13 21:17:54 +0000 | [diff] [blame] | 518 | // Create an exponential backoff around re-enabling indications. The |
| 519 | // maximum elapsed time for the back off is set to 0 so that we will |
| 520 | // continue to retry. The max interval defaults to 1m, but is set |
| 521 | // here for code clarity |
| 522 | indicationBackoff := backoff.NewExponentialBackOff() |
| 523 | indicationBackoff.MaxElapsedTime = 0 |
| 524 | indicationBackoff.MaxInterval = 1 * time.Minute |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 525 | |
Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 526 | dh.lockDevice.Lock() |
| 527 | dh.isReadIndicationRoutineActive = true |
Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 528 | 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] | 529 | dh.lockDevice.Unlock() |
| 530 | |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 531 | Loop: |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 532 | for { |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 533 | select { |
| 534 | case <-dh.stopIndications: |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 535 | 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] | 536 | break Loop |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 537 | default: |
| 538 | indication, err := indications.Recv() |
Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 539 | |
| 540 | select { |
| 541 | case <-indications.Context().Done(): |
| 542 | if err != nil { |
| 543 | logger.Warnw(ctx, "error-during-enable-indications", |
| 544 | log.Fields{"err": err, |
| 545 | "device-id": dh.device.Id}) |
| 546 | } |
| 547 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 548 | // Use an exponential back off to prevent getting into a tight loop |
| 549 | duration := indicationBackoff.NextBackOff() |
Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 550 | logger.Infow(ctx, "backing-off-enable-indication", log.Fields{ |
| 551 | "device-id": dh.device.Id, |
| 552 | "duration": duration, |
| 553 | }) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 554 | if duration == backoff.Stop { |
| 555 | // If we reach a maximum then warn and reset the backoff |
| 556 | // timer and keep attempting. |
Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 557 | logger.Warnw(ctx, "maximum-indication-backoff-reached-resetting-backoff-timer", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 558 | log.Fields{"max-indication-backoff": indicationBackoff.MaxElapsedTime, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 559 | "device-id": dh.device.Id}) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 560 | indicationBackoff.Reset() |
| 561 | } |
David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 562 | |
| 563 | // On failure process a backoff timer while watching for stopIndications |
| 564 | // events |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 565 | backoffTimer := time.NewTimer(indicationBackoff.NextBackOff()) |
David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 566 | select { |
| 567 | case <-dh.stopIndications: |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 568 | 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] | 569 | if !backoffTimer.Stop() { |
| 570 | <-backoffTimer.C |
David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 571 | } |
| 572 | break Loop |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 573 | case <-backoffTimer.C: |
| 574 | // backoffTimer expired continue |
David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 575 | } |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 576 | if indications, err = dh.startOpenOltIndicationStream(ctx); err != nil { |
| 577 | return err |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 578 | } |
| 579 | continue |
Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 580 | default: |
| 581 | if err != nil { |
| 582 | logger.Errorw(ctx, "read-indication-error", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 583 | log.Fields{"err": err, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 584 | "device-id": dh.device.Id}) |
Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 585 | // Close the stream, and re-initialize it |
| 586 | if err = indications.CloseSend(); err != nil { |
| 587 | // Ok to ignore here, because we landed here due to a problem on the stream |
| 588 | // In all probability, the closeSend call may fail |
| 589 | logger.Debugw(ctx, "error-closing-send stream--error-ignored", |
| 590 | log.Fields{"err": err, |
| 591 | "device-id": dh.device.Id}) |
| 592 | } |
| 593 | if indications, err = dh.startOpenOltIndicationStream(ctx); err != nil { |
| 594 | return err |
| 595 | } |
| 596 | // once we re-initialized the indication stream, continue to read indications |
| 597 | continue |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 598 | } |
Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 599 | // Reset backoff if we have a successful receive |
| 600 | indicationBackoff.Reset() |
| 601 | // When OLT is admin down, ignore all indications. |
| 602 | if dh.device.AdminState == voltha.AdminState_DISABLED && !isIndicationAllowedDuringOltAdminDown(indication) { |
| 603 | logger.Debugw(ctx, "olt-is-admin-down, ignore indication", |
| 604 | log.Fields{"indication": indication, |
| 605 | "device-id": dh.device.Id}) |
| 606 | continue |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 607 | } |
Elia Battiston | 599d25f | 2022-02-16 14:49:08 +0100 | [diff] [blame] | 608 | dh.handleIndication(ctx, indication) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 609 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 610 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 611 | } |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 612 | // Close the send stream |
| 613 | _ = indications.CloseSend() // Ok to ignore error, as we stopping the readIndication anyway |
Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 614 | |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 615 | return nil |
| 616 | } |
| 617 | |
| 618 | func (dh *DeviceHandler) startOpenOltIndicationStream(ctx context.Context) (oop.Openolt_EnableIndicationClient, error) { |
Girish Gowdra | 852ad91 | 2021-05-04 00:05:50 -0700 | [diff] [blame] | 619 | 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] | 620 | indications, err := dh.Client.EnableIndication(ctx, new(oop.Empty)) |
| 621 | if err != nil { |
| 622 | return nil, olterrors.NewErrCommunication("indication-read-failure", log.Fields{"device-id": dh.device.Id}, err).Log() |
| 623 | } |
| 624 | if indications == nil { |
| 625 | return nil, olterrors.NewErrInvalidValue(log.Fields{"indications": nil, "device-id": dh.device.Id}, nil).Log() |
| 626 | } |
Girish Gowdra | 852ad91 | 2021-05-04 00:05:50 -0700 | [diff] [blame] | 627 | 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] | 628 | return indications, nil |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | // isIndicationAllowedDuringOltAdminDown returns true if the indication is allowed during OLT Admin down, else false |
| 632 | func isIndicationAllowedDuringOltAdminDown(indication *oop.Indication) bool { |
| 633 | switch indication.Data.(type) { |
| 634 | case *oop.Indication_OltInd, *oop.Indication_IntfInd, *oop.Indication_IntfOperInd: |
| 635 | return true |
| 636 | |
| 637 | default: |
| 638 | return false |
| 639 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 640 | } |
| 641 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 642 | func (dh *DeviceHandler) handleOltIndication(ctx context.Context, oltIndication *oop.OltIndication) error { |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 643 | raisedTs := time.Now().Unix() |
Gamze Abaka | a1a5052 | 2019-10-03 19:28:27 +0000 | [diff] [blame] | 644 | if oltIndication.OperState == "up" && dh.transitionMap.currentDeviceState != deviceStateUp { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 645 | dh.transitionMap.Handle(ctx, DeviceUpInd) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 646 | } else if oltIndication.OperState == "down" { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 647 | dh.transitionMap.Handle(ctx, DeviceDownInd) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 648 | } |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 649 | // Send or clear Alarm |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 650 | 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] | 651 | return olterrors.NewErrAdapter("failed-indication", log.Fields{ |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 652 | "device-id": dh.device.Id, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 653 | "indication": oltIndication, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 654 | "timestamp": raisedTs}, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 655 | } |
| 656 | return nil |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 657 | } |
| 658 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 659 | // nolint: gocyclo |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 660 | func (dh *DeviceHandler) handleIndication(ctx context.Context, indication *oop.Indication) { |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 661 | raisedTs := time.Now().Unix() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 662 | switch indication.Data.(type) { |
| 663 | case *oop.Indication_OltInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 664 | span, ctx := log.CreateChildSpan(ctx, "olt-indication", log.Fields{"device-id": dh.device.Id}) |
| 665 | defer span.Finish() |
Girish Gowdra | 852ad91 | 2021-05-04 00:05:50 -0700 | [diff] [blame] | 666 | 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] | 667 | if err := dh.handleOltIndication(ctx, indication.GetOltInd()); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 668 | _ = 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] | 669 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 670 | case *oop.Indication_IntfInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 671 | span, ctx := log.CreateChildSpan(ctx, "interface-indication", log.Fields{"device-id": dh.device.Id}) |
| 672 | defer span.Finish() |
| 673 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 674 | intfInd := indication.GetIntfInd() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 675 | go func() { |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 676 | 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] | 677 | _ = 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] | 678 | } |
| 679 | }() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 680 | 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] | 681 | case *oop.Indication_IntfOperInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 682 | span, ctx := log.CreateChildSpan(ctx, "interface-oper-indication", log.Fields{"device-id": dh.device.Id}) |
| 683 | defer span.Finish() |
| 684 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 685 | intfOperInd := indication.GetIntfOperInd() |
| 686 | if intfOperInd.GetType() == "nni" { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 687 | go func() { |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 688 | 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] | 689 | _ = 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] | 690 | } |
| 691 | }() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 692 | } else if intfOperInd.GetType() == "pon" { |
| 693 | // TODO: Check what needs to be handled here for When PON PORT down, ONU will be down |
| 694 | // Handle pon port update |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 695 | go func() { |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 696 | 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] | 697 | _ = 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] | 698 | } |
| 699 | }() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 700 | go dh.eventMgr.oltIntfOperIndication(ctx, indication.GetIntfOperInd(), dh.device.Id, raisedTs) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 701 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 702 | logger.Infow(ctx, "received-interface-oper-indication", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 703 | log.Fields{"interfaceOperInd": intfOperInd, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 704 | "device-id": dh.device.Id}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 705 | case *oop.Indication_OnuDiscInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 706 | span, ctx := log.CreateChildSpan(ctx, "onu-discovery-indication", log.Fields{"device-id": dh.device.Id}) |
| 707 | defer span.Finish() |
| 708 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 709 | onuDiscInd := indication.GetOnuDiscInd() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 710 | logger.Infow(ctx, "received-onu-discovery-indication", log.Fields{"OnuDiscInd": onuDiscInd, "device-id": dh.device.Id}) |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 711 | //put message to channel and return immediately |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 712 | dh.putOnuIndicationToChannel(ctx, indication, onuDiscInd.GetIntfId()) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 713 | case *oop.Indication_OnuInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 714 | span, ctx := log.CreateChildSpan(ctx, "onu-indication", log.Fields{"device-id": dh.device.Id}) |
| 715 | defer span.Finish() |
| 716 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 717 | onuInd := indication.GetOnuInd() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 718 | logger.Infow(ctx, "received-onu-indication", log.Fields{"OnuInd": onuInd, "device-id": dh.device.Id}) |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 719 | //put message to channel and return immediately |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 720 | dh.putOnuIndicationToChannel(ctx, indication, onuInd.GetIntfId()) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 721 | case *oop.Indication_OmciInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 722 | span, ctx := log.CreateChildSpan(ctx, "omci-indication", log.Fields{"device-id": dh.device.Id}) |
| 723 | defer span.Finish() |
| 724 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 725 | omciInd := indication.GetOmciInd() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 726 | 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] | 727 | go func() { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 728 | if err := dh.omciIndication(ctx, omciInd); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 729 | _ = 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] | 730 | } |
| 731 | }() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 732 | case *oop.Indication_PktInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 733 | span, ctx := log.CreateChildSpan(ctx, "packet-indication", log.Fields{"device-id": dh.device.Id}) |
| 734 | defer span.Finish() |
| 735 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 736 | pktInd := indication.GetPktInd() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 737 | logger.Debugw(ctx, "received-packet-indication", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 738 | "intf-type": pktInd.IntfId, |
| 739 | "intf-id": pktInd.IntfId, |
| 740 | "gem-port-id": pktInd.GemportId, |
| 741 | "port-no": pktInd.PortNo, |
| 742 | "device-id": dh.device.Id, |
| 743 | }) |
| 744 | |
| 745 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 746 | logger.Debugw(ctx, "received-packet-indication-packet", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 747 | "intf-type": pktInd.IntfId, |
| 748 | "intf-id": pktInd.IntfId, |
| 749 | "gem-port-id": pktInd.GemportId, |
| 750 | "port-no": pktInd.PortNo, |
| 751 | "packet": hex.EncodeToString(pktInd.Pkt), |
| 752 | "device-id": dh.device.Id, |
| 753 | }) |
| 754 | } |
| 755 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 756 | go func() { |
| 757 | if err := dh.handlePacketIndication(ctx, pktInd); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 758 | _ = 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] | 759 | } |
| 760 | }() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 761 | case *oop.Indication_PortStats: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 762 | span, ctx := log.CreateChildSpan(ctx, "port-statistics-indication", log.Fields{"device-id": dh.device.Id}) |
| 763 | defer span.Finish() |
| 764 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 765 | portStats := indication.GetPortStats() |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 766 | go dh.portStats.PortStatisticsIndication(ctx, portStats, dh.totalPonPorts) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 767 | case *oop.Indication_FlowStats: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 768 | span, ctx := log.CreateChildSpan(ctx, "flow-stats-indication", log.Fields{"device-id": dh.device.Id}) |
| 769 | defer span.Finish() |
| 770 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 771 | flowStats := indication.GetFlowStats() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 772 | 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] | 773 | case *oop.Indication_AlarmInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 774 | span, ctx := log.CreateChildSpan(ctx, "alarm-indication", log.Fields{"device-id": dh.device.Id}) |
| 775 | defer span.Finish() |
| 776 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 777 | alarmInd := indication.GetAlarmInd() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 778 | logger.Infow(ctx, "received-alarm-indication", log.Fields{"AlarmInd": alarmInd, "device-id": dh.device.Id}) |
| 779 | go dh.eventMgr.ProcessEvents(ctx, alarmInd, dh.device.Id, raisedTs) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 780 | } |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 781 | } |
| 782 | |
nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 783 | func generateOnuIndication(intfID, onuID uint32, operState, adminState string) *oop.Indication { |
| 784 | onuInd := &oop.OnuIndication{ |
| 785 | IntfId: intfID, |
| 786 | OnuId: onuID, |
| 787 | OperState: operState, |
| 788 | AdminState: adminState, |
| 789 | } |
| 790 | indication := &oop.Indication{ |
| 791 | Data: &oop.Indication_OnuInd{ |
| 792 | OnuInd: onuInd, |
| 793 | }, |
| 794 | } |
| 795 | return indication |
| 796 | } |
| 797 | |
| 798 | func generateOnuAlarmIndication(intfID uint32, onuID uint32, losStatus string) *oop.AlarmIndication { |
| 799 | onuAlarmInd := &oop.OnuAlarmIndication{ |
| 800 | IntfId: intfID, |
| 801 | OnuId: onuID, |
| 802 | LosStatus: losStatus, |
| 803 | } |
| 804 | alarmInd := &oop.AlarmIndication{ |
| 805 | Data: &oop.AlarmIndication_OnuAlarmInd{ |
| 806 | OnuAlarmInd: onuAlarmInd, |
| 807 | }, |
| 808 | } |
| 809 | return alarmInd |
| 810 | } |
| 811 | func generatePonLosAlarmIndication(intfID uint32, losStatus string) *oop.AlarmIndication { |
| 812 | |
| 813 | ponlosAlarmInd := &oop.LosIndication{ |
| 814 | IntfId: intfID, |
| 815 | Status: losStatus, |
| 816 | } |
| 817 | alarmInd := &oop.AlarmIndication{ |
| 818 | Data: &oop.AlarmIndication_LosInd{ |
| 819 | LosInd: ponlosAlarmInd, |
| 820 | }, |
| 821 | } |
| 822 | return alarmInd |
| 823 | } |
| 824 | func (dh *DeviceHandler) updateIntfOperStateAndRaiseIndication(ctx context.Context, operState string, intfID uint32) { |
| 825 | go func() { |
| 826 | if err := dh.addPort(ctx, intfID, voltha.Port_PON_OLT, operState, defaultPortSpeedMbps); err != nil { |
| 827 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "interface-oper-pon", "device-id": dh.device.Id}, err).Log() |
| 828 | } |
| 829 | }() |
| 830 | |
| 831 | raisedTs := time.Now().Unix() |
| 832 | go dh.eventMgr.oltIntfOperIndication(ctx, &oop.IntfOperIndication{Type: "pon", IntfId: intfID, OperState: operState}, dh.device.Id, raisedTs) |
| 833 | } |
| 834 | |
| 835 | func (dh *DeviceHandler) reconcileOnus(ctx context.Context) error { |
| 836 | |
| 837 | onuDevicesFromCore, err := dh.getChildDevicesFromCore(ctx, dh.device.Id) |
| 838 | if err != nil { |
| 839 | |
| 840 | logger.Error(ctx, "unable to fetch child device", log.Fields{"eeror": err}) |
| 841 | |
| 842 | return err |
| 843 | } |
| 844 | for _, onuDeviceFromCore := range onuDevicesFromCore.Items { |
| 845 | |
| 846 | onuOperStatusFromCore := onuDeviceFromCore.OperStatus |
| 847 | onuConnectStatusFromCore := onuDeviceFromCore.ConnectStatus |
| 848 | intfID := plt.PortNoToIntfID(onuDeviceFromCore.ParentPortNo, voltha.Port_PON_OLT) |
| 849 | |
| 850 | onuID := onuDeviceFromCore.ProxyAddress.OnuId |
| 851 | onuDeviceFromOlt, err := dh.getOnuInfo(ctx, intfID, &onuID) |
| 852 | if err != nil { |
| 853 | logger.Error(ctx, "unable to get onu object from olt agent", log.Fields{"eeror": err}) |
| 854 | |
| 855 | } else { |
| 856 | onuOperStatusFromOlt := onuDeviceFromOlt.GetState() |
| 857 | onuLosFromOlt := onuDeviceFromOlt.GetLosi() |
| 858 | switch { |
| 859 | case onuOperStatusFromOlt.String() == "ACTIVE" && onuOperStatusFromCore.String() != "ACTIVE": |
| 860 | OnuIndication := generateOnuIndication(intfID, onuID, "up", "up") |
| 861 | dh.putOnuIndicationToChannel(ctx, OnuIndication, intfID) |
| 862 | |
| 863 | case onuLosFromOlt.String() == "ON" && onuConnectStatusFromCore.String() == "REACHABLE": |
| 864 | OnuIndication := generateOnuIndication(intfID, onuID, "down", "down") //check bal cli login notepad |
| 865 | alarmInd := generateOnuAlarmIndication(intfID, onuID, "on") |
| 866 | raisedTs := time.Now().Unix() |
| 867 | go dh.eventMgr.ProcessEvents(ctx, alarmInd, dh.device.Id, raisedTs) |
| 868 | |
| 869 | dh.putOnuIndicationToChannel(ctx, OnuIndication, intfID) |
| 870 | } |
| 871 | |
| 872 | } |
| 873 | |
| 874 | } |
| 875 | |
| 876 | return nil |
| 877 | } |
| 878 | |
| 879 | func (dh *DeviceHandler) reconcilePonPorts(ctx context.Context) error { // need onuid and pon id |
| 880 | portsFromCore, err := dh.getAllPortsFromCore(ctx, &ca.PortFilter{ |
| 881 | DeviceId: dh.device.Id, |
| 882 | PortType: voltha.Port_PON_OLT, |
| 883 | }) |
| 884 | if err != nil { |
| 885 | logger.Error(ctx, "unable to fetch ports from core", log.Fields{"eeror": err}) |
| 886 | |
| 887 | return err |
| 888 | |
| 889 | } |
| 890 | for _, portFromCore := range portsFromCore.Items { |
| 891 | portNum := portFromCore.GetPortNo() |
| 892 | intfID := plt.PortNoToIntfID(portNum, voltha.Port_PON_OLT) |
| 893 | portOperStatusFromCore := portFromCore.OperStatus |
| 894 | portAdminStateFromCore := portFromCore.AdminState |
| 895 | ponPortFromOlt, err := dh.getIntfInfo(ctx, intfID) |
| 896 | if err != nil { |
| 897 | logger.Error(ctx, "unable to get pon objects from olt agent", log.Fields{"eeror": err}) |
| 898 | } else { |
| 899 | portLosFromOlt := ponPortFromOlt.GetLos() |
| 900 | portStateFromOlt := ponPortFromOlt.GetState() |
| 901 | if portOperStatusFromCore.String() == "ACTIVE" && portLosFromOlt.String() == "ON" { |
| 902 | logger.Debug(ctx, "port is active in core but los is fired from olt", log.Fields{ |
| 903 | "portStateFromOlt": portStateFromOlt.String(), |
| 904 | "portOperStatusFromCore": portOperStatusFromCore.String(), |
| 905 | "device-id": dh.device.Id, |
| 906 | "port": portNum}) |
| 907 | ponLosindication := generatePonLosAlarmIndication(intfID, "on") |
| 908 | raisedTs := time.Now().Unix() |
| 909 | go dh.eventMgr.ProcessEvents(ctx, ponLosindication, dh.device.Id, raisedTs) |
| 910 | |
| 911 | } |
| 912 | switch { |
| 913 | case portStateFromOlt.String() == "ACTIVE_WORKING" && portOperStatusFromCore.String() != "ACTIVE": |
| 914 | logger.Debug(ctx, "mismatch between port state in voltha core and raising port up event", log.Fields{ |
| 915 | "portStateFromOlt": portStateFromOlt.String(), |
| 916 | "portOperStatusFromCore": portOperStatusFromCore.String(), |
| 917 | "device-id": dh.device.Id, |
| 918 | "port": portNum}) |
| 919 | dh.updateIntfOperStateAndRaiseIndication(ctx, "up", intfID) |
| 920 | case (portStateFromOlt.String() == "INACTIVE" || portStateFromOlt.String() == "UNKNOWN") && portOperStatusFromCore.String() == "ACTIVE": |
| 921 | logger.Debug(ctx, "mismatch between port state in voltha core and raising port down event", log.Fields{ |
| 922 | "portStateFromOlt": portStateFromOlt.String(), |
| 923 | "portOperStatusFromCore": portOperStatusFromCore.String(), |
| 924 | "device-id": dh.device.Id, |
| 925 | "port": portNum}) |
| 926 | dh.updateIntfOperStateAndRaiseIndication(ctx, "down", intfID) |
| 927 | case portStateFromOlt.String() == "DISABLED" && portAdminStateFromCore.String() == "ENABLED": |
| 928 | logger.Error(ctx, "port enabled in device but disabled at votlha core", log.Fields{ |
| 929 | "device-id": dh.device.Id, |
| 930 | "port": portNum}) |
| 931 | default: |
| 932 | logger.Error(ctx, "mismatch between port state in voltha core and voltha device", log.Fields{ |
| 933 | "portStateFromOlt": portStateFromOlt.String(), |
| 934 | "portOperStatusFromCore": portOperStatusFromCore.String(), |
| 935 | "device-id": dh.device.Id, |
| 936 | "port": portNum}) |
| 937 | |
| 938 | } |
| 939 | |
| 940 | } |
| 941 | |
| 942 | } |
| 943 | |
| 944 | return nil |
| 945 | } |
| 946 | |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 947 | // doStateUp handle the olt up indication and update to voltha core |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 948 | func (dh *DeviceHandler) doStateUp(ctx context.Context) error { |
Thomas Lee S | 85f3731 | 2020-04-03 17:06:12 +0530 | [diff] [blame] | 949 | //starting the stat collector |
Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 950 | // Declare deviceStateFilter to be used later |
| 951 | var deviceStateFilter *ca.DeviceStateFilter |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 952 | go startCollector(ctx, dh) |
nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 953 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 954 | if err != nil { |
| 955 | return fmt.Errorf("failed to get device from core: %w", err) |
| 956 | } |
| 957 | logger.Info(ctx, "Device state", log.Fields{ |
| 958 | "device-id": device.Id, |
| 959 | "CurrOperStatus": device.OperStatus, |
| 960 | "CurrConnStatus": device.ConnectStatus, |
| 961 | }) |
| 962 | // Perform cleanup if the device's operational status is REBOOTED |
| 963 | if device.OperStatus == voltha.OperStatus_RECONCILING && dh.prevOperStatus == voltha.OperStatus_REBOOTED { |
| 964 | // Log the device's operational status if it's REBOOTED |
| 965 | logger.Info(ctx, "Device is transitioning from REBOOTED to RECONCILING", log.Fields{ |
| 966 | "device-id": device.Id, |
| 967 | "OperStatus": device.OperStatus, |
| 968 | }) |
| 969 | dh.lockDevice.RLock() |
| 970 | // Stop the read indication only if it the routine is active |
| 971 | // The read indication would have already stopped due to failure on the gRPC stream following OLT going unreachable |
| 972 | // Sending message on the 'stopIndication' channel again will cause the readIndication routine to immediately stop |
| 973 | // on next execution of the readIndication routine. |
| 974 | if dh.isHeartbeatCheckActive { |
| 975 | dh.stopHeartbeatCheck <- true |
| 976 | } |
| 977 | if dh.isReadIndicationRoutineActive { |
| 978 | dh.stopIndications <- true |
| 979 | } |
| 980 | dh.lockDevice.RUnlock() |
| 981 | if err := dh.cleanupDeviceResources(ctx); err != nil { |
| 982 | logger.Error(ctx, "unable to clean up device resources", log.Fields{"error": err}) |
| 983 | return fmt.Errorf("cleanup device resources failed: %w", err) |
| 984 | } |
| 985 | if err := dh.initializeDeviceHandlerModules(ctx); err != nil { |
| 986 | return olterrors.NewErrAdapter("device-handler-initialization-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| 987 | } |
| 988 | go startHeartbeatCheck(ctx, dh) |
| 989 | |
| 990 | //dh.lockDevice.RUnlock() |
| 991 | |
| 992 | } else if device.OperStatus == voltha.OperStatus_RECONCILING { |
| 993 | // Log the device's operational status if it's RECONCILING |
| 994 | logger.Info(ctx, "Device is being reconciled", log.Fields{ |
| 995 | "device-id": device.Id, |
| 996 | "OperStatus": device.OperStatus, |
| 997 | }) |
| 998 | |
| 999 | // Perform reconciliation steps |
| 1000 | err = dh.reconcileOnus(ctx) |
| 1001 | if err != nil { |
| 1002 | logger.Error(ctx, "unable to reconcile onu", log.Fields{"error": err}) |
| 1003 | } |
| 1004 | err = dh.reconcilePonPorts(ctx) |
| 1005 | if err != nil { |
| 1006 | logger.Error(ctx, "unable to reconcile pon ports", log.Fields{"error": err}) |
nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 1007 | } |
| 1008 | } |
Girish Gowdra | 618fa57 | 2021-09-01 17:19:29 -0700 | [diff] [blame] | 1009 | // instantiate the mcast handler routines. |
| 1010 | for i := range dh.incomingMcastFlowOrGroup { |
| 1011 | // We land inside the below "if" code path, after the OLT comes back from a reboot, otherwise the routines |
| 1012 | // are already active when the DeviceHandler module is first instantiated (as part of Adopt_device RPC invocation). |
| 1013 | if !dh.mcastHandlerRoutineActive[i] { |
| 1014 | // Spin up a go routine to handling incoming mcast flow/group (add/modify/remove). |
| 1015 | // There will be MaxNumOfGroupHandlerChannels number of mcastFlowOrGroupChannelHandlerRoutine go routines. |
| 1016 | // These routines will be blocked on the dh.incomingMcastFlowOrGroup[mcast-group-id modulo MaxNumOfGroupHandlerChannels] channel |
| 1017 | // for incoming mcast flow/group to be processed serially. |
| 1018 | dh.mcastHandlerRoutineActive[i] = true |
| 1019 | go dh.mcastFlowOrGroupChannelHandlerRoutine(i, dh.incomingMcastFlowOrGroup[i], dh.stopMcastHandlerRoutine[i]) |
| 1020 | } |
| 1021 | } |
Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 1022 | // Create DeviceStateFilter with the desired operational and connection statuses |
| 1023 | deviceStateFilter = &ca.DeviceStateFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1024 | DeviceId: dh.device.Id, |
| 1025 | OperStatus: voltha.OperStatus_ACTIVE, |
| 1026 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 1027 | } |
| 1028 | // Log DeviceStateFilter for debugging purposes |
| 1029 | logger.Info(ctx, "DeviceStateFilter", log.Fields{ |
| 1030 | "DeviceId": deviceStateFilter.DeviceId, |
| 1031 | "OperStatus": deviceStateFilter.OperStatus, |
| 1032 | "ConnStatus": deviceStateFilter.ConnStatus, |
| 1033 | }) |
| 1034 | // Synchronous call to update device state - this method is run in its own go routine |
| 1035 | if err := dh.updateDeviceStateInCore(ctx, deviceStateFilter); err != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1036 | 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] | 1037 | } |
Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 1038 | |
| 1039 | //Clear olt communication failure event |
| 1040 | dh.device.ConnectStatus = voltha.ConnectStatus_REACHABLE |
| 1041 | dh.device.OperStatus = voltha.OperStatus_ACTIVE |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 1042 | raisedTs := time.Now().Unix() |
Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 1043 | go dh.eventMgr.oltCommunicationEvent(ctx, dh.device, raisedTs) |
| 1044 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1045 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | // doStateDown handle the olt down indication |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1049 | func (dh *DeviceHandler) doStateDown(ctx context.Context) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1050 | 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] | 1051 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1052 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1053 | if err != nil || device == nil { |
| 1054 | /*TODO: needs to handle error scenarios */ |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1055 | return olterrors.NewErrNotFound("device", log.Fields{"device-id": dh.device.Id}, err) |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | cloned := proto.Clone(device).(*voltha.Device) |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1059 | |
| 1060 | //Update the device oper state and connection status |
| 1061 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 1062 | dh.lockDevice.Lock() |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1063 | dh.device = cloned |
Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 1064 | dh.lockDevice.Unlock() |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1065 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1066 | if err = dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1067 | DeviceId: cloned.Id, |
| 1068 | OperStatus: cloned.OperStatus, |
| 1069 | ConnStatus: cloned.ConnectStatus, |
| 1070 | }); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1071 | 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] | 1072 | } |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1073 | |
| 1074 | //get the child device for the parent device |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1075 | onuDevices, err := dh.getChildDevicesFromCore(ctx, dh.device.Id) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1076 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1077 | 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] | 1078 | } |
| 1079 | for _, onuDevice := range onuDevices.Items { |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1080 | // Update onu state as down in onu adapter |
| 1081 | onuInd := oop.OnuIndication{} |
| 1082 | onuInd.OperState = "down" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1083 | |
| 1084 | ogClient, err := dh.getChildAdapterServiceClient(onuDevice.AdapterEndpoint) |
| 1085 | if err != nil { |
| 1086 | return err |
| 1087 | } |
| 1088 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1089 | _, err = ogClient.OnuIndication(subCtx, &ia.OnuIndicationMessage{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1090 | DeviceId: onuDevice.Id, |
| 1091 | OnuIndication: &onuInd, |
| 1092 | }) |
| 1093 | cancel() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1094 | if err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1095 | _ = olterrors.NewErrCommunication("inter-adapter-send-failed", log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1096 | "source": dh.openOLT.config.AdapterEndpoint, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1097 | "onu-indicator": onuInd, |
| 1098 | "device-type": onuDevice.Type, |
| 1099 | "device-id": onuDevice.Id}, err).LogAt(log.ErrorLevel) |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1100 | //Do not return here and continue to process other ONUs |
Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 1101 | } else { |
| 1102 | 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] | 1103 | } |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1104 | } |
Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 1105 | dh.lockDevice.Lock() |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1106 | /* Discovered ONUs entries need to be cleared , since after OLT |
| 1107 | is up, it starts sending discovery indications again*/ |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1108 | dh.discOnus = sync.Map{} |
Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 1109 | dh.lockDevice.Unlock() |
| 1110 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1111 | logger.Debugw(ctx, "do-state-down-end", log.Fields{"device-id": device.Id}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1112 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | // doStateInit dial the grpc before going to init state |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1116 | func (dh *DeviceHandler) doStateInit(ctx context.Context) error { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1117 | var err error |
Gamze Abaka | 49c40b3 | 2021-05-06 09:30:41 +0000 | [diff] [blame] | 1118 | |
| 1119 | // if the connection is already available, close the previous connection (olt reboot case) |
| 1120 | if dh.clientCon != nil { |
| 1121 | if err = dh.clientCon.Close(); err != nil { |
| 1122 | logger.Errorw(ctx, "failed-to-close-previous-connection", log.Fields{"device-id": dh.device.Id}) |
| 1123 | } else { |
| 1124 | logger.Debugw(ctx, "previous-grpc-channel-closed-successfully", log.Fields{"device-id": dh.device.Id}) |
| 1125 | } |
| 1126 | } |
| 1127 | |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1128 | logger.Debugw(ctx, "Dailing grpc", log.Fields{"device-id": dh.device.Id}) |
Gamze Abaka | 49c40b3 | 2021-05-06 09:30:41 +0000 | [diff] [blame] | 1129 | // 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] | 1130 | dh.clientCon, err = grpc.Dial(dh.device.GetHostAndPort(), |
| 1131 | grpc.WithInsecure(), |
| 1132 | grpc.WithBlock(), |
| 1133 | grpc.WithStreamInterceptor(grpc_middleware.ChainStreamClient( |
Girish Kumar | 935f7af | 2020-08-18 11:59:42 +0000 | [diff] [blame] | 1134 | grpc_opentracing.StreamClientInterceptor(grpc_opentracing.WithTracer(log.ActiveTracerProxy{})), |
Girish Kumar | 93e9174 | 2020-07-27 16:43:19 +0000 | [diff] [blame] | 1135 | )), |
| 1136 | grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient( |
Girish Kumar | 935f7af | 2020-08-18 11:59:42 +0000 | [diff] [blame] | 1137 | grpc_opentracing.UnaryClientInterceptor(grpc_opentracing.WithTracer(log.ActiveTracerProxy{})), |
Girish Kumar | 93e9174 | 2020-07-27 16:43:19 +0000 | [diff] [blame] | 1138 | ))) |
| 1139 | |
| 1140 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1141 | return olterrors.NewErrCommunication("dial-failure", log.Fields{ |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1142 | "device-id": dh.device.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1143 | "host-and-port": dh.device.GetHostAndPort()}, err) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1144 | } |
Akash Soni | f49299a | 2024-04-25 12:06:37 +0530 | [diff] [blame] | 1145 | //Setting oper and connection state to RECONCILING and conn state to reachable |
| 1146 | cgClient, err := dh.coreClient.GetCoreServiceClient() |
| 1147 | if err != nil { |
| 1148 | return err |
| 1149 | } |
| 1150 | |
| 1151 | if dh.device.OperStatus == voltha.OperStatus_RECONCILING { |
| 1152 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.openOLT.rpcTimeout) |
| 1153 | defer cancel() |
| 1154 | if _, err := cgClient.DeviceStateUpdate(subCtx, &ca.DeviceStateFilter{ |
| 1155 | DeviceId: dh.device.Id, |
| 1156 | OperStatus: voltha.OperStatus_RECONCILING, |
| 1157 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 1158 | }); err != nil { |
| 1159 | return olterrors.NewErrAdapter("device-update-failed", log.Fields{"device-id": dh.device.Id}, err) |
| 1160 | } |
| 1161 | // 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 |
| 1162 | // locally cached copy of the device struct. |
| 1163 | dh.device.OperStatus = voltha.OperStatus_RECONCILING |
| 1164 | dh.device.ConnectStatus = voltha.ConnectStatus_REACHABLE |
| 1165 | } |
| 1166 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1167 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | // postInit create olt client instance to invoke RPC on the olt device |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1171 | func (dh *DeviceHandler) postInit(ctx context.Context) error { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1172 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1173 | dh.transitionMap.Handle(ctx, GrpcConnected) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1174 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | // doStateConnected get the device info and update to voltha core |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1178 | func (dh *DeviceHandler) doStateConnected(ctx context.Context) error { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1179 | var err error |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1180 | 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] | 1181 | |
| 1182 | // Case where OLT is disabled and then rebooted. |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1183 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1184 | if err != nil || device == nil { |
| 1185 | /*TODO: needs to handle error scenarios */ |
| 1186 | return olterrors.NewErrAdapter("device-fetch-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| 1187 | } |
| 1188 | if device.AdminState == voltha.AdminState_DISABLED { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1189 | logger.Debugln(ctx, "do-state-connected--device-admin-state-down") |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1190 | |
| 1191 | cloned := proto.Clone(device).(*voltha.Device) |
| 1192 | cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE |
| 1193 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 1194 | dh.device = cloned |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1195 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1196 | if err = dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1197 | DeviceId: cloned.Id, |
| 1198 | OperStatus: cloned.OperStatus, |
| 1199 | ConnStatus: cloned.ConnectStatus, |
| 1200 | }); err != nil { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1201 | 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] | 1202 | } |
| 1203 | |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 1204 | // 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] | 1205 | _, err = dh.Client.DisableOlt(ctx, new(oop.Empty)) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1206 | if err != nil { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1207 | 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] | 1208 | } |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1209 | // We should still go ahead an initialize various device handler modules so that when OLT is re-enabled, we have |
| 1210 | // all the modules initialized and ready to handle incoming ONUs. |
| 1211 | |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1212 | err = dh.initializeDeviceHandlerModules(ctx) |
| 1213 | if err != nil { |
| 1214 | 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] | 1215 | } |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1216 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1217 | go startHeartbeatCheck(ctx, dh) |
| 1218 | |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1219 | return nil |
| 1220 | } |
| 1221 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1222 | ports, err := dh.listDevicePortsFromCore(ctx, dh.device.Id) |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 1223 | if err != nil { |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1224 | /*TODO: needs to handle error scenarios */ |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 1225 | return olterrors.NewErrAdapter("fetch-ports-failed", log.Fields{"device-id": dh.device.Id}, err) |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1226 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1227 | dh.populateActivePorts(ctx, ports.Items) |
| 1228 | if err := dh.disableAdminDownPorts(ctx, ports.Items); err != nil { |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 1229 | return olterrors.NewErrAdapter("port-status-update-failed", log.Fields{"ports": ports}, err) |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 1230 | } |
| 1231 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1232 | if err := dh.initializeDeviceHandlerModules(ctx); err != nil { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1233 | 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] | 1234 | } |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1235 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1236 | go dh.updateLocalDevice(ctx) |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 1237 | |
| 1238 | if device.PmConfigs != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1239 | dh.UpdatePmConfig(ctx, device.PmConfigs) |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 1240 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1241 | |
| 1242 | go startHeartbeatCheck(ctx, dh) |
| 1243 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1244 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1245 | } |
| 1246 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1247 | func (dh *DeviceHandler) initializeDeviceHandlerModules(ctx context.Context) error { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1248 | var err error |
| 1249 | dh.deviceInfo, err = dh.populateDeviceInfo(ctx) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1250 | |
Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 1251 | if dh.flowMgr != nil { |
| 1252 | dh.StopAllFlowRoutines(ctx) |
| 1253 | } |
| 1254 | |
| 1255 | dh.CloseKVClient(ctx) |
| 1256 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1257 | if err != nil { |
| 1258 | return olterrors.NewErrAdapter("populate-device-info-failed", log.Fields{"device-id": dh.device.Id}, err) |
| 1259 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1260 | dh.totalPonPorts = dh.deviceInfo.GetPonPorts() |
| 1261 | dh.agentPreviouslyConnected = dh.deviceInfo.PreviouslyConnected |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1262 | // +1 is for NNI |
| 1263 | dh.resourceMgr = make([]*rsrcMgr.OpenOltResourceMgr, dh.totalPonPorts+1) |
| 1264 | dh.flowMgr = make([]*OpenOltFlowMgr, dh.totalPonPorts+1) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1265 | var i uint32 |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1266 | // Index from 0 to until totalPonPorts ( Ex: 0 .. 15 ) -> PonPort Managers |
| 1267 | // Index totalPonPorts ( Ex: 16 ) -> NniPort Manager |
| 1268 | // There is only one NNI manager since multiple NNI is not supported for now |
| 1269 | for i = 0; i < dh.totalPonPorts+1; i++ { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1270 | // Instantiate resource manager |
| 1271 | 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] | 1272 | return olterrors.ErrResourceManagerInstantiating |
| 1273 | } |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1274 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1275 | // GroupManager instance is per OLT. But it needs a reference to any instance of resourceMgr to interface with |
| 1276 | // the KV store to manage mcast group data. Provide the first instance (0th index) |
| 1277 | if dh.groupMgr = NewGroupManager(ctx, dh, dh.resourceMgr[0]); dh.groupMgr == nil { |
| 1278 | return olterrors.ErrGroupManagerInstantiating |
| 1279 | } |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1280 | for i = 0; i < dh.totalPonPorts+1; i++ { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1281 | // Instantiate flow manager |
| 1282 | if dh.flowMgr[i] = NewFlowManager(ctx, dh, dh.resourceMgr[i], dh.groupMgr, i); dh.flowMgr[i] == nil { |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 1283 | //Continue to check the rest of the ports |
| 1284 | logger.Errorw(ctx, "error-initializing-flow-manager-for-intf", log.Fields{"intfID": i, "device-id": dh.device.Id}) |
| 1285 | } else { |
| 1286 | dh.resourceMgr[i].TechprofileRef = dh.flowMgr[i].techprofile |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1287 | } |
| 1288 | } |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1289 | /* TODO: Instantiate Alarm , stats , BW managers */ |
| 1290 | /* Instantiating Event Manager to handle Alarms and KPIs */ |
| 1291 | dh.eventMgr = NewEventMgr(dh.EventProxy, dh) |
| 1292 | |
| 1293 | // Stats config for new device |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1294 | dh.portStats = NewOpenOltStatsMgr(ctx, dh) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1295 | |
| 1296 | return nil |
| 1297 | |
| 1298 | } |
| 1299 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1300 | func (dh *DeviceHandler) populateDeviceInfo(ctx context.Context) (*oop.DeviceInfo, error) { |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1301 | var err error |
| 1302 | var deviceInfo *oop.DeviceInfo |
| 1303 | |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1304 | 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] | 1305 | |
| 1306 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1307 | return nil, olterrors.NewErrPersistence("get", "device", 0, nil, err) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1308 | } |
| 1309 | if deviceInfo == nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1310 | return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1311 | } |
| 1312 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1313 | 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] | 1314 | dh.device.Root = true |
| 1315 | dh.device.Vendor = deviceInfo.Vendor |
| 1316 | dh.device.Model = deviceInfo.Model |
| 1317 | dh.device.SerialNumber = deviceInfo.DeviceSerialNumber |
| 1318 | dh.device.HardwareVersion = deviceInfo.HardwareVersion |
| 1319 | dh.device.FirmwareVersion = deviceInfo.FirmwareVersion |
| 1320 | |
| 1321 | if deviceInfo.DeviceId == "" { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1322 | 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] | 1323 | host := strings.Split(dh.device.GetHostAndPort(), ":")[0] |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1324 | genmac, err := generateMacFromHost(ctx, host) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 1325 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1326 | 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] | 1327 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1328 | 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] | 1329 | dh.device.MacAddress = genmac |
| 1330 | } else { |
| 1331 | dh.device.MacAddress = deviceInfo.DeviceId |
| 1332 | } |
| 1333 | |
| 1334 | // 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] | 1335 | if err = dh.updateDeviceInCore(ctx, dh.device); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1336 | 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] | 1337 | } |
| 1338 | |
| 1339 | return deviceInfo, nil |
| 1340 | } |
| 1341 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1342 | func startCollector(ctx context.Context, dh *DeviceHandler) { |
Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 1343 | logger.Debugw(ctx, "starting-collector", log.Fields{"device-id": dh.device.Id}) |
Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 1344 | |
| 1345 | defer func() { |
| 1346 | dh.lockDevice.Lock() |
| 1347 | dh.isCollectorActive = false |
| 1348 | dh.lockDevice.Unlock() |
| 1349 | }() |
| 1350 | |
| 1351 | dh.lockDevice.Lock() |
| 1352 | dh.isCollectorActive = true |
| 1353 | dh.lockDevice.Unlock() |
| 1354 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1355 | for { |
| 1356 | select { |
| 1357 | case <-dh.stopCollector: |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 1358 | logger.Debugw(ctx, "stopping-collector-for-olt", log.Fields{"device-id": dh.device.Id}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1359 | return |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 1360 | case <-time.After(time.Duration(dh.metrics.ToPmConfigs().DefaultFreq) * time.Second): |
Girish Gowdra | 34815db | 2020-05-11 17:18:04 -0700 | [diff] [blame] | 1361 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1362 | ports, err := dh.listDevicePortsFromCore(ctx, dh.device.Id) |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 1363 | if err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1364 | 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] | 1365 | continue |
| 1366 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1367 | for _, port := range ports.Items { |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1368 | // NNI Stats |
| 1369 | if port.Type == voltha.Port_ETHERNET_NNI { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1370 | intfID := plt.PortNoToIntfID(port.PortNo, voltha.Port_ETHERNET_NNI) |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1371 | cmnni := dh.portStats.collectNNIMetrics(intfID) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1372 | logger.Debugw(ctx, "collect-nni-metrics", log.Fields{"metrics": cmnni}) |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 1373 | 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] | 1374 | logger.Debugw(ctx, "publish-nni-metrics", log.Fields{"nni-port": port.Label}) |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1375 | } |
| 1376 | // PON Stats |
| 1377 | if port.Type == voltha.Port_PON_OLT { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1378 | intfID := plt.PortNoToIntfID(port.PortNo, voltha.Port_PON_OLT) |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1379 | if val, ok := dh.activePorts.Load(intfID); ok && val == true { |
| 1380 | cmpon := dh.portStats.collectPONMetrics(intfID) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1381 | logger.Debugw(ctx, "collect-pon-metrics", log.Fields{"metrics": cmpon}) |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 1382 | 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] | 1383 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1384 | logger.Debugw(ctx, "publish-pon-metrics", log.Fields{"pon-port": port.Label}) |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 1385 | |
yasin sapli | 9e4c509 | 2022-02-01 13:52:33 +0000 | [diff] [blame] | 1386 | onuGemInfoLst := dh.resourceMgr[intfID].GetOnuGemInfoList(ctx) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1387 | if len(onuGemInfoLst) > 0 { |
| 1388 | go dh.portStats.collectOnuAndGemStats(ctx, onuGemInfoLst) |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 1389 | } |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 1390 | } |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | } |
| 1395 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 1396 | // AdoptDevice adopts the OLT device |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1397 | func (dh *DeviceHandler) AdoptDevice(ctx context.Context, device *voltha.Device) { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1398 | dh.transitionMap = NewTransitionMap(dh) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1399 | 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] | 1400 | dh.transitionMap.Handle(ctx, DeviceInit) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1401 | |
| 1402 | // Now, set the initial PM configuration for that device |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1403 | cgClient, err := dh.coreClient.GetCoreServiceClient() |
| 1404 | if err != nil { |
| 1405 | logger.Errorw(ctx, "no-core-connection", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 1406 | return |
| 1407 | } |
| 1408 | |
| 1409 | // Now, set the initial PM configuration for that device |
| 1410 | if _, err := cgClient.DevicePMConfigUpdate(ctx, dh.metrics.ToPmConfigs()); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1411 | _ = 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] | 1412 | } |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1413 | } |
| 1414 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 1415 | // GetOfpDeviceInfo Gets the Ofp information of the given device |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1416 | func (dh *DeviceHandler) GetOfpDeviceInfo(device *voltha.Device) (*ca.SwitchCapability, error) { |
| 1417 | return &ca.SwitchCapability{ |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1418 | Desc: &of.OfpDesc{ |
Devmalya Paul | 70dd497 | 2019-06-10 15:19:17 +0530 | [diff] [blame] | 1419 | MfrDesc: "VOLTHA Project", |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1420 | HwDesc: "open_pon", |
| 1421 | SwDesc: "open_pon", |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1422 | SerialNum: device.SerialNumber, |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1423 | }, |
| 1424 | SwitchFeatures: &of.OfpSwitchFeatures{ |
| 1425 | NBuffers: 256, |
| 1426 | NTables: 2, |
| 1427 | Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS | |
| 1428 | of.OfpCapabilities_OFPC_TABLE_STATS | |
| 1429 | of.OfpCapabilities_OFPC_PORT_STATS | |
| 1430 | of.OfpCapabilities_OFPC_GROUP_STATS), |
| 1431 | }, |
| 1432 | }, nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1433 | } |
| 1434 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1435 | // GetTechProfileDownloadMessage fetches the TechProfileDownloadMessage for the caller. |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1436 | 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] | 1437 | ifID, err := plt.IntfIDFromPonPortNum(ctx, request.ParentPonPort) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1438 | if err != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1439 | return nil, err |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1440 | } |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 1441 | if dh.flowMgr == nil || dh.flowMgr[ifID] == nil { |
| 1442 | 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() |
| 1443 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1444 | return dh.flowMgr[ifID].getTechProfileDownloadMessage(ctx, request.TpInstancePath, request.OnuId, request.DeviceId) |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 1445 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1448 | func (dh *DeviceHandler) omciIndication(ctx context.Context, omciInd *oop.OmciIndication) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1449 | 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] | 1450 | var deviceType string |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1451 | var deviceID string |
| 1452 | var proxyDeviceID string |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1453 | var childAdapterEndpoint string |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1454 | |
Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1455 | transid := extractOmciTransactionID(omciInd.Pkt) |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1456 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1457 | 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] | 1458 | "omci-transaction-id": transid, "omci-msg": hex.EncodeToString(omciInd.Pkt)}) |
| 1459 | } |
Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1460 | |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1461 | onuKey := dh.formOnuKey(omciInd.IntfId, omciInd.OnuId) |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1462 | |
| 1463 | if onuInCache, ok := dh.onus.Load(onuKey); !ok { |
| 1464 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1465 | 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] | 1466 | ponPort := plt.IntfIDToPortNo(omciInd.GetIntfId(), voltha.Port_PON_OLT) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1467 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1468 | onuDevice, err := dh.getChildDeviceFromCore(ctx, &ca.ChildDeviceFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1469 | ParentId: dh.device.Id, |
| 1470 | OnuId: omciInd.OnuId, |
| 1471 | ParentPortNo: ponPort, |
| 1472 | }) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1473 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1474 | return olterrors.NewErrNotFound("onu", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1475 | "intf-id": omciInd.IntfId, |
| 1476 | "onu-id": omciInd.OnuId}, err) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1477 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1478 | deviceType = onuDevice.Type |
| 1479 | deviceID = onuDevice.Id |
| 1480 | proxyDeviceID = onuDevice.ProxyAddress.DeviceId |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1481 | childAdapterEndpoint = onuDevice.AdapterEndpoint |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1482 | //if not exist in cache, then add to cache. |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1483 | 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] | 1484 | } else { |
| 1485 | //found in cache |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1486 | 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] | 1487 | deviceType = onuInCache.(*OnuDevice).deviceType |
| 1488 | deviceID = onuInCache.(*OnuDevice).deviceID |
| 1489 | proxyDeviceID = onuInCache.(*OnuDevice).proxyDeviceID |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1490 | childAdapterEndpoint = onuInCache.(*OnuDevice).adapterEndpoint |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1491 | } |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1492 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1493 | if err := dh.sendOmciIndicationToChildAdapter(ctx, childAdapterEndpoint, &ia.OmciMessage{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1494 | ParentDeviceId: proxyDeviceID, |
| 1495 | ChildDeviceId: deviceID, |
| 1496 | Message: omciInd.Pkt, |
| 1497 | }); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1498 | return olterrors.NewErrCommunication("omci-request", log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1499 | "source": dh.openOLT.config.AdapterEndpoint, |
| 1500 | "device-type": deviceType, |
| 1501 | "destination": childAdapterEndpoint, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1502 | "onu-id": deviceID, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1503 | "proxy-device-id": proxyDeviceID}, err) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1504 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1505 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1506 | } |
| 1507 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1508 | // //ProcessInterAdapterMessage sends the proxied messages to the target device |
| 1509 | // // If the proxy address is not found in the unmarshalled message, it first fetches the onu device for which the message |
| 1510 | // // is meant, and then send the unmarshalled omci message to this onu |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1511 | // func (dh *DeviceHandler) ProcessInterAdapterMessage(ctx context.Context, msg *ca.InterAdapterMessage) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1512 | // logger.Debugw(ctx, "process-inter-adapter-message", log.Fields{"msgID": msg.Header.Id}) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1513 | // if msg.Header.Type == ca.InterAdapterMessageType_OMCI_REQUEST { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1514 | // return dh.handleInterAdapterOmciMsg(ctx, msg) |
| 1515 | // } |
| 1516 | // return olterrors.NewErrInvalidValue(log.Fields{"inter-adapter-message-type": msg.Header.Type}, nil) |
| 1517 | // } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1518 | |
kesavand | b9f54fd | 2021-11-25 20:08:04 +0530 | [diff] [blame] | 1519 | // ProxyOmciRequests sends the proxied OMCI message to the target device |
| 1520 | func (dh *DeviceHandler) ProxyOmciRequests(ctx context.Context, omciMsgs *ia.OmciMessages) error { |
Abhilash Laxmeshwar | 092e6ca | 2022-12-08 19:51:27 +0530 | [diff] [blame] | 1521 | if DeviceState(dh.device.ConnectStatus) != DeviceState(voltha.ConnectStatus_REACHABLE) { |
| 1522 | return status.Error(codes.Unavailable, "OLT unreachable") |
| 1523 | } |
kesavand | b9f54fd | 2021-11-25 20:08:04 +0530 | [diff] [blame] | 1524 | if omciMsgs.GetProxyAddress() == nil { |
| 1525 | onuDevice, err := dh.getDeviceFromCore(ctx, omciMsgs.ChildDeviceId) |
| 1526 | if err != nil { |
| 1527 | return olterrors.NewErrNotFound("onu", log.Fields{ |
| 1528 | "parent-device-id": dh.device.Id, |
| 1529 | "child-device-id": omciMsgs.ChildDeviceId}, err) |
| 1530 | } |
| 1531 | logger.Debugw(ctx, "device-retrieved-from-core", log.Fields{"onu-device-proxy-address": onuDevice.ProxyAddress}) |
| 1532 | if err := dh.sendProxyOmciRequests(log.WithSpanFromContext(context.Background(), ctx), onuDevice, omciMsgs); err != nil { |
| 1533 | return olterrors.NewErrCommunication("send-failed", log.Fields{ |
| 1534 | "parent-device-id": dh.device.Id, |
| 1535 | "child-device-id": omciMsgs.ChildDeviceId}, err) |
| 1536 | } |
| 1537 | } else { |
| 1538 | logger.Debugw(ctx, "proxy-address-found-in-omci-message", log.Fields{"onu-device-proxy-address": omciMsgs.ProxyAddress}) |
| 1539 | if err := dh.sendProxyOmciRequests(log.WithSpanFromContext(context.Background(), ctx), nil, omciMsgs); err != nil { |
| 1540 | return olterrors.NewErrCommunication("send-failed", log.Fields{ |
| 1541 | "parent-device-id": dh.device.Id, |
| 1542 | "child-device-id": omciMsgs.ChildDeviceId}, err) |
| 1543 | } |
| 1544 | } |
| 1545 | return nil |
| 1546 | } |
| 1547 | |
| 1548 | func (dh *DeviceHandler) sendProxyOmciRequests(ctx context.Context, onuDevice *voltha.Device, omciMsgs *ia.OmciMessages) error { |
| 1549 | var intfID uint32 |
| 1550 | var onuID uint32 |
| 1551 | var connectStatus common.ConnectStatus_Types |
| 1552 | if onuDevice != nil { |
| 1553 | intfID = onuDevice.ProxyAddress.GetChannelId() |
| 1554 | onuID = onuDevice.ProxyAddress.GetOnuId() |
| 1555 | connectStatus = onuDevice.ConnectStatus |
| 1556 | } else { |
| 1557 | intfID = omciMsgs.GetProxyAddress().GetChannelId() |
| 1558 | onuID = omciMsgs.GetProxyAddress().GetOnuId() |
| 1559 | connectStatus = omciMsgs.GetConnectStatus() |
| 1560 | } |
| 1561 | if connectStatus != voltha.ConnectStatus_REACHABLE { |
| 1562 | logger.Debugw(ctx, "onu-not-reachable--cannot-send-omci", log.Fields{"intf-id": intfID, "onu-id": onuID}) |
| 1563 | |
| 1564 | return olterrors.NewErrCommunication("unreachable", log.Fields{ |
| 1565 | "intf-id": intfID, |
| 1566 | "onu-id": onuID}, nil) |
| 1567 | } |
| 1568 | |
| 1569 | // TODO: OpenOLT Agent oop.OmciMsg expects a hex encoded string for OMCI packets rather than the actual bytes. |
| 1570 | // Fix this in the agent and then we can pass byte array as Pkt: omciMsg.Message. |
| 1571 | |
| 1572 | onuSecOmciMsgList := omciMsgs.GetMessages() |
| 1573 | |
| 1574 | for _, onuSecOmciMsg := range onuSecOmciMsgList { |
| 1575 | |
| 1576 | var omciMessage *oop.OmciMsg |
| 1577 | hexPkt := make([]byte, hex.EncodedLen(len(onuSecOmciMsg))) |
| 1578 | hex.Encode(hexPkt, onuSecOmciMsg) |
| 1579 | omciMessage = &oop.OmciMsg{IntfId: intfID, OnuId: onuID, Pkt: hexPkt} |
| 1580 | |
| 1581 | // TODO: Below logging illustrates the "stringify" of the omci Pkt. |
| 1582 | // once above is fixed this log line can change to just use hex.EncodeToString(omciMessage.Pkt) |
| 1583 | //https://jira.opencord.org/browse/VOL-4604 |
| 1584 | transid := extractOmciTransactionID(onuSecOmciMsg) |
| 1585 | logger.Debugw(ctx, "sent-omci-msg", log.Fields{"intf-id": intfID, "onu-id": onuID, |
| 1586 | "omciTransactionID": transid, "omciMsg": string(omciMessage.Pkt)}) |
| 1587 | |
| 1588 | _, err := dh.Client.OmciMsgOut(log.WithSpanFromContext(context.Background(), ctx), omciMessage) |
| 1589 | if err != nil { |
| 1590 | return olterrors.NewErrCommunication("omci-send-failed", log.Fields{ |
| 1591 | "intf-id": intfID, |
| 1592 | "onu-id": onuID, |
| 1593 | "message": omciMessage}, err) |
| 1594 | } |
| 1595 | } |
| 1596 | return nil |
| 1597 | } |
| 1598 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1599 | // ProxyOmciMessage sends the proxied OMCI message to the target device |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1600 | func (dh *DeviceHandler) ProxyOmciMessage(ctx context.Context, omciMsg *ia.OmciMessage) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1601 | 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] | 1602 | |
Abhilash Laxmeshwar | 092e6ca | 2022-12-08 19:51:27 +0530 | [diff] [blame] | 1603 | if DeviceState(dh.device.ConnectStatus) != DeviceState(voltha.ConnectStatus_REACHABLE) { |
| 1604 | return status.Error(codes.Unavailable, "OLT unreachable") |
| 1605 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1606 | if omciMsg.GetProxyAddress() == nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1607 | onuDevice, err := dh.getDeviceFromCore(ctx, omciMsg.ChildDeviceId) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1608 | if err != nil { |
| 1609 | return olterrors.NewErrNotFound("onu", log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1610 | "parent-device-id": dh.device.Id, |
| 1611 | "child-device-id": omciMsg.ChildDeviceId}, err) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1612 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1613 | logger.Debugw(ctx, "device-retrieved-from-core", log.Fields{"onu-device-proxy-address": onuDevice.ProxyAddress}) |
| 1614 | 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] | 1615 | return olterrors.NewErrCommunication("send-failed", log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1616 | "parent-device-id": dh.device.Id, |
| 1617 | "child-device-id": omciMsg.ChildDeviceId}, err) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1618 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1619 | } else { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1620 | logger.Debugw(ctx, "proxy-address-found-in-omci-message", log.Fields{"onu-device-proxy-address": omciMsg.ProxyAddress}) |
| 1621 | 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] | 1622 | return olterrors.NewErrCommunication("send-failed", log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1623 | "parent-device-id": dh.device.Id, |
| 1624 | "child-device-id": omciMsg.ChildDeviceId}, err) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1625 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1626 | } |
| 1627 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1628 | } |
| 1629 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1630 | 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] | 1631 | var intfID uint32 |
| 1632 | var onuID uint32 |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1633 | var connectStatus common.ConnectStatus_Types |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1634 | if onuDevice != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1635 | intfID = onuDevice.ProxyAddress.GetChannelId() |
| 1636 | onuID = onuDevice.ProxyAddress.GetOnuId() |
| 1637 | connectStatus = onuDevice.ConnectStatus |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1638 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1639 | intfID = omciMsg.GetProxyAddress().GetChannelId() |
| 1640 | onuID = omciMsg.GetProxyAddress().GetOnuId() |
| 1641 | connectStatus = omciMsg.GetConnectStatus() |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1642 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1643 | if connectStatus != voltha.ConnectStatus_REACHABLE { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1644 | 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] | 1645 | |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1646 | return olterrors.NewErrCommunication("unreachable", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1647 | "intf-id": intfID, |
| 1648 | "onu-id": onuID}, nil) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1651 | // TODO: OpenOLT Agent oop.OmciMsg expects a hex encoded string for OMCI packets rather than the actual bytes. |
| 1652 | // 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] | 1653 | // https://jira.opencord.org/browse/VOL-4604 |
lcui | e24ef18 | 2019-04-29 22:58:36 -0700 | [diff] [blame] | 1654 | var omciMessage *oop.OmciMsg |
Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1655 | hexPkt := make([]byte, hex.EncodedLen(len(omciMsg.Message))) |
| 1656 | hex.Encode(hexPkt, omciMsg.Message) |
| 1657 | omciMessage = &oop.OmciMsg{IntfId: intfID, OnuId: onuID, Pkt: hexPkt} |
| 1658 | |
| 1659 | // TODO: Below logging illustrates the "stringify" of the omci Pkt. |
| 1660 | // once above is fixed this log line can change to just use hex.EncodeToString(omciMessage.Pkt) |
| 1661 | transid := extractOmciTransactionID(omciMsg.Message) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1662 | 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] | 1663 | "omciTransactionID": transid, "omciMsg": string(omciMessage.Pkt)}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1664 | |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1665 | _, err := dh.Client.OmciMsgOut(log.WithSpanFromContext(context.Background(), ctx), omciMessage) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1666 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1667 | return olterrors.NewErrCommunication("omci-send-failed", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1668 | "intf-id": intfID, |
| 1669 | "onu-id": onuID, |
| 1670 | "message": omciMessage}, err) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1671 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1672 | return nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1675 | 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] | 1676 | 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] | 1677 | if err := dh.resourceMgr[intfID].AddNewOnuGemInfoToCacheAndKvStore(ctx, uint32(onuID), serialNumber); err != nil { |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1678 | 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] | 1679 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1680 | var pir uint32 = 1000000 |
kesavand | 494c208 | 2020-08-31 11:16:12 +0530 | [diff] [blame] | 1681 | 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] | 1682 | if _, err := dh.Client.ActivateOnu(ctx, &Onu); err != nil { |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1683 | st, _ := status.FromError(err) |
| 1684 | if st.Code() == codes.AlreadyExists { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1685 | logger.Debugw(ctx, "onu-activation-in-progress", log.Fields{"SerialNumber": serialNumber, "onu-id": onuID, "device-id": dh.device.Id}) |
| 1686 | |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1687 | } else { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1688 | 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] | 1689 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1690 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1691 | 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] | 1692 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1693 | return nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 1696 | // getChildDevice function can be used in general to get child device, if not found in cache the function will |
| 1697 | // get from core and update the cache and return the child device. |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1698 | func (dh *DeviceHandler) getChildDevice(ctx context.Context, sn string, parentPortNo uint32) *OnuDevice { |
| 1699 | var InCacheOnuDev *OnuDevice |
| 1700 | dh.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool { |
| 1701 | if onuInCache.(*OnuDevice).serialNumber == sn { |
| 1702 | InCacheOnuDev = onuInCache.(*OnuDevice) |
| 1703 | return false |
| 1704 | } |
| 1705 | return true |
| 1706 | }) |
| 1707 | //Got the onu device from cache return |
| 1708 | if InCacheOnuDev != nil { |
| 1709 | logger.Debugw(ctx, "Got child device from cache", log.Fields{"onudev": InCacheOnuDev.serialNumber}) |
| 1710 | return InCacheOnuDev |
| 1711 | } |
| 1712 | onuDevice, _ := dh.getChildDeviceFromCore(ctx, &ca.ChildDeviceFilter{ |
| 1713 | ParentId: dh.device.Id, |
| 1714 | SerialNumber: sn, |
| 1715 | ParentPortNo: parentPortNo, |
| 1716 | }) |
| 1717 | //No device found in core return nil |
| 1718 | if onuDevice == nil { |
| 1719 | return nil |
| 1720 | } |
| 1721 | onuID := onuDevice.ProxyAddress.OnuId |
| 1722 | intfID := plt.PortNoToIntfID(parentPortNo, voltha.Port_PON_OLT) |
| 1723 | onuKey := dh.formOnuKey(intfID, onuID) |
| 1724 | |
| 1725 | onuDev := NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuDevice.ProxyAddress.OnuId, intfID, onuDevice.ProxyAddress.DeviceId, false, onuDevice.AdapterEndpoint) |
| 1726 | dh.onus.Store(onuKey, onuDev) |
| 1727 | logger.Debugw(ctx, "got child device from core", log.Fields{"onudev": onuDevice}) |
| 1728 | return onuDev |
| 1729 | } |
| 1730 | |
| 1731 | func (dh *DeviceHandler) checkForResourceExistance(ctx context.Context, onuDiscInd *oop.OnuDiscIndication, sn string) (bool, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1732 | channelID := onuDiscInd.GetIntfId() |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1733 | parentPortNo := plt.IntfIDToPortNo(onuDiscInd.GetIntfId(), voltha.Port_PON_OLT) |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1734 | tpInstExists := false |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 1735 | |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1736 | //CheckOnuDevExistenceAtOnuDiscovery if true , a check will be made for the existence of the onu device. If the onu device |
| 1737 | // still exists , the onu discovery will be ignored, else a check for active techprofiles for ONU is checked. |
| 1738 | if !dh.openOLT.CheckOnuDevExistenceAtOnuDiscovery { |
| 1739 | onuDev := dh.getChildDevice(ctx, sn, parentPortNo) |
| 1740 | if onuDev != nil { |
| 1741 | var onuGemInfo *rsrcMgr.OnuGemInfo |
| 1742 | var err error |
| 1743 | if onuGemInfo, err = dh.resourceMgr[channelID].GetOnuGemInfo(ctx, onuDev.onuID); err != nil { |
| 1744 | logger.Warnw(ctx, "Unable to find onuGemInfo", log.Fields{"onuID": onuDev.onuID}) |
| 1745 | return false, err |
| 1746 | } |
| 1747 | if onuGemInfo != nil { |
| 1748 | for _, uni := range onuGemInfo.UniPorts { |
| 1749 | uniID := plt.UniIDFromPortNum(uni) |
| 1750 | tpIDs := dh.resourceMgr[channelID].GetTechProfileIDForOnu(ctx, onuDev.onuID, uniID) |
| 1751 | if len(tpIDs) != 0 { |
| 1752 | logger.Warnw(ctx, "Techprofile present for ONU, ignoring onu discovery", log.Fields{"onuID": onuDev.onuID}) |
| 1753 | tpInstExists = true |
| 1754 | break |
| 1755 | } |
| 1756 | } |
| 1757 | } |
| 1758 | } |
| 1759 | return tpInstExists, nil |
| 1760 | } |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1761 | |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1762 | onuDevice, _ := dh.getChildDeviceFromCore(ctx, &ca.ChildDeviceFilter{ |
| 1763 | ParentId: dh.device.Id, |
| 1764 | SerialNumber: sn, |
| 1765 | ParentPortNo: parentPortNo, |
| 1766 | }) |
| 1767 | if onuDevice != nil { |
| 1768 | logger.Infow(ctx, "Child device still present ignoring discovery indication", log.Fields{"sn": sn}) |
| 1769 | return true, nil |
| 1770 | } |
| 1771 | logger.Infow(ctx, "No device present in core , continuing with discovery", log.Fields{"sn": sn}) |
| 1772 | |
| 1773 | return false, nil |
| 1774 | |
| 1775 | } |
| 1776 | |
Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 1777 | // processDiscONULOSClear clears the LOS Alarm if it's needed |
| 1778 | func (dh *DeviceHandler) processDiscONULOSClear(ctx context.Context, onuDiscInd *oop.OnuDiscIndication, sn string) { |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 1779 | var alarmInd oop.OnuAlarmIndication |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 1780 | raisedTs := time.Now().Unix() |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 1781 | |
Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 1782 | /* When PON cable disconnected and connected back from OLT, it was expected OnuAlarmIndication |
| 1783 | with "los_status: off" should be raised but BAL does not raise this Alarm hence manually sending |
| 1784 | OnuLosClear event on receiving OnuDiscoveryIndication for the Onu after checking whether |
| 1785 | OnuLosRaise event sent for it */ |
| 1786 | dh.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool { |
| 1787 | if onuInCache.(*OnuDevice).serialNumber == sn && onuInCache.(*OnuDevice).losRaised { |
| 1788 | if onuDiscInd.GetIntfId() != onuInCache.(*OnuDevice).intfID { |
| 1789 | logger.Warnw(ctx, "onu-is-on-a-different-intf-id-now", log.Fields{ |
| 1790 | "previousIntfId": onuInCache.(*OnuDevice).intfID, |
| 1791 | "currentIntfId": onuDiscInd.GetIntfId()}) |
| 1792 | // TODO:: Should we need to ignore raising OnuLosClear event |
| 1793 | // when onu connected to different PON? |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 1794 | } |
Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 1795 | alarmInd.IntfId = onuInCache.(*OnuDevice).intfID |
| 1796 | alarmInd.OnuId = onuInCache.(*OnuDevice).onuID |
| 1797 | alarmInd.LosStatus = statusCheckOff |
| 1798 | go func() { |
| 1799 | if err := dh.eventMgr.onuAlarmIndication(ctx, &alarmInd, onuInCache.(*OnuDevice).deviceID, raisedTs); err != nil { |
| 1800 | logger.Errorw(ctx, "indication-failed", log.Fields{"err": err}) |
| 1801 | } |
| 1802 | }() |
| 1803 | // stop iterating |
| 1804 | return false |
| 1805 | } |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1806 | return true |
Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 1807 | }) |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | func (dh *DeviceHandler) onuDiscIndication(ctx context.Context, onuDiscInd *oop.OnuDiscIndication) error { |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1811 | var error error |
| 1812 | |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1813 | channelID := onuDiscInd.GetIntfId() |
| 1814 | parentPortNo := plt.IntfIDToPortNo(onuDiscInd.GetIntfId(), voltha.Port_PON_OLT) |
| 1815 | |
| 1816 | sn := dh.stringifySerialNumber(onuDiscInd.SerialNumber) |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1817 | defer func() { |
| 1818 | if error != nil { |
| 1819 | logger.Infow(ctx, "onu-processing-errored-out-not-adding-to-discovery-map", log.Fields{"sn": sn}) |
| 1820 | } else { |
| 1821 | // once the function completes set the value to false so that |
| 1822 | // we know the processing has inProcess. |
| 1823 | // Note that this is done after checking if we are already processing |
| 1824 | // to avoid changing the value from a different thread |
| 1825 | logger.Infow(ctx, "onu-processing-completed", log.Fields{"sn": sn}) |
| 1826 | dh.discOnus.Store(sn, false) |
| 1827 | } |
| 1828 | }() |
| 1829 | |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1830 | logger.Infow(ctx, "new-discovery-indication", log.Fields{"sn": sn}) |
| 1831 | |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1832 | tpInstExists, error := dh.checkForResourceExistance(ctx, onuDiscInd, sn) |
| 1833 | if error != nil { |
| 1834 | return error |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1835 | } |
| 1836 | if tpInstExists { |
| 1837 | //ignore the discovery if tpinstance is present. |
Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 1838 | logger.Debugw(ctx, "ignoring-onu-indication-as-tp-already-exists", log.Fields{"sn": sn}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1839 | return nil |
Amit Ghosh | e5c6a85 | 2020-02-10 15:09:46 +0000 | [diff] [blame] | 1840 | } |
Matteo Scandolo | 7eaec53 | 2022-06-23 15:54:57 -0700 | [diff] [blame] | 1841 | inProcess, existing := dh.discOnus.LoadOrStore(sn, true) |
| 1842 | |
| 1843 | // if the ONU existed, handle the LOS Alarm |
| 1844 | if existing { |
| 1845 | |
| 1846 | if inProcess.(bool) { |
| 1847 | // if we're currently processing the ONU on a different thread, do nothing |
| 1848 | logger.Warnw(ctx, "onu-sn-is-being-processed", log.Fields{"sn": sn}) |
| 1849 | return nil |
| 1850 | } |
| 1851 | // if we had dealt with this ONU before, but the process didn't complete (this happens in case of errors) |
| 1852 | // then continue processing it |
| 1853 | logger.Debugw(ctx, "onu-processing-had-completed-but-new-indication", log.Fields{"sn": sn}) |
| 1854 | |
| 1855 | dh.processDiscONULOSClear(ctx, onuDiscInd, sn) |
serkantul | e333d15 | 2022-10-12 01:44:00 +0300 | [diff] [blame] | 1856 | return nil |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1857 | } |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 1858 | var onuID uint32 |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1859 | |
| 1860 | // check the ONU is already know to the OLT |
| 1861 | // 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] | 1862 | onuDevice, error := dh.getChildDeviceFromCore(ctx, &ca.ChildDeviceFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1863 | ParentId: dh.device.Id, |
| 1864 | SerialNumber: sn, |
| 1865 | }) |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1866 | |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1867 | if error != nil { |
| 1868 | logger.Debugw(ctx, "core-proxy-get-child-device-failed", log.Fields{"parentDevice": dh.device.Id, "err": error, "sn": sn}) |
| 1869 | if e, ok := status.FromError(error); ok { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1870 | 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] | 1871 | switch e.Code() { |
| 1872 | case codes.Internal: |
| 1873 | // this probably means NOT FOUND, so just create a new device |
| 1874 | onuDevice = nil |
| 1875 | case codes.DeadlineExceeded: |
| 1876 | // if the call times out, cleanup and exit |
| 1877 | dh.discOnus.Delete(sn) |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1878 | error = olterrors.NewErrTimeout("get-child-device", log.Fields{"device-id": dh.device.Id}, error) |
| 1879 | return error |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1880 | } |
| 1881 | } |
| 1882 | } |
| 1883 | |
| 1884 | if onuDevice == nil { |
| 1885 | // 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] | 1886 | logger.Debugw(ctx, "creating-new-onu", log.Fields{"sn": sn}) |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1887 | // we need to create a new ChildDevice |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 1888 | ponintfid := onuDiscInd.GetIntfId() |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1889 | onuID, error = dh.resourceMgr[ponintfid].GetONUID(ctx) |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 1890 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1891 | 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] | 1892 | |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1893 | if error != nil { |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1894 | // if we can't create an ID in resource manager, |
| 1895 | // cleanup and exit |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1896 | dh.discOnus.Delete(sn) |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1897 | |
| 1898 | error = olterrors.NewErrAdapter("resource-manager-get-onu-id-failed", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1899 | "pon-intf-id": ponintfid, |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1900 | "serial-number": sn}, error) |
| 1901 | return error |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1902 | } |
| 1903 | |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1904 | if onuDevice, error = dh.sendChildDeviceDetectedToCore(ctx, &ca.DeviceDiscovery{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1905 | ParentId: dh.device.Id, |
| 1906 | ParentPortNo: parentPortNo, |
| 1907 | ChannelId: channelID, |
| 1908 | VendorId: string(onuDiscInd.SerialNumber.GetVendorId()), |
| 1909 | SerialNumber: sn, |
| 1910 | OnuId: onuID, |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1911 | }); error != nil { |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1912 | dh.discOnus.Delete(sn) |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1913 | 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] | 1914 | |
| 1915 | error = olterrors.NewErrAdapter("core-proxy-child-device-detected-failed", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1916 | "pon-intf-id": ponintfid, |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1917 | "serial-number": sn}, error) |
| 1918 | return error |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1919 | } |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1920 | if error := dh.eventMgr.OnuDiscoveryIndication(ctx, onuDiscInd, dh.device.Id, onuDevice.Id, onuID, sn, time.Now().Unix()); error != nil { |
| 1921 | logger.Error(ctx, "discovery-indication-failed", log.Fields{"err": error}) |
| 1922 | error = olterrors.NewErrAdapter("discovery-indication-failed", log.Fields{ |
| 1923 | "onu-id": onuID, |
| 1924 | "device-id": dh.device.Id, |
| 1925 | "serial-number": sn}, error) |
| 1926 | return error |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1927 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1928 | logger.Infow(ctx, "onu-child-device-added", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1929 | log.Fields{"onuDevice": onuDevice, |
| 1930 | "sn": sn, |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1931 | "onu-id": onuID, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1932 | "device-id": dh.device.Id}) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1933 | } |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1934 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1935 | // Setup the gRPC connection to the adapter responsible for that onuDevice, if not setup yet |
| 1936 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1937 | error = dh.setupChildInterAdapterClient(subCtx, onuDevice.AdapterEndpoint) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1938 | cancel() |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1939 | if error != nil { |
| 1940 | |
| 1941 | error = olterrors.NewErrCommunication("no-connection-to-child-adapter", log.Fields{"device-id": onuDevice.Id}, error) |
| 1942 | return error |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1943 | } |
| 1944 | |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1945 | // we can now use the existing ONU Id |
| 1946 | onuID = onuDevice.ProxyAddress.OnuId |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1947 | //Insert the ONU into cache to use in OnuIndication. |
| 1948 | //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] | 1949 | logger.Debugw(ctx, "onu-discovery-indication-key-create", |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1950 | log.Fields{"onu-id": onuID, |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1951 | "intfId": onuDiscInd.GetIntfId(), |
| 1952 | "sn": sn}) |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1953 | onuKey := dh.formOnuKey(onuDiscInd.GetIntfId(), onuID) |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 1954 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1955 | 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] | 1956 | dh.onus.Store(onuKey, onuDev) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1957 | logger.Debugw(ctx, "new-onu-device-discovered", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1958 | log.Fields{"onu": onuDev, |
| 1959 | "sn": sn}) |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 1960 | |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1961 | if error = dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1962 | DeviceId: onuDevice.Id, |
| 1963 | ParentDeviceId: dh.device.Id, |
| 1964 | OperStatus: common.OperStatus_DISCOVERED, |
| 1965 | ConnStatus: common.ConnectStatus_REACHABLE, |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1966 | }); error != nil { |
| 1967 | |
| 1968 | error = olterrors.NewErrAdapter("failed-to-update-device-state", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1969 | "device-id": onuDevice.Id, |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1970 | "serial-number": sn}, error) |
| 1971 | return error |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1972 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1973 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1974 | 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] | 1975 | if error = dh.activateONU(ctx, onuDiscInd.IntfId, int64(onuID), onuDiscInd.SerialNumber, sn); error != nil { |
| 1976 | |
| 1977 | error = olterrors.NewErrAdapter("onu-activation-failed", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1978 | "device-id": onuDevice.Id, |
nikesh.krishnan | 3099ac1 | 2023-10-06 14:37:21 +0530 | [diff] [blame] | 1979 | "serial-number": sn}, error) |
| 1980 | return error |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1981 | } |
| 1982 | return nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 1985 | func (dh *DeviceHandler) onuIndication(ctx context.Context, onuInd *oop.OnuIndication) error { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1986 | |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1987 | ponPort := plt.IntfIDToPortNo(onuInd.GetIntfId(), voltha.Port_PON_OLT) |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1988 | var onuDevice *voltha.Device |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1989 | var err error |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1990 | foundInCache := false |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1991 | logger.Debugw(ctx, "onu-indication-key-create", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1992 | log.Fields{"onuId": onuInd.OnuId, |
| 1993 | "intfId": onuInd.GetIntfId(), |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1994 | "device-id": dh.device.Id}) |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1995 | onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.OnuId) |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 1996 | serialNumber := dh.stringifySerialNumber(onuInd.SerialNumber) |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1997 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1998 | errFields := log.Fields{"device-id": dh.device.Id} |
| 1999 | |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 2000 | if onuInCache, ok := dh.onus.Load(onuKey); ok { |
| 2001 | |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2002 | //If ONU id is discovered before then use GetDevice to get onuDevice because it is cheaper. |
| 2003 | foundInCache = true |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2004 | errFields["onu-id"] = onuInCache.(*OnuDevice).deviceID |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2005 | onuDevice, err = dh.getDeviceFromCore(ctx, onuInCache.(*OnuDevice).deviceID) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2006 | } else { |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2007 | //If ONU not found in adapter cache then we have to use GetChildDevice to get onuDevice |
| 2008 | if serialNumber != "" { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2009 | errFields["serial-number"] = serialNumber |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2010 | } else { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2011 | errFields["onu-id"] = onuInd.OnuId |
| 2012 | errFields["parent-port-no"] = ponPort |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2013 | } |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2014 | onuDevice, err = dh.getChildDeviceFromCore(ctx, &ca.ChildDeviceFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2015 | ParentId: dh.device.Id, |
| 2016 | SerialNumber: serialNumber, |
| 2017 | OnuId: onuInd.OnuId, |
| 2018 | ParentPortNo: ponPort, |
| 2019 | }) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2020 | } |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 2021 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2022 | if err != nil || onuDevice == nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2023 | return olterrors.NewErrNotFound("onu-device", errFields, err) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2026 | if onuDevice.ParentPortNo != ponPort { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2027 | 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] | 2028 | "previousIntfId": onuDevice.ParentPortNo, |
| 2029 | "currentIntfId": ponPort}) |
| 2030 | } |
| 2031 | |
| 2032 | if onuDevice.ProxyAddress.OnuId != onuInd.OnuId { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2033 | 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] | 2034 | "expected-onu-id": onuDevice.ProxyAddress.OnuId, |
| 2035 | "received-onu-id": onuInd.OnuId, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2036 | "device-id": dh.device.Id}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2037 | } |
| 2038 | if !foundInCache { |
| 2039 | onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.GetOnuId()) |
| 2040 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2041 | 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] | 2042 | |
| 2043 | } |
kesavand | 7cf3a05 | 2020-08-28 12:49:18 +0530 | [diff] [blame] | 2044 | 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] | 2045 | 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] | 2046 | logger.Warnw(ctx, "onu-activation-indication-reporting-failed", log.Fields{"err": err}) |
kesavand | 7cf3a05 | 2020-08-28 12:49:18 +0530 | [diff] [blame] | 2047 | } |
| 2048 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2049 | if err := dh.updateOnuStates(ctx, onuDevice, onuInd); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2050 | return olterrors.NewErrCommunication("state-update-failed", errFields, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2051 | } |
| 2052 | return nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2055 | 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] | 2056 | 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] | 2057 | if onuInd.AdminState == "down" || onuInd.OperState == "down" { |
| 2058 | // The ONU has gone admin_state "down" or oper_state "down" - we expect the ONU to send discovery again |
| 2059 | // The ONU admin_state is "up" while "oper_state" is down in cases where ONU activation fails. In this case |
| 2060 | // the ONU sends Discovery again. |
Girish Gowdra | 429f950 | 2020-05-04 13:22:16 -0700 | [diff] [blame] | 2061 | dh.discOnus.Delete(onuDevice.SerialNumber) |
Amit Ghosh | 9bbc565 | 2020-02-17 13:37:32 +0000 | [diff] [blame] | 2062 | // Tests have shown that we sometimes get OperState as NOT down even if AdminState is down, forcing it |
| 2063 | if onuInd.OperState != "down" { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2064 | logger.Warnw(ctx, "onu-admin-state-down", log.Fields{"operState": onuInd.OperState}) |
Amit Ghosh | 9bbc565 | 2020-02-17 13:37:32 +0000 | [diff] [blame] | 2065 | onuInd.OperState = "down" |
| 2066 | } |
| 2067 | } |
| 2068 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2069 | switch onuInd.OperState { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2070 | case "up", "down": |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2071 | 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] | 2072 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2073 | err := dh.sendOnuIndicationToChildAdapter(ctx, onuDevice.AdapterEndpoint, &ia.OnuIndicationMessage{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2074 | DeviceId: onuDevice.Id, |
| 2075 | OnuIndication: onuInd, |
| 2076 | }) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2077 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2078 | return olterrors.NewErrCommunication("inter-adapter-send-failed", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2079 | "onu-indicator": onuInd, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2080 | "source": dh.openOLT.config.AdapterEndpoint, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2081 | "device-type": onuDevice.Type, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2082 | "device-id": onuDevice.Id}, err) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2083 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2084 | default: |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2085 | return olterrors.NewErrInvalidValue(log.Fields{"oper-state": onuInd.OperState}, nil) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2086 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2087 | return nil |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2090 | func (dh *DeviceHandler) stringifySerialNumber(serialNum *oop.SerialNumber) string { |
| 2091 | if serialNum != nil { |
| 2092 | return string(serialNum.VendorId) + dh.stringifyVendorSpecific(serialNum.VendorSpecific) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2093 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2094 | return "" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2095 | } |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 2096 | func (dh *DeviceHandler) deStringifySerialNumber(serialNum string) (*oop.SerialNumber, error) { |
| 2097 | decodedStr, err := hex.DecodeString(serialNum[4:]) |
| 2098 | if err != nil { |
| 2099 | return nil, err |
| 2100 | } |
| 2101 | return &oop.SerialNumber{ |
| 2102 | VendorId: []byte(serialNum[:4]), |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2103 | VendorSpecific: decodedStr, |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 2104 | }, nil |
| 2105 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2106 | |
| 2107 | func (dh *DeviceHandler) stringifyVendorSpecific(vendorSpecific []byte) string { |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2108 | if len(vendorSpecific) > 3 { |
| 2109 | tmp := fmt.Sprintf("%x", (uint32(vendorSpecific[0])>>4)&0x0f) + |
| 2110 | fmt.Sprintf("%x", uint32(vendorSpecific[0]&0x0f)) + |
| 2111 | fmt.Sprintf("%x", (uint32(vendorSpecific[1])>>4)&0x0f) + |
| 2112 | fmt.Sprintf("%x", (uint32(vendorSpecific[1]))&0x0f) + |
| 2113 | fmt.Sprintf("%x", (uint32(vendorSpecific[2])>>4)&0x0f) + |
| 2114 | fmt.Sprintf("%x", (uint32(vendorSpecific[2]))&0x0f) + |
| 2115 | fmt.Sprintf("%x", (uint32(vendorSpecific[3])>>4)&0x0f) + |
| 2116 | fmt.Sprintf("%x", (uint32(vendorSpecific[3]))&0x0f) |
| 2117 | return tmp |
| 2118 | } |
| 2119 | return "" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2122 | // UpdateFlowsBulk upates the bulk flow |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2123 | func (dh *DeviceHandler) UpdateFlowsBulk() error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2124 | return olterrors.ErrNotImplemented |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 2125 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2126 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2127 | // GetChildDevice returns the child device for given parent port and onu id |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2128 | func (dh *DeviceHandler) GetChildDevice(ctx context.Context, parentPort, onuID uint32) (*voltha.Device, error) { |
| 2129 | logger.Debugw(ctx, "getchilddevice", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2130 | log.Fields{"pon-port": parentPort, |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2131 | "onu-id": onuID, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2132 | "device-id": dh.device.Id}) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2133 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2134 | onuDevice, err := dh.getChildDeviceFromCore(ctx, &ca.ChildDeviceFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2135 | ParentId: dh.device.Id, |
| 2136 | OnuId: onuID, |
| 2137 | ParentPortNo: parentPort, |
| 2138 | }) |
| 2139 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 2140 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2141 | return nil, olterrors.NewErrNotFound("onu-device", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2142 | "intf-id": parentPort, |
| 2143 | "onu-id": onuID}, err) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 2144 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2145 | 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] | 2146 | return onuDevice, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2147 | } |
| 2148 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2149 | // SendPacketInToCore sends packet-in to core |
| 2150 | // For this, it calls SendPacketIn of the core-proxy which uses a device specific topic to send the request. |
| 2151 | // The adapter handling the device creates a device specific topic |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2152 | func (dh *DeviceHandler) SendPacketInToCore(ctx context.Context, logicalPort uint32, packetPayload []byte) error { |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2153 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2154 | logger.Debugw(ctx, "send-packet-in-to-core", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2155 | "port": logicalPort, |
| 2156 | "packet": hex.EncodeToString(packetPayload), |
| 2157 | "device-id": dh.device.Id, |
| 2158 | }) |
| 2159 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2160 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2161 | if err := dh.sendPacketToCore(ctx, &ca.PacketIn{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2162 | DeviceId: dh.device.Id, |
| 2163 | Port: logicalPort, |
| 2164 | Packet: packetPayload, |
| 2165 | }); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2166 | return olterrors.NewErrCommunication("packet-send-failed", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2167 | "source": "adapter", |
| 2168 | "destination": "core", |
| 2169 | "device-id": dh.device.Id, |
| 2170 | "logical-port": logicalPort, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2171 | "packet": hex.EncodeToString(packetPayload)}, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2172 | } |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2173 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2174 | logger.Debugw(ctx, "sent-packet-in-to-core-successfully", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2175 | "packet": hex.EncodeToString(packetPayload), |
| 2176 | "device-id": dh.device.Id, |
| 2177 | }) |
| 2178 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2179 | return nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2180 | } |
| 2181 | |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 2182 | // UpdatePmConfig updates the pm metrics. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2183 | func (dh *DeviceHandler) UpdatePmConfig(ctx context.Context, pmConfigs *voltha.PmConfigs) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2184 | 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] | 2185 | |
| 2186 | if pmConfigs.DefaultFreq != dh.metrics.ToPmConfigs().DefaultFreq { |
| 2187 | dh.metrics.UpdateFrequency(pmConfigs.DefaultFreq) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2188 | logger.Debugf(ctx, "frequency-updated") |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 2189 | } |
| 2190 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2191 | if !pmConfigs.Grouped { |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 2192 | metrics := dh.metrics.GetSubscriberMetrics() |
| 2193 | for _, m := range pmConfigs.Metrics { |
| 2194 | metrics[m.Name].Enabled = m.Enabled |
| 2195 | |
| 2196 | } |
| 2197 | } |
| 2198 | } |
| 2199 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2200 | 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] | 2201 | var err error |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2202 | var errorsList []error |
| 2203 | |
Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2204 | if dh.getDeviceDeletionInProgressFlag() { |
| 2205 | // The device itself is going to be reset as part of deletion. So nothing to be done. |
| 2206 | logger.Infow(ctx, "device-deletion-in-progress--not-handling-flows-or-groups", log.Fields{"device-id": device.Id}) |
| 2207 | return nil |
| 2208 | } |
| 2209 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 2210 | if flows != nil { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2211 | for _, flow := range flows.ToRemove.Items { |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2212 | intfID := dh.getIntfIDFromFlow(ctx, flow) |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2213 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2214 | logger.Debugw(ctx, "removing-flow", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2215 | log.Fields{"device-id": device.Id, |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2216 | "intfId": intfID, |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2217 | "flowToRemove": flow}) |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2218 | if flow_utils.HasGroup(flow) { |
| 2219 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, flow, nil, McastFlowOrGroupRemove) |
| 2220 | } else { |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2221 | if dh.flowMgr == nil || dh.flowMgr[intfID] == nil { |
| 2222 | err = fmt.Errorf("flow-manager-uninitialized-%v", device.Id) |
| 2223 | } else { |
| 2224 | err = dh.flowMgr[intfID].RouteFlowToOnuChannel(ctx, flow, false, nil) |
| 2225 | } |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2226 | } |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2227 | if err != nil { |
Elia Battiston | 2aaf434 | 2022-02-07 15:16:38 +0100 | [diff] [blame] | 2228 | if werr, ok := err.(olterrors.WrappedError); ok && status.Code(werr.Unwrap()) == codes.NotFound { |
| 2229 | //The flow we want to remove is not there, there is no need to throw an error |
| 2230 | logger.Warnw(ctx, "flow-to-remove-not-found", |
| 2231 | log.Fields{ |
| 2232 | "ponIf": intfID, |
| 2233 | "flowToRemove": flow, |
| 2234 | "error": err, |
| 2235 | }) |
| 2236 | } else { |
| 2237 | errorsList = append(errorsList, err) |
| 2238 | } |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2239 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2240 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2241 | |
| 2242 | for _, flow := range flows.ToAdd.Items { |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2243 | intfID := dh.getIntfIDFromFlow(ctx, flow) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2244 | logger.Debugw(ctx, "adding-flow", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2245 | log.Fields{"device-id": device.Id, |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2246 | "ponIf": intfID, |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2247 | "flowToAdd": flow}) |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2248 | if flow_utils.HasGroup(flow) { |
| 2249 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, flow, nil, McastFlowOrGroupAdd) |
| 2250 | } else { |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2251 | if dh.flowMgr == nil || dh.flowMgr[intfID] == nil { |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 2252 | // The flow manager module could be uninitialized if the flow arrives too soon before the device has reconciled fully |
| 2253 | logger.Errorw(ctx, "flow-manager-uninitialized", log.Fields{"device-id": device.Id}) |
| 2254 | err = fmt.Errorf("flow-manager-uninitialized-%v", device.Id) |
| 2255 | } else { |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2256 | err = dh.flowMgr[intfID].RouteFlowToOnuChannel(ctx, flow, true, flowMetadata) |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 2257 | } |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2258 | } |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2259 | if err != nil { |
| 2260 | errorsList = append(errorsList, err) |
| 2261 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2262 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 2263 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2264 | |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 2265 | return errorsList |
| 2266 | } |
| 2267 | |
| 2268 | func (dh *DeviceHandler) handleGroups(ctx context.Context, groups *of.FlowGroupChanges) []error { |
| 2269 | var err error |
| 2270 | var errorsList []error |
| 2271 | |
Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2272 | if dh.getDeviceDeletionInProgressFlag() { |
| 2273 | // The device itself is going to be reset as part of deletion. So nothing to be done. |
| 2274 | logger.Infow(ctx, "device-deletion-in-progress--not-handling-flows-or-groups", log.Fields{"device-id": dh.device.Id}) |
| 2275 | return nil |
| 2276 | } |
| 2277 | |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2278 | // 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] | 2279 | if groups != nil { |
| 2280 | for _, group := range groups.ToAdd.Items { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2281 | // err = dh.groupMgr.AddGroup(ctx, group) |
| 2282 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, nil, group, McastFlowOrGroupAdd) |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2283 | if err != nil { |
| 2284 | errorsList = append(errorsList, err) |
| 2285 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2286 | } |
| 2287 | for _, group := range groups.ToUpdate.Items { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2288 | // err = dh.groupMgr.ModifyGroup(ctx, group) |
| 2289 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, nil, group, McastFlowOrGroupModify) |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2290 | if err != nil { |
| 2291 | errorsList = append(errorsList, err) |
| 2292 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2293 | } |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 2294 | for _, group := range groups.ToRemove.Items { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2295 | // err = dh.groupMgr.DeleteGroup(ctx, group) |
| 2296 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, nil, group, McastFlowOrGroupRemove) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 2297 | if err != nil { |
| 2298 | errorsList = append(errorsList, err) |
| 2299 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2300 | } |
| 2301 | } |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 2302 | |
| 2303 | return errorsList |
| 2304 | } |
| 2305 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2306 | // UpdateFlowsIncrementally updates the device flow |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2307 | 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] | 2308 | |
| 2309 | var errorsList []error |
Girish Gowdra | 950326e | 2021-11-05 12:43:24 -0700 | [diff] [blame] | 2310 | |
| 2311 | if dh.getDeviceDeletionInProgressFlag() { |
| 2312 | // The device itself is going to be reset as part of deletion. So nothing to be done. |
| 2313 | logger.Infow(ctx, "device-deletion-in-progress--not-handling-flows-or-groups", log.Fields{"device-id": device.Id}) |
| 2314 | return nil |
| 2315 | } |
nikesh.krishnan | 0897d47 | 2023-09-05 18:35:08 +0530 | [diff] [blame] | 2316 | if dh.transitionMap.currentDeviceState != deviceStateUp { |
| 2317 | logger.Error(ctx, "device-is-not-up--not-handling-flows-or-groups", log.Fields{"device-id": device.Id, "current-device-state": dh.transitionMap.currentDeviceState}) |
| 2318 | return fmt.Errorf("device-is-not-up--not-handling-flows-or-groups") |
| 2319 | } |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 2320 | logger.Debugw(ctx, "received-incremental-flowupdate-in-device-handler", log.Fields{"device-id": device.Id, "flows": flows, "groups": groups, "flowMetadata": flowMetadata}) |
| 2321 | errorsList = append(errorsList, dh.handleFlows(ctx, device, flows, flowMetadata)...) |
| 2322 | errorsList = append(errorsList, dh.handleGroups(ctx, groups)...) |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2323 | if len(errorsList) > 0 { |
| 2324 | return fmt.Errorf("errors-installing-flows-groups, errors:%v", errorsList) |
| 2325 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2326 | 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] | 2327 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2328 | } |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2329 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2330 | // DisableDevice disables the given device |
| 2331 | // It marks the following for the given device: |
| 2332 | // Device-Handler Admin-State : down |
| 2333 | // Device Port-State: UNKNOWN |
| 2334 | // Device Oper-State: UNKNOWN |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2335 | func (dh *DeviceHandler) DisableDevice(ctx context.Context, device *voltha.Device) error { |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 2336 | /* On device disable ,admin state update has to be done prior sending request to agent since |
| 2337 | the indication thread may processes invalid indications of ONU and OLT*/ |
Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 2338 | if dh.Client != nil { |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 2339 | 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] | 2340 | if e, ok := status.FromError(err); ok && e.Code() == codes.Internal { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2341 | 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] | 2342 | } |
Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2343 | } |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 2344 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2345 | logger.Debugw(ctx, "olt-disabled", log.Fields{"device-id": device.Id}) |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 2346 | /* 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] | 2347 | UNREACHABLE state which needs to be configured again*/ |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 2348 | |
| 2349 | dh.discOnus = sync.Map{} |
| 2350 | dh.onus = sync.Map{} |
| 2351 | |
Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 2352 | dh.lockDevice.RLock() |
Thomas Lee S | 85f3731 | 2020-04-03 17:06:12 +0530 | [diff] [blame] | 2353 | //stopping the stats collector |
Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 2354 | if dh.isCollectorActive { |
| 2355 | dh.stopCollector <- true |
| 2356 | } |
| 2357 | dh.lockDevice.RUnlock() |
Thomas Lee S | 85f3731 | 2020-04-03 17:06:12 +0530 | [diff] [blame] | 2358 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2359 | go dh.notifyChildDevices(ctx, "unreachable") |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2360 | cloned := proto.Clone(device).(*voltha.Device) |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2361 | //Update device Admin state |
| 2362 | dh.device = cloned |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2363 | |
kdarapu | 1afeceb | 2020-02-12 01:38:09 -0500 | [diff] [blame] | 2364 | // 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] | 2365 | if err := dh.updatePortsStateInCore(ctx, &ca.PortStateFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2366 | DeviceId: cloned.Id, |
| 2367 | PortTypeFilter: ^uint32(1 << voltha.Port_PON_OLT), |
| 2368 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2369 | }); err != nil { |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 2370 | 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] | 2371 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2372 | logger.Debugw(ctx, "disable-device-end", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2373 | return nil |
| 2374 | } |
| 2375 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2376 | func (dh *DeviceHandler) notifyChildDevices(ctx context.Context, state string) { |
Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2377 | // Update onu state as unreachable in onu adapter |
| 2378 | onuInd := oop.OnuIndication{} |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2379 | onuInd.OperState = state |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2380 | |
Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2381 | //get the child device for the parent device |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2382 | onuDevices, err := dh.getChildDevicesFromCore(ctx, dh.device.Id) |
Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2383 | if err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2384 | 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] | 2385 | } |
| 2386 | if onuDevices != nil { |
| 2387 | for _, onuDevice := range onuDevices.Items { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2388 | err := dh.sendOnuIndicationToChildAdapter(ctx, onuDevice.AdapterEndpoint, &ia.OnuIndicationMessage{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2389 | DeviceId: onuDevice.Id, |
| 2390 | OnuIndication: &onuInd, |
| 2391 | }) |
Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 2392 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2393 | logger.Errorw(ctx, "failed-to-send-inter-adapter-message", log.Fields{"OnuInd": onuInd, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2394 | "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] | 2395 | } |
| 2396 | |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | } |
| 2401 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2402 | // ReenableDevice re-enables the olt device after disable |
| 2403 | // It marks the following for the given device: |
| 2404 | // Device-Handler Admin-State : up |
| 2405 | // Device Port-State: ACTIVE |
| 2406 | // Device Oper-State: ACTIVE |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2407 | func (dh *DeviceHandler) ReenableDevice(ctx context.Context, device *voltha.Device) error { |
nikesh.krishnan | e363ace | 2023-02-28 03:12:38 +0530 | [diff] [blame] | 2408 | if dh.Client != nil { |
| 2409 | if _, err := dh.Client.ReenableOlt(log.WithSpanFromContext(context.Background(), ctx), new(oop.Empty)); err != nil { |
| 2410 | if e, ok := status.FromError(err); ok && e.Code() == codes.Internal { |
| 2411 | return olterrors.NewErrAdapter("olt-reenable-failed", log.Fields{"device-id": dh.device.Id}, err) |
| 2412 | } |
Abhilash Laxmeshwar | 5b302e1 | 2020-01-09 15:15:14 +0530 | [diff] [blame] | 2413 | } |
nikesh.krishnan | e363ace | 2023-02-28 03:12:38 +0530 | [diff] [blame] | 2414 | } else { |
| 2415 | return olterrors.NewErrAdapter("olt-reenable-failed", log.Fields{"device-id": dh.device.Id}, errors.New("nil device client")) |
| 2416 | |
Abhilash Laxmeshwar | 5b302e1 | 2020-01-09 15:15:14 +0530 | [diff] [blame] | 2417 | } |
nikesh.krishnan | e363ace | 2023-02-28 03:12:38 +0530 | [diff] [blame] | 2418 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2419 | logger.Debug(ctx, "olt-reenabled") |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2420 | |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2421 | // Update the all ports state on that device to enable |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2422 | ports, err := dh.listDevicePortsFromCore(ctx, device.Id) |
Mahir Gunyel | e5e807a | 2021-10-22 11:33:25 -0700 | [diff] [blame] | 2423 | var retError error |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 2424 | if err != nil { |
Mahir Gunyel | e5e807a | 2021-10-22 11:33:25 -0700 | [diff] [blame] | 2425 | retError = olterrors.NewErrAdapter("list-ports-failed", log.Fields{"device-id": device.Id}, err) |
| 2426 | } else { |
| 2427 | if err := dh.disableAdminDownPorts(ctx, ports.Items); err != nil { |
| 2428 | retError = olterrors.NewErrAdapter("port-status-update-failed-after-olt-reenable", log.Fields{"device": device}, err) |
| 2429 | } |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 2430 | } |
Mahir Gunyel | e5e807a | 2021-10-22 11:33:25 -0700 | [diff] [blame] | 2431 | if retError == nil { |
| 2432 | //Update the device oper status as ACTIVE |
| 2433 | device.OperStatus = voltha.OperStatus_ACTIVE |
| 2434 | } else { |
| 2435 | //Update the device oper status as FAILED |
| 2436 | device.OperStatus = voltha.OperStatus_FAILED |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2437 | } |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 2438 | dh.device = device |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2439 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2440 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2441 | DeviceId: device.Id, |
| 2442 | OperStatus: device.OperStatus, |
| 2443 | ConnStatus: device.ConnectStatus, |
| 2444 | }); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2445 | return olterrors.NewErrAdapter("state-update-failed", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2446 | "device-id": device.Id, |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 2447 | "connect-status": device.ConnectStatus, |
| 2448 | "oper-status": device.OperStatus}, err) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2449 | } |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2450 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2451 | logger.Debugw(ctx, "reenabledevice-end", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2452 | |
Mahir Gunyel | e5e807a | 2021-10-22 11:33:25 -0700 | [diff] [blame] | 2453 | return retError |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 2454 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2455 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2456 | func (dh *DeviceHandler) clearUNIData(ctx context.Context, onu *rsrcMgr.OnuGemInfo) error { |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2457 | var uniID uint32 |
| 2458 | var err error |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2459 | var errs []error |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2460 | for _, port := range onu.UniPorts { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2461 | uniID = plt.UniIDFromPortNum(port) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2462 | 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] | 2463 | /* Delete tech-profile instance from the KV store */ |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2464 | if dh.flowMgr == nil || dh.flowMgr[onu.IntfID] == nil { |
| 2465 | logger.Debugw(ctx, "failed-to-remove-tech-profile-instance-for-onu-no-flowmng", log.Fields{"onu-id": onu.OnuID}) |
| 2466 | } else { |
| 2467 | if err = dh.flowMgr[onu.IntfID].DeleteTechProfileInstances(ctx, onu.IntfID, onu.OnuID, uniID); err != nil { |
| 2468 | 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] | 2469 | errs = append(errs, err) |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2470 | } |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2471 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2472 | 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] | 2473 | tpIDList := dh.resourceMgr[onu.IntfID].GetTechProfileIDForOnu(ctx, onu.OnuID, uniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2474 | for _, tpID := range tpIDList { |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2475 | 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] | 2476 | 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] | 2477 | errs = append(errs, err) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2478 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2479 | 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] | 2480 | 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] | 2481 | 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] | 2482 | errs = append(errs, err) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2483 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2484 | 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] | 2485 | } |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2486 | dh.resourceMgr[onu.IntfID].FreePONResourcesForONU(ctx, onu.OnuID, uniID) |
| 2487 | 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] | 2488 | 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] | 2489 | errs = append(errs, err) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2490 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2491 | 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] | 2492 | 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] | 2493 | 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] | 2494 | errs = append(errs, err) |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2495 | } |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2496 | } |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2497 | if len(errs) > 0 { |
| 2498 | return olterrors.NewErrAdapter(fmt.Errorf("one-or-more-error-during-clear-uni-data, errors:%v", |
| 2499 | errs).Error(), log.Fields{"device-id": dh.device.Id}, nil) |
| 2500 | } |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2501 | return nil |
| 2502 | } |
| 2503 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2504 | // 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] | 2505 | func (dh *DeviceHandler) DeleteDevice(ctx context.Context, device *voltha.Device) error { |
Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 2506 | 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] | 2507 | /* Clear the KV store data associated with the all the UNI ports |
| 2508 | This clears up flow data and also resource map data for various |
| 2509 | other pon resources like alloc_id and gemport_id |
| 2510 | */ |
Girish Gowdra | 950326e | 2021-11-05 12:43:24 -0700 | [diff] [blame] | 2511 | |
| 2512 | dh.setDeviceDeletionInProgressFlag(true) |
Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 2513 | |
| 2514 | dh.StopAllFlowRoutines(ctx) |
Girish Gowdra | 950326e | 2021-11-05 12:43:24 -0700 | [diff] [blame] | 2515 | |
Himani Chawla | 49a5d56 | 2020-11-25 11:53:44 +0530 | [diff] [blame] | 2516 | dh.lockDevice.RLock() |
Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 2517 | // Stop the Stats collector |
| 2518 | if dh.isCollectorActive { |
| 2519 | dh.stopCollector <- true |
| 2520 | } |
| 2521 | // stop the heartbeat check routine |
| 2522 | if dh.isHeartbeatCheckActive { |
| 2523 | dh.stopHeartbeatCheck <- true |
| 2524 | } |
Himani Chawla | 49a5d56 | 2020-11-25 11:53:44 +0530 | [diff] [blame] | 2525 | // Stop the read indication only if it the routine is active |
| 2526 | if dh.isReadIndicationRoutineActive { |
| 2527 | dh.stopIndications <- true |
| 2528 | } |
| 2529 | dh.lockDevice.RUnlock() |
Akash Soni | 5c76e27 | 2024-01-15 04:09:24 +0530 | [diff] [blame] | 2530 | |
| 2531 | err := dh.cleanupDeviceResources(ctx) |
| 2532 | if err != nil { |
| 2533 | logger.Errorw(ctx, "could-not-remove-device-from-KV-store", log.Fields{"device-id": dh.device.Id, "err": err}) |
| 2534 | } else { |
| 2535 | logger.Debugw(ctx, "successfully-removed-device-from-Resource-manager-KV-store", log.Fields{"device-id": dh.device.Id}) |
| 2536 | } |
| 2537 | |
Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 2538 | dh.removeOnuIndicationChannels(ctx) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2539 | //Reset the state |
| 2540 | if dh.Client != nil { |
| 2541 | if _, err := dh.Client.Reboot(ctx, new(oop.Empty)); err != nil { |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2542 | go func() { |
| 2543 | failureReason := fmt.Sprintf("Failed to reboot during device delete request with error: %s", err.Error()) |
| 2544 | if err = dh.eventMgr.oltRebootFailedEvent(ctx, dh.device.Id, failureReason, time.Now().Unix()); err != nil { |
| 2545 | logger.Errorw(ctx, "on-olt-reboot-failed", log.Fields{"device-id": dh.device.Id, "err": err}) |
| 2546 | } |
| 2547 | }() |
| 2548 | 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] | 2549 | } |
| 2550 | } |
Girish Gowdra | b1caa44 | 2020-10-19 12:24:39 -0700 | [diff] [blame] | 2551 | // There is no need to update the core about operation status and connection status of the OLT. |
| 2552 | // The OLT is getting deleted anyway and the core might have already cleared the OLT device from its DB. |
| 2553 | // So any attempt to update the operation status and connection status of the OLT will result in core throwing an error back, |
| 2554 | // because the device does not exist in DB. |
Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 2555 | |
khenaidoo | 7eb2d67 | 2021-10-22 19:08:50 -0400 | [diff] [blame] | 2556 | // Stop the adapter grpc clients for that parent device |
| 2557 | dh.deleteAdapterClients(ctx) |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2558 | return err |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2559 | } |
Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 2560 | |
| 2561 | // StopAllFlowRoutines stops all flow routines |
| 2562 | func (dh *DeviceHandler) StopAllFlowRoutines(ctx context.Context) { |
| 2563 | var wg sync.WaitGroup |
| 2564 | wg.Add(1) // for the mcast routine below to finish |
| 2565 | go dh.StopAllMcastHandlerRoutines(ctx, &wg) |
| 2566 | for _, flMgr := range dh.flowMgr { |
| 2567 | if flMgr != nil { |
| 2568 | wg.Add(1) // for the flow handler routine below to finish |
| 2569 | go flMgr.StopAllFlowHandlerRoutines(ctx, &wg) |
| 2570 | } |
| 2571 | } |
| 2572 | if !dh.waitForTimeoutOrCompletion(&wg, time.Second*30) { |
| 2573 | logger.Warnw(ctx, "timed out waiting for stopping flow and group handlers", log.Fields{"deviceID": dh.device.Id}) |
| 2574 | } else { |
| 2575 | logger.Infow(ctx, "all flow and group handlers shutdown gracefully", log.Fields{"deviceID": dh.device.Id}) |
| 2576 | } |
| 2577 | } |
| 2578 | |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2579 | func (dh *DeviceHandler) cleanupDeviceResources(ctx context.Context) error { |
| 2580 | var errs []error |
Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 2581 | if dh.resourceMgr != nil { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2582 | var ponPort uint32 |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2583 | for ponPort = 0; ponPort < dh.totalPonPorts; ponPort++ { |
yasin sapli | 9e4c509 | 2022-02-01 13:52:33 +0000 | [diff] [blame] | 2584 | onuGemData := dh.resourceMgr[ponPort].GetOnuGemInfoList(ctx) |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 2585 | for i, onu := range onuGemData { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2586 | logger.Debugw(ctx, "onu-data", log.Fields{"onu": onu}) |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2587 | if err := dh.clearUNIData(ctx, &onuGemData[i]); err != nil { |
| 2588 | errs = append(errs, err) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2589 | } |
| 2590 | } |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2591 | if err := dh.resourceMgr[ponPort].DeleteAllFlowIDsForGemForIntf(ctx); err != nil { |
| 2592 | errs = append(errs, err) |
| 2593 | } |
| 2594 | if err := dh.resourceMgr[ponPort].DeleteAllOnuGemInfoForIntf(ctx); err != nil { |
| 2595 | errs = append(errs, err) |
| 2596 | } |
| 2597 | if err := dh.resourceMgr[ponPort].DeleteMcastQueueForIntf(ctx); err != nil { |
| 2598 | errs = append(errs, err) |
| 2599 | } |
Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 2600 | if err := dh.resourceMgr[ponPort].Delete(ctx, ponPort); err != nil { |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2601 | errs = append(errs, err) |
Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 2602 | } |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2603 | } |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2604 | } |
| 2605 | // Clean up NNI manager's data |
| 2606 | if err := dh.resourceMgr[dh.totalPonPorts].DeleteAllFlowIDsForGemForIntf(ctx); err != nil { |
| 2607 | errs = append(errs, err) |
Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 2608 | } |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2609 | |
Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 2610 | dh.CloseKVClient(ctx) |
| 2611 | |
Girish Gowdra | 0f3190e | 2022-02-11 14:18:28 -0800 | [diff] [blame] | 2612 | // Take one final sweep at cleaning up KV store for the OLT device |
| 2613 | // Clean everything at <base-path-prefix>/openolt/<device-id> |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2614 | if err := dh.kvStore.DeleteWithPrefix(ctx, ""); err != nil { |
| 2615 | errs = append(errs, err) |
Girish Gowdra | 0f3190e | 2022-02-11 14:18:28 -0800 | [diff] [blame] | 2616 | } |
| 2617 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2618 | /*Delete ONU map for the device*/ |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 2619 | dh.onus.Range(func(key interface{}, value interface{}) bool { |
| 2620 | dh.onus.Delete(key) |
| 2621 | return true |
| 2622 | }) |
| 2623 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2624 | /*Delete discovered ONU map for the device*/ |
| 2625 | dh.discOnus.Range(func(key interface{}, value interface{}) bool { |
| 2626 | dh.discOnus.Delete(key) |
| 2627 | return true |
| 2628 | }) |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 2629 | if len(errs) > 0 { |
| 2630 | return olterrors.NewErrAdapter(fmt.Errorf("one-or-more-error-during-device-delete, errors:%v", |
| 2631 | errs).Error(), log.Fields{"device-id": dh.device.Id}, nil) |
| 2632 | } |
| 2633 | return nil |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 2634 | } |
| 2635 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2636 | // RebootDevice reboots the given device |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2637 | func (dh *DeviceHandler) RebootDevice(ctx context.Context, device *voltha.Device) error { |
nikesh.krishnan | e363ace | 2023-02-28 03:12:38 +0530 | [diff] [blame] | 2638 | if dh.Client != nil { |
| 2639 | if _, err := dh.Client.Reboot(log.WithSpanFromContext(context.Background(), ctx), new(oop.Empty)); err != nil { |
| 2640 | return olterrors.NewErrAdapter("olt-reboot-failed", log.Fields{"device-id": dh.device.Id}, err) |
| 2641 | } |
| 2642 | } else { |
| 2643 | return olterrors.NewErrAdapter("olt-reboot-failed", log.Fields{"device-id": dh.device.Id}, errors.New("nil device client")) |
| 2644 | |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 2645 | } |
nikesh.krishnan | e363ace | 2023-02-28 03:12:38 +0530 | [diff] [blame] | 2646 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2647 | logger.Debugw(ctx, "rebooted-device-successfully", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 2648 | return nil |
| 2649 | } |
| 2650 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2651 | func (dh *DeviceHandler) handlePacketIndication(ctx context.Context, packetIn *oop.PacketIndication) error { |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2652 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2653 | logger.Debugw(ctx, "received-packet-in", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2654 | "packet-indication": *packetIn, |
| 2655 | "device-id": dh.device.Id, |
| 2656 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 2657 | }) |
| 2658 | } |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2659 | if dh.flowMgr == nil || dh.flowMgr[packetIn.IntfId] == nil { |
| 2660 | return olterrors.NewErrNotFound("flow-manager", log.Fields{"intf-id": packetIn.IntfId, "packet": hex.EncodeToString(packetIn.Pkt)}, nil) |
| 2661 | } |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2662 | logicalPortNum, err := dh.flowMgr[packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, packetIn) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2663 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2664 | 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] | 2665 | } |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2666 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2667 | logger.Debugw(ctx, "sending-packet-in-to-core", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2668 | "logical-port-num": logicalPortNum, |
| 2669 | "device-id": dh.device.Id, |
| 2670 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 2671 | }) |
| 2672 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2673 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2674 | if err := dh.sendPacketToCore(ctx, &ca.PacketIn{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2675 | DeviceId: dh.device.Id, |
| 2676 | Port: logicalPortNum, |
| 2677 | Packet: packetIn.Pkt, |
| 2678 | }); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2679 | return olterrors.NewErrCommunication("send-packet-in", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2680 | "destination": "core", |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2681 | "source": dh.device.Type, |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 2682 | "device-id": dh.device.Id, |
| 2683 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 2684 | }, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2685 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2686 | |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2687 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2688 | logger.Debugw(ctx, "success-sending-packet-in-to-core!", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2689 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 2690 | "device-id": dh.device.Id, |
| 2691 | }) |
| 2692 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2693 | return nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2694 | } |
| 2695 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2696 | // PacketOutNNI sends packet-out from VOLTHA to OLT on the NNI provided |
| 2697 | func (dh *DeviceHandler) PacketOutNNI(ctx context.Context, egressPortNo uint32, packet *of.OfpPacketOut) error { |
| 2698 | nniIntfID, err := plt.IntfIDFromNniPortNum(ctx, uint32(egressPortNo)) |
| 2699 | if err != nil { |
| 2700 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 2701 | "egress-nni-port": egressPortNo, |
| 2702 | "device-id": dh.device.Id, |
| 2703 | }, err) |
| 2704 | } |
| 2705 | uplinkPkt := oop.UplinkPacket{IntfId: nniIntfID, Pkt: packet.Data} |
| 2706 | |
| 2707 | if logger.V(log.DebugLevel) { |
| 2708 | logger.Debugw(ctx, "sending-packet-to-nni", log.Fields{ |
| 2709 | "uplink-pkt": uplinkPkt, |
| 2710 | "packet": hex.EncodeToString(packet.Data), |
| 2711 | "device-id": dh.device.Id, |
| 2712 | }) |
| 2713 | } |
| 2714 | |
| 2715 | if _, err := dh.Client.UplinkPacketOut(ctx, &uplinkPkt); err != nil { |
| 2716 | return olterrors.NewErrCommunication("packet-out-to-nni", log.Fields{ |
| 2717 | "packet": hex.EncodeToString(packet.Data), |
| 2718 | "device-id": dh.device.Id, |
| 2719 | }, err) |
| 2720 | } |
| 2721 | return nil |
| 2722 | } |
| 2723 | |
| 2724 | // PacketOutUNI sends packet-out from VOLTHA to OLT on the UNI provided |
| 2725 | func (dh *DeviceHandler) PacketOutUNI(ctx context.Context, egressPortNo uint32, packet *of.OfpPacketOut) error { |
| 2726 | outerEthType := (uint16(packet.Data[12]) << 8) | uint16(packet.Data[13]) |
| 2727 | innerEthType := (uint16(packet.Data[16]) << 8) | uint16(packet.Data[17]) |
| 2728 | if outerEthType == 0x8942 || outerEthType == 0x88cc { |
| 2729 | // Do not packet-out lldp packets on uni port. |
| 2730 | // ONOS has no clue about uni/nni ports, it just packets out on all |
| 2731 | // available ports on the Logical Switch. It should not be interested |
| 2732 | // in the UNI links. |
| 2733 | logger.Debugw(ctx, "dropping-lldp-packet-out-on-uni", log.Fields{ |
| 2734 | "device-id": dh.device.Id, |
| 2735 | }) |
| 2736 | return nil |
| 2737 | } |
| 2738 | if outerEthType == 0x88a8 || outerEthType == 0x8100 { |
| 2739 | if innerEthType == 0x8100 { |
| 2740 | // q-in-q 802.1ad or 802.1q double tagged packet. |
| 2741 | // slice out the outer tag. |
| 2742 | packet.Data = append(packet.Data[:12], packet.Data[16:]...) |
| 2743 | if logger.V(log.DebugLevel) { |
| 2744 | logger.Debugw(ctx, "packet-now-single-tagged", log.Fields{ |
| 2745 | "packet-data": hex.EncodeToString(packet.Data), |
| 2746 | "device-id": dh.device.Id, |
| 2747 | }) |
| 2748 | } |
| 2749 | } |
| 2750 | } |
| 2751 | intfID := plt.IntfIDFromUniPortNum(uint32(egressPortNo)) |
| 2752 | onuID := plt.OnuIDFromPortNum(uint32(egressPortNo)) |
| 2753 | uniID := plt.UniIDFromPortNum(uint32(egressPortNo)) |
| 2754 | var gemPortID uint32 |
| 2755 | err := olterrors.NewErrNotFound("no-flow-manager-found-for-packet-out", log.Fields{"device-id": dh.device.Id}, nil).(error) |
| 2756 | if dh.flowMgr != nil && dh.flowMgr[intfID] != nil { |
| 2757 | gemPortID, err = dh.flowMgr[intfID].GetPacketOutGemPortID(ctx, intfID, onuID, uint32(egressPortNo), packet.Data) |
| 2758 | } |
| 2759 | if err != nil { |
| 2760 | // In this case the openolt agent will receive the gemPortID as 0. |
| 2761 | // The agent tries to retrieve the gemPortID in this case. |
| 2762 | // This may not always succeed at the agent and packetOut may fail. |
| 2763 | logger.Errorw(ctx, "failed-to-retrieve-gemport-id-for-packet-out", log.Fields{ |
| 2764 | "intf-id": intfID, |
| 2765 | "onu-id": onuID, |
| 2766 | "uni-id": uniID, |
| 2767 | "packet": hex.EncodeToString(packet.Data), |
| 2768 | "device-id": dh.device.Id, |
| 2769 | "error": err, |
| 2770 | }) |
| 2771 | } |
| 2772 | |
| 2773 | onuPkt := oop.OnuPacket{IntfId: intfID, OnuId: onuID, PortNo: uint32(egressPortNo), GemportId: gemPortID, Pkt: packet.Data} |
| 2774 | if logger.V(log.DebugLevel) { |
| 2775 | logger.Debugw(ctx, "sending-packet-to-onu", log.Fields{ |
| 2776 | "egress-port-no": egressPortNo, |
| 2777 | "intf-id": intfID, |
| 2778 | "onu-id": onuID, |
| 2779 | "uni-id": uniID, |
| 2780 | "gem-port-id": gemPortID, |
| 2781 | "packet": hex.EncodeToString(packet.Data), |
| 2782 | "device-id": dh.device.Id, |
| 2783 | }) |
| 2784 | } |
| 2785 | |
| 2786 | if _, err := dh.Client.OnuPacketOut(ctx, &onuPkt); err != nil { |
| 2787 | return olterrors.NewErrCommunication("packet-out-send", log.Fields{ |
| 2788 | "source": "adapter", |
| 2789 | "destination": "onu", |
| 2790 | "egress-port-number": egressPortNo, |
| 2791 | "intf-id": intfID, |
| 2792 | "oni-id": onuID, |
| 2793 | "uni-id": uniID, |
| 2794 | "gem-port-id": gemPortID, |
| 2795 | "packet": hex.EncodeToString(packet.Data), |
| 2796 | "device-id": dh.device.Id, |
| 2797 | }, err) |
| 2798 | } |
| 2799 | return nil |
| 2800 | } |
| 2801 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2802 | // PacketOut sends packet-out from VOLTHA to OLT on the egress port provided |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2803 | 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] | 2804 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2805 | logger.Debugw(ctx, "incoming-packet-out", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2806 | "device-id": dh.device.Id, |
| 2807 | "egress-port-no": egressPortNo, |
| 2808 | "pkt-length": len(packet.Data), |
| 2809 | "packet": hex.EncodeToString(packet.Data), |
| 2810 | }) |
| 2811 | } |
Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 2812 | |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2813 | egressPortType := plt.IntfIDToPortTypeName(uint32(egressPortNo)) |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2814 | var err error |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2815 | if egressPortType == voltha.Port_ETHERNET_UNI { |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2816 | err = dh.PacketOutUNI(ctx, egressPortNo, packet) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2817 | } else if egressPortType == voltha.Port_ETHERNET_NNI { |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2818 | err = dh.PacketOutNNI(ctx, egressPortNo, packet) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2819 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2820 | 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] | 2821 | "egress-port-no": egressPortNo, |
Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 2822 | "egressPortType": egressPortType, |
| 2823 | "packet": hex.EncodeToString(packet.Data), |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2824 | "device-id": dh.device.Id, |
Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 2825 | }) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2826 | } |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 2827 | return err |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2828 | } |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 2829 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2830 | func (dh *DeviceHandler) formOnuKey(intfID, onuID uint32) string { |
| 2831 | return "" + strconv.Itoa(int(intfID)) + "." + strconv.Itoa(int(onuID)) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 2832 | } |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2833 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2834 | func startHeartbeatCheck(ctx context.Context, dh *DeviceHandler) { |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 2835 | |
Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 2836 | defer func() { |
| 2837 | dh.lockDevice.Lock() |
| 2838 | dh.isHeartbeatCheckActive = false |
| 2839 | dh.lockDevice.Unlock() |
| 2840 | }() |
| 2841 | |
| 2842 | dh.lockDevice.Lock() |
| 2843 | dh.isHeartbeatCheckActive = true |
| 2844 | dh.lockDevice.Unlock() |
| 2845 | |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2846 | // start the heartbeat check towards the OLT. |
| 2847 | var timerCheck *time.Timer |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2848 | dh.heartbeatSignature = dh.getHeartbeatSignature(ctx) |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2849 | |
| 2850 | for { |
| 2851 | heartbeatTimer := time.NewTimer(dh.openOLT.HeartbeatCheckInterval) |
| 2852 | select { |
| 2853 | case <-heartbeatTimer.C: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 2854 | 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] | 2855 | if heartBeat, err := dh.Client.HeartbeatCheck(ctxWithTimeout, new(oop.Empty)); err != nil { |
Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2856 | logger.Warnw(ctx, "heartbeat-failed", log.Fields{"device-id": dh.device.Id}) |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2857 | if timerCheck == nil { |
| 2858 | // 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] | 2859 | timerCheck = time.AfterFunc(dh.openOLT.HeartbeatFailReportInterval, func() { dh.updateStateUnreachable(ctx) }) |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2860 | } |
| 2861 | } else { |
| 2862 | if timerCheck != nil { |
| 2863 | if timerCheck.Stop() { |
Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2864 | 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] | 2865 | } |
| 2866 | timerCheck = nil |
| 2867 | } |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2868 | if dh.heartbeatSignature == 0 || dh.heartbeatSignature == heartBeat.HeartbeatSignature { |
| 2869 | if dh.heartbeatSignature == 0 { |
| 2870 | // First time the signature will be 0, update the signture to DB when not found. |
| 2871 | dh.updateHeartbeatSignature(ctx, heartBeat.HeartbeatSignature) |
| 2872 | dh.heartbeatSignature = heartBeat.HeartbeatSignature |
| 2873 | } |
| 2874 | logger.Infow(ctx, "heartbeat signature", log.Fields{"sign": dh.heartbeatSignature}) |
| 2875 | |
| 2876 | dh.lockDevice.RLock() |
| 2877 | // Stop the read indication only if it the routine is active |
| 2878 | // The read indication would have already stopped due to failure on the gRPC stream following OLT going unreachable |
| 2879 | // Sending message on the 'stopIndication' channel again will cause the readIndication routine to immediately stop |
| 2880 | // on next execution of the readIndication routine. |
| 2881 | if !dh.isReadIndicationRoutineActive { |
| 2882 | // Start reading indications |
| 2883 | go func() { |
| 2884 | if err = dh.readIndications(ctx); err != nil { |
| 2885 | _ = olterrors.NewErrAdapter("indication-read-failure", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| 2886 | } |
| 2887 | }() |
| 2888 | } |
| 2889 | dh.lockDevice.RUnlock() |
| 2890 | |
| 2891 | } else { |
| 2892 | logger.Warn(ctx, "Heartbeat signature changed, OLT is rebooted. Cleaningup resources.") |
| 2893 | dh.updateHeartbeatSignature(ctx, heartBeat.HeartbeatSignature) |
| 2894 | dh.heartbeatSignature = heartBeat.HeartbeatSignature |
| 2895 | go dh.updateStateRebooted(ctx) |
| 2896 | } |
| 2897 | |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2898 | } |
| 2899 | cancel() |
| 2900 | case <-dh.stopHeartbeatCheck: |
Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2901 | 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] | 2902 | return |
| 2903 | } |
| 2904 | } |
| 2905 | } |
| 2906 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2907 | func (dh *DeviceHandler) updateStateUnreachable(ctx context.Context) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2908 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2909 | if err != nil || device == nil { |
Girish Gowdra | b1caa44 | 2020-10-19 12:24:39 -0700 | [diff] [blame] | 2910 | // One case where we have seen core returning an error for GetDevice call is after OLT device delete. |
| 2911 | // After OLT delete, the adapter asks for OLT to reboot. When OLT is rebooted, shortly we loose heartbeat. |
| 2912 | // The 'startHeartbeatCheck' then asks the device to be marked unreachable towards the core, but the core |
| 2913 | // has already deleted the device and returns error. In this particular scenario, it is Ok because any necessary |
| 2914 | // cleanup in the adapter was already done during DeleteDevice API handler routine. |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2915 | _ = olterrors.NewErrNotFound("device", log.Fields{"device-id": dh.device.Id}, err).Log() |
Girish Gowdra | b1caa44 | 2020-10-19 12:24:39 -0700 | [diff] [blame] | 2916 | // Immediately return, otherwise accessing a null 'device' struct would cause panic |
| 2917 | return |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2918 | } |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2919 | |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2920 | 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] | 2921 | "admin-state": device.AdminState, "oper-status": device.OperStatus}) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2922 | if device.ConnectStatus == voltha.ConnectStatus_REACHABLE { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2923 | if err = dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2924 | DeviceId: dh.device.Id, |
| 2925 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2926 | ConnStatus: voltha.ConnectStatus_UNREACHABLE, |
| 2927 | }); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2928 | _ = 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] | 2929 | } |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2930 | /* |
| 2931 | if err = dh.updatePortsStateInCore(ctx, &ca.PortStateFilter{ |
| 2932 | DeviceId: dh.device.Id, |
| 2933 | PortTypeFilter: 0, |
| 2934 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2935 | }); err != nil { |
| 2936 | _ = olterrors.NewErrAdapter("port-update-failed", log.Fields{"device-id": dh.device.Id}, err).Log() |
| 2937 | } |
| 2938 | */ |
Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 2939 | |
| 2940 | //raise olt communication failure event |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 2941 | raisedTs := time.Now().Unix() |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2942 | cloned := proto.Clone(device).(*voltha.Device) |
| 2943 | cloned.ConnectStatus = voltha.ConnectStatus_UNREACHABLE |
| 2944 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 2945 | dh.device = cloned // update local copy of the device |
| 2946 | go dh.eventMgr.oltCommunicationEvent(ctx, cloned, raisedTs) |
Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 2947 | |
Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 2948 | dh.lockDevice.RLock() |
Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 2949 | // Stop the Stats collector |
| 2950 | if dh.isCollectorActive { |
| 2951 | dh.stopCollector <- true |
| 2952 | } |
| 2953 | // stop the heartbeat check routine |
| 2954 | if dh.isHeartbeatCheckActive { |
| 2955 | dh.stopHeartbeatCheck <- true |
| 2956 | } |
Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 2957 | // Stop the read indication only if it the routine is active |
| 2958 | // The read indication would have already stopped due to failure on the gRPC stream following OLT going unreachable |
| 2959 | // Sending message on the 'stopIndication' channel again will cause the readIndication routine to immediately stop |
| 2960 | // on next execution of the readIndication routine. |
| 2961 | if dh.isReadIndicationRoutineActive { |
| 2962 | dh.stopIndications <- true |
| 2963 | } |
| 2964 | dh.lockDevice.RUnlock() |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2965 | dh.transitionMap.Handle(ctx, DeviceInit) |
| 2966 | |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2967 | } |
| 2968 | } |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2969 | |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2970 | func (dh *DeviceHandler) updateStateRebooted(ctx context.Context) { |
| 2971 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
| 2972 | if err != nil || device == nil { |
| 2973 | // One case where we have seen core returning an error for GetDevice call is after OLT device delete. |
| 2974 | // After OLT delete, the adapter asks for OLT to reboot. When OLT is rebooted, shortly we loose heartbeat. |
| 2975 | // The 'startHeartbeatCheck' then asks the device to be marked unreachable towards the core, but the core |
| 2976 | // has already deleted the device and returns error. In this particular scenario, it is Ok because any necessary |
| 2977 | // cleanup in the adapter was already done during DeleteDevice API handler routine. |
| 2978 | _ = olterrors.NewErrNotFound("device", log.Fields{"device-id": dh.device.Id}, err).Log() |
| 2979 | // Immediately return, otherwise accessing a null 'device' struct would cause panic |
| 2980 | return |
| 2981 | } |
Mahir Gunyel | 701df86 | 2023-09-07 16:16:04 -0700 | [diff] [blame] | 2982 | //Starting the cleanup process |
| 2983 | dh.setDeviceDeletionInProgressFlag(true) |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2984 | |
| 2985 | logger.Warnw(ctx, "update-state-rebooted", log.Fields{"device-id": dh.device.Id, "connect-status": device.ConnectStatus, |
| 2986 | "admin-state": device.AdminState, "oper-status": device.OperStatus, "conn-status": voltha.ConnectStatus_UNREACHABLE}) |
| 2987 | if err = dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| 2988 | DeviceId: dh.device.Id, |
| 2989 | OperStatus: voltha.OperStatus_REBOOTED, |
| 2990 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2991 | }); err != nil { |
| 2992 | _ = olterrors.NewErrAdapter("device-state-update-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| 2993 | } |
| 2994 | |
| 2995 | dh.lockDevice.RLock() |
| 2996 | // Stop the read indication only if it the routine is active |
| 2997 | // The read indication would have already stopped due to failure on the gRPC stream following OLT going unreachable |
| 2998 | // Sending message on the 'stopIndication' channel again will cause the readIndication routine to immediately stop |
| 2999 | // on next execution of the readIndication routine. |
| 3000 | if dh.isReadIndicationRoutineActive { |
| 3001 | dh.stopIndications <- true |
| 3002 | } |
| 3003 | dh.lockDevice.RUnlock() |
| 3004 | |
| 3005 | //raise olt communication failure event |
| 3006 | raisedTs := time.Now().Unix() |
| 3007 | cloned := proto.Clone(device).(*voltha.Device) |
| 3008 | cloned.ConnectStatus = voltha.ConnectStatus_UNREACHABLE |
| 3009 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 3010 | dh.device = cloned // update local copy of the device |
| 3011 | go dh.eventMgr.oltCommunicationEvent(ctx, cloned, raisedTs) |
| 3012 | |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 3013 | if err := dh.cleanupDeviceResources(ctx); err != nil { |
| 3014 | logger.Errorw(ctx, "failure-in-cleanup-device-resources", log.Fields{"device-id": dh.device.Id, "err": err}) |
| 3015 | } else { |
| 3016 | logger.Debugw(ctx, "removed-device-from-Resource-manager-KV-store", log.Fields{"device-id": dh.device.Id}) |
| 3017 | } |
Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 3018 | |
| 3019 | dh.lockDevice.RLock() |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3020 | // Stop the Stats collector |
Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 3021 | if dh.isCollectorActive { |
| 3022 | dh.stopCollector <- true |
| 3023 | } |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3024 | // stop the heartbeat check routine |
Holger Hildebrandt | e6c877b | 2022-09-15 13:51:39 +0000 | [diff] [blame] | 3025 | if dh.isHeartbeatCheckActive { |
| 3026 | dh.stopHeartbeatCheck <- true |
| 3027 | } |
| 3028 | dh.lockDevice.RUnlock() |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3029 | |
Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 3030 | dh.StopAllFlowRoutines(ctx) |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3031 | |
| 3032 | //reset adapter reconcile flag |
| 3033 | dh.adapterPreviouslyConnected = false |
| 3034 | for { |
| 3035 | |
| 3036 | childDevices, err := dh.getChildDevicesFromCore(ctx, dh.device.Id) |
| 3037 | if err != nil || childDevices == nil { |
| 3038 | logger.Errorw(ctx, "Failed to get child devices from core", log.Fields{"deviceID": dh.device.Id}) |
| 3039 | continue |
| 3040 | } |
| 3041 | if len(childDevices.Items) == 0 { |
| 3042 | logger.Infow(ctx, "All childDevices cleared from core, proceed with device init", log.Fields{"deviceID": dh.device.Id}) |
| 3043 | break |
| 3044 | } else { |
| 3045 | logger.Warn(ctx, "Not all child devices are cleared, continuing to wait") |
| 3046 | time.Sleep(5 * time.Second) |
| 3047 | } |
| 3048 | |
| 3049 | } |
Mahir Gunyel | 701df86 | 2023-09-07 16:16:04 -0700 | [diff] [blame] | 3050 | //Cleanup completed , reset the flag |
| 3051 | dh.setDeviceDeletionInProgressFlag(false) |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 3052 | logger.Infow(ctx, "cleanup complete after reboot , moving to init", log.Fields{"deviceID": device.Id}) |
| 3053 | dh.transitionMap.Handle(ctx, DeviceInit) |
| 3054 | |
| 3055 | } |
| 3056 | |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3057 | // EnablePort to enable Pon interface |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3058 | func (dh *DeviceHandler) EnablePort(ctx context.Context, port *voltha.Port) error { |
| 3059 | logger.Debugw(ctx, "enable-port", log.Fields{"Device": dh.device, "port": port}) |
| 3060 | return dh.modifyPhyPort(ctx, port, true) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | // DisablePort to disable pon interface |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3064 | func (dh *DeviceHandler) DisablePort(ctx context.Context, port *voltha.Port) error { |
| 3065 | logger.Debugw(ctx, "disable-port", log.Fields{"Device": dh.device, "port": port}) |
| 3066 | return dh.modifyPhyPort(ctx, port, false) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3067 | } |
| 3068 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3069 | // 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] | 3070 | func (dh *DeviceHandler) modifyPhyPort(ctx context.Context, port *voltha.Port, enablePort bool) error { |
| 3071 | 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] | 3072 | if port.GetType() == voltha.Port_ETHERNET_NNI { |
| 3073 | // Bug is opened for VOL-2505 to support NNI disable feature. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3074 | 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] | 3075 | log.Fields{"device": dh.device, "port": port}) |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3076 | return olterrors.NewErrAdapter("illegal-port-request", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3077 | "port-type": port.GetType, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3078 | "enable-state": enablePort}, nil) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3079 | } |
| 3080 | // fetch interfaceid from PortNo |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3081 | ponID := plt.PortNoToIntfID(port.GetPortNo(), voltha.Port_PON_OLT) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3082 | ponIntf := &oop.Interface{IntfId: ponID} |
| 3083 | var operStatus voltha.OperStatus_Types |
| 3084 | if enablePort { |
| 3085 | operStatus = voltha.OperStatus_ACTIVE |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3086 | out, err := dh.Client.EnablePonIf(ctx, ponIntf) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3087 | |
| 3088 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3089 | return olterrors.NewErrAdapter("pon-port-enable-failed", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3090 | "device-id": dh.device.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3091 | "port": port}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3092 | } |
| 3093 | // updating interface local cache for collecting stats |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 3094 | dh.activePorts.Store(ponID, true) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3095 | 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] | 3096 | } else { |
| 3097 | operStatus = voltha.OperStatus_UNKNOWN |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3098 | out, err := dh.Client.DisablePonIf(ctx, ponIntf) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3099 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3100 | return olterrors.NewErrAdapter("pon-port-disable-failed", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3101 | "device-id": dh.device.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3102 | "port": port}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3103 | } |
| 3104 | // updating interface local cache for collecting stats |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 3105 | dh.activePorts.Store(ponID, false) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3106 | 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] | 3107 | } |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3108 | if err := dh.updatePortStateInCore(ctx, &ca.PortState{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3109 | DeviceId: dh.device.Id, |
| 3110 | PortType: voltha.Port_PON_OLT, |
| 3111 | PortNo: port.PortNo, |
| 3112 | OperStatus: operStatus, |
| 3113 | }); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3114 | return olterrors.NewErrAdapter("port-state-update-failed", log.Fields{ |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 3115 | "device-id": dh.device.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3116 | "port": port.PortNo}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3117 | } |
| 3118 | return nil |
| 3119 | } |
| 3120 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3121 | // 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] | 3122 | func (dh *DeviceHandler) disableAdminDownPorts(ctx context.Context, ports []*voltha.Port) error { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3123 | // Disable the port and update the oper_port_status to core |
| 3124 | // 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] | 3125 | for _, port := range ports { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3126 | if port.AdminState == common.AdminState_DISABLED { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3127 | if err := dh.DisablePort(ctx, port); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3128 | return olterrors.NewErrAdapter("port-disable-failed", log.Fields{ |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 3129 | "device-id": dh.device.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3130 | "port": port}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3131 | } |
| 3132 | } |
| 3133 | } |
| 3134 | return nil |
| 3135 | } |
| 3136 | |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3137 | // populateActivePorts to populate activePorts map |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 3138 | func (dh *DeviceHandler) populateActivePorts(ctx context.Context, ports []*voltha.Port) { |
| 3139 | logger.Infow(ctx, "populateActivePorts", log.Fields{"device-id": dh.device.Id}) |
| 3140 | for _, port := range ports { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3141 | if port.Type == voltha.Port_ETHERNET_NNI { |
| 3142 | if port.OperStatus == voltha.OperStatus_ACTIVE { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3143 | dh.activePorts.Store(plt.PortNoToIntfID(port.PortNo, voltha.Port_ETHERNET_NNI), true) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3144 | } else { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3145 | dh.activePorts.Store(plt.PortNoToIntfID(port.PortNo, voltha.Port_ETHERNET_NNI), false) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3146 | } |
| 3147 | } |
| 3148 | if port.Type == voltha.Port_PON_OLT { |
| 3149 | if port.OperStatus == voltha.OperStatus_ACTIVE { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3150 | dh.activePorts.Store(plt.PortNoToIntfID(port.PortNo, voltha.Port_PON_OLT), true) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3151 | } else { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3152 | dh.activePorts.Store(plt.PortNoToIntfID(port.PortNo, voltha.Port_PON_OLT), false) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 3153 | } |
| 3154 | } |
| 3155 | } |
| 3156 | } |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 3157 | |
| 3158 | // ChildDeviceLost deletes ONU and clears pon resources related to it. |
Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 3159 | 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] | 3160 | 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] | 3161 | if dh.getDeviceDeletionInProgressFlag() { |
| 3162 | // Given that the OLT device itself is getting deleted, everything will be cleaned up in the DB and the OLT |
| 3163 | // will reboot, so everything will be reset on the pOLT too. |
| 3164 | logger.Infow(ctx, "olt-device-delete-in-progress-not-handling-child-device-lost", |
| 3165 | log.Fields{"parent-device-id": dh.device.Id, "pon-port": pPortNo, "onuID": onuID, "onuSN": onuSn}) |
| 3166 | return nil |
| 3167 | } |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3168 | intfID := plt.PortNoToIntfID(pPortNo, voltha.Port_PON_OLT) |
Girish Gowdra | 89ae6d8 | 2020-05-28 23:40:53 -0700 | [diff] [blame] | 3169 | onuKey := dh.formOnuKey(intfID, onuID) |
Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 3170 | |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 3171 | var sn *oop.SerialNumber |
| 3172 | var err error |
Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 3173 | if sn, err = dh.deStringifySerialNumber(onuSn); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3174 | return olterrors.NewErrAdapter("failed-to-destringify-serial-number", |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 3175 | log.Fields{ |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 3176 | "devicer-id": dh.device.Id, |
Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 3177 | "serial-number": onuSn}, err).Log() |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 3178 | } |
Girish Gowdra | 89ae6d8 | 2020-05-28 23:40:53 -0700 | [diff] [blame] | 3179 | |
Girish Gowdra | 89ae6d8 | 2020-05-28 23:40:53 -0700 | [diff] [blame] | 3180 | onu := &oop.Onu{IntfId: intfID, OnuId: onuID, SerialNumber: sn} |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3181 | //clear PON resources associated with ONU |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3182 | onuGem, err := dh.resourceMgr[intfID].GetOnuGemInfo(ctx, onuID) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3183 | if err != nil || onuGem == nil || onuGem.OnuID != onuID { |
| 3184 | logger.Warnw(ctx, "failed-to-get-onu-info-for-pon-port", log.Fields{ |
| 3185 | "device-id": dh.device.Id, |
| 3186 | "intf-id": intfID, |
| 3187 | "onuID": onuID, |
| 3188 | "err": err}) |
| 3189 | } else { |
| 3190 | logger.Debugw(ctx, "onu-data", log.Fields{"onu": onu}) |
yasin sapli | e87d4bd | 2021-12-06 09:04:03 +0000 | [diff] [blame] | 3191 | // Delete flows from device before schedulers and queue |
| 3192 | // Clear flowids for gem cache. |
| 3193 | removedFlows := []uint64{} |
| 3194 | for _, gem := range onuGem.GemPorts { |
| 3195 | if flowIDs, err := dh.resourceMgr[intfID].GetFlowIDsForGem(ctx, gem); err == nil { |
| 3196 | for _, flowID := range flowIDs { |
| 3197 | //multiple gem port can have the same flow id |
| 3198 | //it is better to send only one flowRemove request to the agent |
| 3199 | var alreadyRemoved bool |
| 3200 | for _, removedFlowID := range removedFlows { |
| 3201 | if removedFlowID == flowID { |
| 3202 | logger.Debugw(ctx, "flow-is-already-removed-due-to-another-gem", log.Fields{"flowID": flowID}) |
| 3203 | alreadyRemoved = true |
| 3204 | break |
| 3205 | } |
| 3206 | } |
| 3207 | if !alreadyRemoved { |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3208 | dh.removeFlowFromDevice(ctx, flowID, intfID) |
yasin sapli | e87d4bd | 2021-12-06 09:04:03 +0000 | [diff] [blame] | 3209 | removedFlows = appendUnique64bit(removedFlows, flowID) |
| 3210 | } |
| 3211 | } |
| 3212 | } |
| 3213 | _ = dh.resourceMgr[intfID].DeleteFlowIDsForGem(ctx, gem) |
| 3214 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3215 | if err := dh.clearUNIData(ctx, onuGem); err != nil { |
| 3216 | logger.Warnw(ctx, "failed-to-clear-uni-data-for-onu", log.Fields{ |
| 3217 | "device-id": dh.device.Id, |
| 3218 | "onu-device": onu, |
| 3219 | "err": err}) |
| 3220 | } |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3221 | if err := dh.resourceMgr[intfID].DelOnuGemInfo(ctx, onuID); err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3222 | logger.Warnw(ctx, "persistence-update-onu-gem-info-failed", log.Fields{ |
| 3223 | "intf-id": intfID, |
| 3224 | "onu-device": onu, |
| 3225 | "onu-gem": onuGem, |
| 3226 | "err": err}) |
| 3227 | //Not returning error on cleanup. |
| 3228 | } |
| 3229 | logger.Debugw(ctx, "removed-onu-gem-info", log.Fields{"intf": intfID, "onu-device": onu, "onugem": onuGem}) |
Himani Chawla | bcc9585 | 2021-10-27 10:55:40 +0530 | [diff] [blame] | 3230 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3231 | } |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3232 | dh.resourceMgr[intfID].FreeonuID(ctx, []uint32{onuID}) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3233 | dh.onus.Delete(onuKey) |
| 3234 | dh.discOnus.Delete(onuSn) |
| 3235 | |
| 3236 | // Now clear the ONU on the OLT |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 3237 | 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] | 3238 | return olterrors.NewErrAdapter("failed-to-delete-onu", log.Fields{ |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 3239 | "device-id": dh.device.Id, |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 3240 | "onu-id": onuID}, err).Log() |
| 3241 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3242 | |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 3243 | return nil |
| 3244 | } |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3245 | func (dh *DeviceHandler) removeFlowFromDevice(ctx context.Context, flowID uint64, intfID uint32) { |
| 3246 | flow := &oop.Flow{FlowId: flowID} |
| 3247 | if dh.flowMgr == nil || dh.flowMgr[intfID] == nil { |
| 3248 | logger.Warnw(ctx, "failed-to-get-flow-mgr-to-remove-flow-from-device", log.Fields{ |
| 3249 | "device-id": dh.device.Id}) |
| 3250 | } else { |
| 3251 | if err := dh.flowMgr[intfID].removeFlowFromDevice(ctx, flow, flowID); err != nil { |
| 3252 | logger.Warnw(ctx, "failed-to-remove-flow-from-device", log.Fields{ |
| 3253 | "device-id": dh.device.Id, |
| 3254 | "err": err}) |
| 3255 | } |
| 3256 | } |
| 3257 | } |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3258 | |
| 3259 | func getInPortFromFlow(flow *of.OfpFlowStats) uint32 { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3260 | for _, field := range flow_utils.GetOfbFields(flow) { |
| 3261 | if field.Type == flow_utils.IN_PORT { |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3262 | return field.GetPort() |
| 3263 | } |
| 3264 | } |
| 3265 | return InvalidPort |
| 3266 | } |
| 3267 | |
| 3268 | func getOutPortFromFlow(flow *of.OfpFlowStats) uint32 { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3269 | for _, action := range flow_utils.GetActions(flow) { |
| 3270 | if action.Type == flow_utils.OUTPUT { |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3271 | if out := action.GetOutput(); out != nil { |
| 3272 | return out.GetPort() |
| 3273 | } |
| 3274 | } |
| 3275 | } |
| 3276 | return InvalidPort |
| 3277 | } |
| 3278 | |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3279 | func getPorts(flow *of.OfpFlowStats) (uint32, uint32) { |
| 3280 | inPort := getInPortFromFlow(flow) |
| 3281 | outPort := getOutPortFromFlow(flow) |
| 3282 | |
| 3283 | if inPort == InvalidPort || outPort == InvalidPort { |
| 3284 | return inPort, outPort |
| 3285 | } |
| 3286 | |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3287 | if isControllerFlow := plt.IsControllerBoundFlow(outPort); isControllerFlow { |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3288 | /* 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] | 3289 | if portType := plt.IntfIDToPortTypeName(inPort); portType == voltha.Port_PON_OLT { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3290 | if uniPort := flow_utils.GetChildPortFromTunnelId(flow); uniPort != 0 { |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3291 | return uniPort, outPort |
| 3292 | } |
| 3293 | } |
| 3294 | } else { |
| 3295 | // 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] | 3296 | if portType := plt.IntfIDToPortTypeName(outPort); portType == voltha.Port_PON_OLT { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3297 | if uniPort := flow_utils.GetChildPortFromTunnelId(flow); uniPort != 0 { |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3298 | return inPort, uniPort |
| 3299 | } |
| 3300 | // 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] | 3301 | } else if portType := plt.IntfIDToPortTypeName(inPort); portType == voltha.Port_PON_OLT { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3302 | if uniPort := flow_utils.GetChildPortFromTunnelId(flow); uniPort != 0 { |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 3303 | return uniPort, outPort |
| 3304 | } |
| 3305 | } |
| 3306 | } |
| 3307 | |
| 3308 | return InvalidPort, InvalidPort |
| 3309 | } |
Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 3310 | |
| 3311 | func extractOmciTransactionID(omciPkt []byte) uint16 { |
| 3312 | if len(omciPkt) > 3 { |
| 3313 | d := omciPkt[0:2] |
| 3314 | transid := binary.BigEndian.Uint16(d) |
| 3315 | return transid |
| 3316 | } |
| 3317 | return 0 |
| 3318 | } |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 3319 | |
| 3320 | // StoreOnuDevice stores the onu parameters to the local cache. |
| 3321 | func (dh *DeviceHandler) StoreOnuDevice(onuDevice *OnuDevice) { |
| 3322 | onuKey := dh.formOnuKey(onuDevice.intfID, onuDevice.onuID) |
| 3323 | dh.onus.Store(onuKey, onuDevice) |
| 3324 | } |
Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 3325 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3326 | 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] | 3327 | var err error |
Andrea Campanella | 9931ad6 | 2020-04-28 15:11:06 +0200 | [diff] [blame] | 3328 | var sn *oop.SerialNumber |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3329 | var ID uint32 |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3330 | resp := new(extension.ReturnValues) |
Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 3331 | valueparam := new(oop.ValueParam) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 3332 | ctx = log.WithSpanFromContext(context.Background(), ctx) |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 3333 | 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] | 3334 | if sn, err = dh.deStringifySerialNumber(device.SerialNumber); err != nil { |
| 3335 | return nil, err |
| 3336 | } |
| 3337 | ID = device.ProxyAddress.GetOnuId() |
| 3338 | Onu := oop.Onu{IntfId: device.ParentPortNo, OnuId: ID, SerialNumber: sn} |
| 3339 | valueparam.Onu = &Onu |
| 3340 | valueparam.Value = value |
| 3341 | |
| 3342 | // This API is unsupported until agent patch is added |
| 3343 | resp.Unsupported = uint32(value) |
| 3344 | _ = ctx |
| 3345 | |
| 3346 | // Uncomment this code once agent changes are complete and tests |
| 3347 | /* |
| 3348 | resp, err = dh.Client.GetValue(ctx, valueparam) |
| 3349 | if err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3350 | 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] | 3351 | return nil, err |
| 3352 | } |
| 3353 | */ |
| 3354 | |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 3355 | 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] | 3356 | return resp, nil |
| 3357 | } |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 3358 | |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 3359 | func (dh *DeviceHandler) getIntfIDFromFlow(ctx context.Context, flow *of.OfpFlowStats) uint32 { |
| 3360 | // Default to NNI |
| 3361 | var intfID = dh.totalPonPorts |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 3362 | inPort, outPort := getPorts(flow) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 3363 | if inPort != InvalidPort && outPort != InvalidPort { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3364 | _, intfID, _, _ = plt.ExtractAccessFromFlow(inPort, outPort) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 3365 | } |
| 3366 | return intfID |
| 3367 | } |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3368 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3369 | func (dh *DeviceHandler) getOnuIndicationChannel(ctx context.Context, intfID uint32) chan onuIndicationMsg { |
| 3370 | dh.perPonOnuIndicationChannelLock.Lock() |
| 3371 | if ch, ok := dh.perPonOnuIndicationChannel[intfID]; ok { |
| 3372 | dh.perPonOnuIndicationChannelLock.Unlock() |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3373 | return ch.indicationChannel |
| 3374 | } |
| 3375 | channels := onuIndicationChannels{ |
| 3376 | //We create a buffered channel here to avoid calling function to be blocked |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3377 | //in case of multiple indications from the ONUs, |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3378 | //especially in the case where indications are buffered in OLT. |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3379 | indicationChannel: make(chan onuIndicationMsg, 500), |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3380 | stopChannel: make(chan struct{}), |
| 3381 | } |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3382 | dh.perPonOnuIndicationChannel[intfID] = channels |
| 3383 | dh.perPonOnuIndicationChannelLock.Unlock() |
| 3384 | go dh.onuIndicationsRoutine(&channels) |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3385 | return channels.indicationChannel |
| 3386 | |
| 3387 | } |
| 3388 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3389 | func (dh *DeviceHandler) removeOnuIndicationChannels(ctx context.Context) { |
| 3390 | logger.Debug(ctx, "remove-onu-indication-channels", log.Fields{"device-id": dh.device.Id}) |
| 3391 | dh.perPonOnuIndicationChannelLock.Lock() |
| 3392 | defer dh.perPonOnuIndicationChannelLock.Unlock() |
| 3393 | for _, v := range dh.perPonOnuIndicationChannel { |
| 3394 | close(v.stopChannel) |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3395 | } |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3396 | dh.perPonOnuIndicationChannel = make(map[uint32]onuIndicationChannels) |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3397 | } |
| 3398 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3399 | func (dh *DeviceHandler) putOnuIndicationToChannel(ctx context.Context, indication *oop.Indication, intfID uint32) { |
| 3400 | ind := onuIndicationMsg{ |
| 3401 | ctx: ctx, |
| 3402 | indication: indication, |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3403 | } |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3404 | 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] | 3405 | // Send the onuIndication on the ONU channel |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3406 | dh.getOnuIndicationChannel(ctx, intfID) <- ind |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3407 | } |
| 3408 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3409 | func (dh *DeviceHandler) onuIndicationsRoutine(onuChannels *onuIndicationChannels) { |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3410 | for { |
| 3411 | select { |
| 3412 | // process one indication per onu, before proceeding to the next one |
| 3413 | case onuInd := <-onuChannels.indicationChannel: |
Andrea Campanella | 46b0140 | 2021-11-15 16:58:05 -0800 | [diff] [blame] | 3414 | indication := *(proto.Clone(onuInd.indication)).(*oop.Indication) |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3415 | 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] | 3416 | "ind": indication}) |
| 3417 | switch indication.Data.(type) { |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3418 | case *oop.Indication_OnuInd: |
Andrea Campanella | 46b0140 | 2021-11-15 16:58:05 -0800 | [diff] [blame] | 3419 | if err := dh.onuIndication(onuInd.ctx, indication.GetOnuInd()); err != nil { |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3420 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{ |
| 3421 | "type": "onu-indication", |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3422 | "device-id": dh.device.Id}, err).Log() |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3423 | } |
| 3424 | case *oop.Indication_OnuDiscInd: |
Andrea Campanella | 46b0140 | 2021-11-15 16:58:05 -0800 | [diff] [blame] | 3425 | if err := dh.onuDiscIndication(onuInd.ctx, indication.GetOnuDiscInd()); err != nil { |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3426 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{ |
| 3427 | "type": "onu-discovery", |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 3428 | "device-id": dh.device.Id}, err).Log() |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 3429 | } |
| 3430 | } |
| 3431 | case <-onuChannels.stopChannel: |
| 3432 | logger.Debugw(context.Background(), "stop-signal-received-for-onu-channel", log.Fields{"device-id": dh.device.Id}) |
| 3433 | close(onuChannels.indicationChannel) |
| 3434 | return |
| 3435 | } |
| 3436 | } |
| 3437 | } |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3438 | |
| 3439 | // RouteMcastFlowOrGroupMsgToChannel routes incoming mcast flow or group to a channel to be handled by the a specific |
| 3440 | // instance of mcastFlowOrGroupChannelHandlerRoutine meant to handle messages for that group. |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3441 | 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] | 3442 | if dh.getDeviceDeletionInProgressFlag() { |
| 3443 | // The device itself is going to be reset as part of deletion. So nothing to be done. |
| 3444 | logger.Infow(ctx, "device-deletion-in-progress--not-handling-flows-or-groups", log.Fields{"device-id": dh.device.Id}) |
| 3445 | return nil |
| 3446 | } |
| 3447 | |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3448 | // Step1 : Fill McastFlowOrGroupControlBlock |
| 3449 | // Step2 : Push the McastFlowOrGroupControlBlock to appropriate channel |
| 3450 | // Step3 : Wait on response channel for response |
| 3451 | // Step4 : Return error value |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3452 | startTime := time.Now() |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3453 | logger.Debugw(ctx, "process-flow-or-group", log.Fields{"flow": flow, "group": group, "action": action}) |
| 3454 | errChan := make(chan error) |
| 3455 | var groupID uint32 |
| 3456 | mcastFlowOrGroupCb := McastFlowOrGroupControlBlock{ |
| 3457 | ctx: ctx, |
| 3458 | flowOrGroupAction: action, |
| 3459 | flow: flow, |
| 3460 | group: group, |
| 3461 | errChan: &errChan, |
| 3462 | } |
| 3463 | if flow != nil { |
| 3464 | groupID = flow_utils.GetGroup(flow) |
| 3465 | } else if group != nil { |
| 3466 | groupID = group.Desc.GroupId |
| 3467 | } else { |
| 3468 | return errors.New("flow-and-group-both-nil") |
| 3469 | } |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3470 | mcastRoutineIdx := groupID % MaxNumOfGroupHandlerChannels |
| 3471 | if dh.mcastHandlerRoutineActive[mcastRoutineIdx] { |
| 3472 | // Derive the appropriate go routine to handle the request by a simple module operation. |
| 3473 | // There are only MaxNumOfGroupHandlerChannels number of channels to handle the mcast flow or group |
| 3474 | dh.incomingMcastFlowOrGroup[groupID%MaxNumOfGroupHandlerChannels] <- mcastFlowOrGroupCb |
| 3475 | // Wait for handler to return error value |
| 3476 | err := <-errChan |
| 3477 | logger.Debugw(ctx, "process-flow-or-group--received-resp", log.Fields{"err": err, "totalTimeInSeconds": time.Since(startTime).Milliseconds()}) |
| 3478 | return err |
| 3479 | } |
| 3480 | logger.Errorw(ctx, "mcast handler routine not active for onu", log.Fields{"mcastRoutineIdx": mcastRoutineIdx}) |
| 3481 | return fmt.Errorf("mcast-handler-routine-not-active-for-index-%v", mcastRoutineIdx) |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | // mcastFlowOrGroupChannelHandlerRoutine routine to handle incoming mcast flow/group message |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3485 | func (dh *DeviceHandler) mcastFlowOrGroupChannelHandlerRoutine(routineIndex int, mcastFlowOrGroupChannel chan McastFlowOrGroupControlBlock, stopHandler chan bool) { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3486 | for { |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3487 | select { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3488 | // block on the channel to receive an incoming mcast flow/group |
| 3489 | // process the flow completely before proceeding to handle the next flow |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3490 | case mcastFlowOrGroupCb := <-mcastFlowOrGroupChannel: |
| 3491 | if mcastFlowOrGroupCb.flow != nil { |
| 3492 | if mcastFlowOrGroupCb.flowOrGroupAction == McastFlowOrGroupAdd { |
| 3493 | logger.Debugw(mcastFlowOrGroupCb.ctx, "adding-mcast-flow", |
| 3494 | log.Fields{"device-id": dh.device.Id, |
| 3495 | "flowToAdd": mcastFlowOrGroupCb.flow}) |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3496 | err := olterrors.NewErrNotFound("no-flow-manager-found-to-add-mcast-flow", log.Fields{"device-id": dh.device.Id}, nil).(error) |
| 3497 | // The mcast flow is not unique to any particular PON port, so it is OK to default to first non nil PON |
| 3498 | for _, flMgr := range dh.flowMgr { |
| 3499 | if flMgr != nil { |
| 3500 | err = flMgr.AddFlow(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.flow, nil) |
| 3501 | break |
| 3502 | } |
| 3503 | } |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3504 | // Pass the return value over the return channel |
| 3505 | *mcastFlowOrGroupCb.errChan <- err |
| 3506 | } else { // flow remove |
| 3507 | logger.Debugw(mcastFlowOrGroupCb.ctx, "removing-mcast-flow", |
| 3508 | log.Fields{"device-id": dh.device.Id, |
| 3509 | "flowToRemove": mcastFlowOrGroupCb.flow}) |
Mahir Gunyel | a2e6870 | 2022-12-07 00:00:42 -0800 | [diff] [blame] | 3510 | // The mcast flow is not unique to any particular PON port, so it is OK to default to first non nil PON |
| 3511 | err := olterrors.NewErrNotFound("no-flow-manager-found-to-remove-mcast-flow", log.Fields{"device-id": dh.device.Id}, nil).(error) |
| 3512 | for _, flMgr := range dh.flowMgr { |
| 3513 | if flMgr != nil { |
| 3514 | err = flMgr.RemoveFlow(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.flow) |
| 3515 | break |
| 3516 | } |
| 3517 | } |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3518 | // Pass the return value over the return channel |
| 3519 | *mcastFlowOrGroupCb.errChan <- err |
| 3520 | } |
| 3521 | } else { // mcast group |
| 3522 | if mcastFlowOrGroupCb.flowOrGroupAction == McastFlowOrGroupAdd { |
| 3523 | logger.Debugw(mcastFlowOrGroupCb.ctx, "adding-mcast-group", |
| 3524 | log.Fields{"device-id": dh.device.Id, |
| 3525 | "groupToAdd": mcastFlowOrGroupCb.group}) |
| 3526 | err := dh.groupMgr.AddGroup(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.group) |
| 3527 | // Pass the return value over the return channel |
| 3528 | *mcastFlowOrGroupCb.errChan <- err |
| 3529 | } else if mcastFlowOrGroupCb.flowOrGroupAction == McastFlowOrGroupModify { // group modify |
| 3530 | logger.Debugw(mcastFlowOrGroupCb.ctx, "modifying-mcast-group", |
| 3531 | log.Fields{"device-id": dh.device.Id, |
| 3532 | "groupToModify": mcastFlowOrGroupCb.group}) |
| 3533 | err := dh.groupMgr.ModifyGroup(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.group) |
| 3534 | // Pass the return value over the return channel |
| 3535 | *mcastFlowOrGroupCb.errChan <- err |
| 3536 | } else { // group remove |
| 3537 | logger.Debugw(mcastFlowOrGroupCb.ctx, "removing-mcast-group", |
| 3538 | log.Fields{"device-id": dh.device.Id, |
| 3539 | "groupToRemove": mcastFlowOrGroupCb.group}) |
| 3540 | err := dh.groupMgr.DeleteGroup(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.group) |
| 3541 | // Pass the return value over the return channel |
| 3542 | *mcastFlowOrGroupCb.errChan <- err |
| 3543 | } |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3544 | } |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3545 | case <-stopHandler: |
| 3546 | dh.mcastHandlerRoutineActive[routineIndex] = false |
| 3547 | return |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 3548 | } |
| 3549 | } |
| 3550 | } |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3551 | |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3552 | // 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] | 3553 | func (dh *DeviceHandler) StopAllMcastHandlerRoutines(ctx context.Context, wg *sync.WaitGroup) { |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3554 | for i, v := range dh.stopMcastHandlerRoutine { |
| 3555 | if dh.mcastHandlerRoutineActive[i] { |
Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 3556 | select { |
| 3557 | case v <- true: |
| 3558 | case <-time.After(time.Second * 5): |
| 3559 | logger.Warnw(ctx, "timeout stopping mcast handler routine", log.Fields{"idx": i, "deviceID": dh.device.Id}) |
| 3560 | } |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3561 | } |
| 3562 | } |
Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 3563 | |
| 3564 | if dh.incomingMcastFlowOrGroup != nil { |
| 3565 | for k := range dh.incomingMcastFlowOrGroup { |
| 3566 | if dh.incomingMcastFlowOrGroup[k] != nil { |
| 3567 | dh.incomingMcastFlowOrGroup[k] = nil |
| 3568 | } |
| 3569 | } |
| 3570 | dh.incomingMcastFlowOrGroup = nil |
| 3571 | } |
| 3572 | |
Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 3573 | wg.Done() |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 3574 | logger.Debug(ctx, "stopped all mcast handler routines") |
| 3575 | } |
| 3576 | |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3577 | func (dh *DeviceHandler) getOltPortCounters(ctx context.Context, oltPortInfo *extension.GetOltPortCounters) *extension.SingleGetValueResponse { |
| 3578 | |
| 3579 | singleValResp := extension.SingleGetValueResponse{ |
| 3580 | Response: &extension.GetValueResponse{ |
| 3581 | Response: &extension.GetValueResponse_PortCoutners{ |
| 3582 | PortCoutners: &extension.GetOltPortCountersResponse{}, |
| 3583 | }, |
| 3584 | }, |
| 3585 | } |
| 3586 | |
| 3587 | errResp := func(status extension.GetValueResponse_Status, |
| 3588 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 3589 | return &extension.SingleGetValueResponse{ |
| 3590 | Response: &extension.GetValueResponse{ |
| 3591 | Status: status, |
| 3592 | ErrReason: reason, |
| 3593 | }, |
| 3594 | } |
| 3595 | } |
| 3596 | |
| 3597 | if oltPortInfo.PortType != extension.GetOltPortCounters_Port_ETHERNET_NNI && |
| 3598 | oltPortInfo.PortType != extension.GetOltPortCounters_Port_PON_OLT { |
| 3599 | //send error response |
| 3600 | logger.Debugw(ctx, "getOltPortCounters invalid portType", log.Fields{"oltPortInfo": oltPortInfo.PortType}) |
| 3601 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_PORT_TYPE) |
| 3602 | } |
| 3603 | statIndChn := make(chan bool, 1) |
| 3604 | dh.portStats.RegisterForStatIndication(ctx, portStatsType, statIndChn, oltPortInfo.PortNo, oltPortInfo.PortType) |
| 3605 | defer dh.portStats.DeRegisterFromStatIndication(ctx, portStatsType, statIndChn) |
| 3606 | //request openOlt agent to send the the port statistics indication |
| 3607 | |
| 3608 | go func() { |
| 3609 | _, err := dh.Client.CollectStatistics(ctx, new(oop.Empty)) |
| 3610 | if err != nil { |
| 3611 | logger.Errorw(ctx, "getOltPortCounters CollectStatistics failed ", log.Fields{"err": err}) |
| 3612 | } |
| 3613 | }() |
| 3614 | select { |
| 3615 | case <-statIndChn: |
| 3616 | //indication received for ports stats |
| 3617 | logger.Debugw(ctx, "getOltPortCounters recvd statIndChn", log.Fields{"oltPortInfo": oltPortInfo}) |
| 3618 | case <-time.After(oltPortInfoTimeout * time.Second): |
| 3619 | logger.Debugw(ctx, "getOltPortCounters timeout happened", log.Fields{"oltPortInfo": oltPortInfo}) |
| 3620 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_TIMEOUT) |
| 3621 | case <-ctx.Done(): |
| 3622 | logger.Debugw(ctx, "getOltPortCounters ctx Done ", log.Fields{"oltPortInfo": oltPortInfo}) |
| 3623 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_TIMEOUT) |
| 3624 | } |
| 3625 | if oltPortInfo.PortType == extension.GetOltPortCounters_Port_ETHERNET_NNI { |
| 3626 | //get nni stats |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3627 | intfID := plt.PortNoToIntfID(oltPortInfo.PortNo, voltha.Port_ETHERNET_NNI) |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3628 | logger.Debugw(ctx, "getOltPortCounters intfID ", log.Fields{"intfID": intfID}) |
| 3629 | cmnni := dh.portStats.collectNNIMetrics(intfID) |
| 3630 | if cmnni == nil { |
| 3631 | //TODO define the error reason |
| 3632 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 3633 | } |
| 3634 | dh.portStats.updateGetOltPortCountersResponse(ctx, &singleValResp, cmnni) |
| 3635 | return &singleValResp |
| 3636 | |
| 3637 | } else if oltPortInfo.PortType == extension.GetOltPortCounters_Port_PON_OLT { |
| 3638 | // get pon stats |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3639 | intfID := plt.PortNoToIntfID(oltPortInfo.PortNo, voltha.Port_PON_OLT) |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 3640 | if val, ok := dh.activePorts.Load(intfID); ok && val == true { |
| 3641 | cmpon := dh.portStats.collectPONMetrics(intfID) |
| 3642 | if cmpon == nil { |
| 3643 | //TODO define the error reason |
| 3644 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 3645 | } |
| 3646 | dh.portStats.updateGetOltPortCountersResponse(ctx, &singleValResp, cmpon) |
| 3647 | return &singleValResp |
| 3648 | } |
| 3649 | } |
| 3650 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 3651 | } |
Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 3652 | |
Akash Soni | 3bcf5e0 | 2024-12-03 08:01:48 +0530 | [diff] [blame] | 3653 | func (dh *DeviceHandler) getOltOffloadStats(ctx context.Context, oltPortInfo *extension.GetOffloadedAppsStatisticsRequest) *extension.SingleGetValueResponse { |
| 3654 | |
| 3655 | singleValResp := extension.SingleGetValueResponse{ |
| 3656 | Response: &extension.GetValueResponse{ |
| 3657 | Status: extension.GetValueResponse_OK, |
| 3658 | Response: &extension.GetValueResponse_OffloadedAppsStats{ |
| 3659 | OffloadedAppsStats: &extension.GetOffloadedAppsStatisticsResponse{}, |
| 3660 | }, |
| 3661 | }, |
| 3662 | } |
| 3663 | |
| 3664 | return &singleValResp |
| 3665 | } |
| 3666 | |
Akash Soni | 3c75ad7 | 2024-12-23 12:09:48 +0530 | [diff] [blame^] | 3667 | func (dh *DeviceHandler) setOltOffload(ctx context.Context, congig *extension.AppOffloadConfig) *extension.SingleSetValueResponse { |
| 3668 | |
| 3669 | singleValResp := extension.SingleSetValueResponse{ |
| 3670 | Response: &extension.SetValueResponse{ |
| 3671 | Status: extension.SetValueResponse_OK, |
| 3672 | }, |
| 3673 | } |
| 3674 | |
| 3675 | return &singleValResp |
| 3676 | } |
| 3677 | |
| 3678 | func (dh *DeviceHandler) setOnuOffload(ctx context.Context, config *extension.AppOffloadOnuConfig) *extension.SingleSetValueResponse { |
Akash Soni | 3bcf5e0 | 2024-12-03 08:01:48 +0530 | [diff] [blame] | 3679 | |
| 3680 | singleValResp := extension.SingleSetValueResponse{ |
| 3681 | Response: &extension.SetValueResponse{ |
| 3682 | Status: extension.SetValueResponse_OK, |
| 3683 | }, |
| 3684 | } |
| 3685 | |
| 3686 | return &singleValResp |
| 3687 | } |
| 3688 | |
Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 3689 | func (dh *DeviceHandler) getOnuPonCounters(ctx context.Context, onuPonInfo *extension.GetOnuCountersRequest) *extension.SingleGetValueResponse { |
| 3690 | |
| 3691 | singleValResp := extension.SingleGetValueResponse{ |
| 3692 | Response: &extension.GetValueResponse{ |
| 3693 | Response: &extension.GetValueResponse_OnuPonCounters{ |
| 3694 | OnuPonCounters: &extension.GetOnuCountersResponse{}, |
| 3695 | }, |
| 3696 | }, |
| 3697 | } |
| 3698 | |
| 3699 | errResp := func(status extension.GetValueResponse_Status, |
| 3700 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 3701 | return &extension.SingleGetValueResponse{ |
| 3702 | Response: &extension.GetValueResponse{ |
| 3703 | Status: status, |
| 3704 | ErrReason: reason, |
| 3705 | }, |
| 3706 | } |
| 3707 | } |
| 3708 | intfID := onuPonInfo.IntfId |
| 3709 | onuID := onuPonInfo.OnuId |
| 3710 | onuKey := dh.formOnuKey(intfID, onuID) |
| 3711 | |
| 3712 | if _, ok := dh.onus.Load(onuKey); !ok { |
| 3713 | logger.Errorw(ctx, "get-onui-pon-counters-request-invalid-request-received", log.Fields{"intfID": intfID, "onuID": onuID}) |
| 3714 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE) |
| 3715 | } |
| 3716 | logger.Debugw(ctx, "get-onui-pon-counters-request-received", log.Fields{"intfID": intfID, "onuID": onuID}) |
| 3717 | cmnni := dh.portStats.collectOnDemandOnuStats(ctx, intfID, onuID) |
| 3718 | if cmnni == nil { |
| 3719 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 3720 | } |
| 3721 | dh.portStats.updateGetOnuPonCountersResponse(ctx, &singleValResp, cmnni) |
| 3722 | return &singleValResp |
| 3723 | |
| 3724 | } |
Gamze Abaka | 85e9a14 | 2021-05-26 13:41:39 +0000 | [diff] [blame] | 3725 | |
nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 3726 | func (dh *DeviceHandler) getOnuInfo(ctx context.Context, intfID uint32, onuID *uint32) (*oop.OnuInfo, error) { |
| 3727 | |
| 3728 | Onu := oop.Onu{IntfId: intfID, OnuId: *onuID} |
| 3729 | OnuInfo, err := dh.Client.GetOnuInfo(ctx, &Onu) |
| 3730 | if err != nil { |
| 3731 | return nil, err |
| 3732 | } |
| 3733 | return OnuInfo, nil |
| 3734 | |
| 3735 | } |
| 3736 | |
| 3737 | func (dh *DeviceHandler) getIntfInfo(ctx context.Context, intfID uint32) (*oop.PonIntfInfo, error) { |
| 3738 | |
| 3739 | Intf := oop.Interface{IntfId: intfID} |
| 3740 | IntfInfo, err := dh.Client.GetPonInterfaceInfo(ctx, &Intf) |
| 3741 | if err != nil { |
| 3742 | return nil, err |
| 3743 | } |
| 3744 | return IntfInfo, nil |
| 3745 | |
| 3746 | } |
| 3747 | |
Gamze Abaka | 85e9a14 | 2021-05-26 13:41:39 +0000 | [diff] [blame] | 3748 | func (dh *DeviceHandler) getRxPower(ctx context.Context, rxPowerRequest *extension.GetRxPowerRequest) *extension.SingleGetValueResponse { |
| 3749 | |
| 3750 | Onu := oop.Onu{IntfId: rxPowerRequest.IntfId, OnuId: rxPowerRequest.OnuId} |
| 3751 | rxPower, err := dh.Client.GetPonRxPower(ctx, &Onu) |
| 3752 | if err != nil { |
| 3753 | logger.Errorw(ctx, "error-while-getting-rx-power", log.Fields{"Onu": Onu, "err": err}) |
| 3754 | return generateSingleGetValueErrorResponse(err) |
| 3755 | } |
| 3756 | return &extension.SingleGetValueResponse{ |
| 3757 | Response: &extension.GetValueResponse{ |
| 3758 | Status: extension.GetValueResponse_OK, |
| 3759 | Response: &extension.GetValueResponse_RxPower{ |
| 3760 | RxPower: &extension.GetRxPowerResponse{ |
| 3761 | IntfId: rxPowerRequest.IntfId, |
| 3762 | OnuId: rxPowerRequest.OnuId, |
| 3763 | Status: rxPower.Status, |
| 3764 | FailReason: rxPower.FailReason.String(), |
| 3765 | RxPower: rxPower.RxPowerMeanDbm, |
| 3766 | }, |
| 3767 | }, |
| 3768 | }, |
| 3769 | } |
| 3770 | } |
| 3771 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 3772 | func (dh *DeviceHandler) getPONRxPower(ctx context.Context, OltRxPowerRequest *extension.GetOltRxPowerRequest) *extension.SingleGetValueResponse { |
| 3773 | |
| 3774 | errResp := func(status extension.GetValueResponse_Status, |
| 3775 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 3776 | return &extension.SingleGetValueResponse{ |
| 3777 | Response: &extension.GetValueResponse{ |
| 3778 | Status: status, |
| 3779 | ErrReason: reason, |
| 3780 | }, |
| 3781 | } |
| 3782 | } |
| 3783 | |
| 3784 | resp := extension.SingleGetValueResponse{ |
| 3785 | Response: &extension.GetValueResponse{ |
| 3786 | Status: extension.GetValueResponse_OK, |
| 3787 | Response: &extension.GetValueResponse_OltRxPower{ |
| 3788 | OltRxPower: &extension.GetOltRxPowerResponse{}, |
| 3789 | }, |
| 3790 | }, |
| 3791 | } |
| 3792 | |
| 3793 | logger.Debugw(ctx, "getPONRxPower", log.Fields{"portLabel": OltRxPowerRequest.PortLabel, "OnuSerialNumber": OltRxPowerRequest.OnuSn, "device-id": dh.device.Id}) |
| 3794 | portLabel := OltRxPowerRequest.PortLabel |
| 3795 | serialNumber := OltRxPowerRequest.OnuSn |
| 3796 | |
| 3797 | portInfo := strings.Split(portLabel, "-") |
| 3798 | portNumber, err := strconv.ParseUint(portInfo[1], 10, 32) |
| 3799 | |
| 3800 | if err != nil { |
| 3801 | logger.Errorw(ctx, "getPONRxPower invalid portNumber ", log.Fields{"oltPortNumber": portInfo[1]}) |
| 3802 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_REQ_TYPE) |
| 3803 | } |
| 3804 | |
| 3805 | if portInfo[0] != "pon" { |
| 3806 | logger.Errorw(ctx, "getPONRxPower invalid portType", log.Fields{"oltPortType": portInfo[0]}) |
| 3807 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_PORT_TYPE) |
| 3808 | } |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 3809 | |
| 3810 | if serialNumber != "" { |
| 3811 | |
| 3812 | onuDev := dh.getChildDevice(ctx, serialNumber, (uint32)(portNumber)) |
| 3813 | if onuDev != nil { |
| 3814 | |
| 3815 | Onu := oop.Onu{IntfId: uint32(portNumber), OnuId: onuDev.onuID} |
| 3816 | rxPower, err := dh.Client.GetPonRxPower(ctx, &Onu) |
| 3817 | if err != nil { |
| 3818 | |
| 3819 | logger.Errorw(ctx, "error-while-getting-rx-power", log.Fields{"Onu": Onu, "err": err}) |
| 3820 | return generateSingleGetValueErrorResponse(err) |
| 3821 | |
| 3822 | } |
| 3823 | |
| 3824 | rxPowerValue := extension.RxPower{} |
| 3825 | rxPowerValue.OnuSn = onuDev.serialNumber |
| 3826 | rxPowerValue.Status = rxPower.GetStatus() |
| 3827 | rxPowerValue.RxPower = rxPower.GetRxPowerMeanDbm() |
| 3828 | rxPowerValue.FailReason = rxPower.GetFailReason().String() |
| 3829 | |
| 3830 | resp.Response.GetOltRxPower().RxPower = append(resp.Response.GetOltRxPower().RxPower, &rxPowerValue) |
| 3831 | |
| 3832 | } else { |
| 3833 | |
| 3834 | logger.Errorw(ctx, "getPONRxPower invalid Device", log.Fields{"portLabel": portLabel, "serialNumber": serialNumber}) |
| 3835 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE) |
| 3836 | } |
| 3837 | |
| 3838 | } else { |
| 3839 | |
| 3840 | dh.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool { |
praneeth kumar nalmas | b234f23 | 2023-11-29 12:50:46 +0530 | [diff] [blame] | 3841 | if onuInCache.(*OnuDevice).intfID == (uint32)(portNumber) { |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 3842 | |
praneeth kumar nalmas | b234f23 | 2023-11-29 12:50:46 +0530 | [diff] [blame] | 3843 | Onu := oop.Onu{IntfId: (uint32)(portNumber), OnuId: onuInCache.(*OnuDevice).onuID} |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 3844 | rxPower, err := dh.Client.GetPonRxPower(ctx, &Onu) |
| 3845 | if err != nil { |
| 3846 | logger.Errorw(ctx, "error-while-getting-rx-power, however considering to proceed further with other ONUs on PON", log.Fields{"Onu": Onu, "err": err}) |
| 3847 | } else { |
| 3848 | |
| 3849 | rxPowerValue := extension.RxPower{} |
| 3850 | rxPowerValue.OnuSn = onuInCache.(*OnuDevice).serialNumber |
| 3851 | rxPowerValue.Status = rxPower.GetStatus() |
| 3852 | rxPowerValue.RxPower = rxPower.GetRxPowerMeanDbm() |
| 3853 | rxPowerValue.FailReason = rxPower.GetFailReason().String() |
| 3854 | |
| 3855 | resp.Response.GetOltRxPower().RxPower = append(resp.Response.GetOltRxPower().RxPower, &rxPowerValue) |
| 3856 | } |
| 3857 | |
| 3858 | } |
| 3859 | logger.Infow(ctx, "getPONRxPower response ", log.Fields{"Response": resp}) |
| 3860 | return true |
| 3861 | }) |
| 3862 | } |
| 3863 | logger.Infow(ctx, "getPONRxPower response ", log.Fields{"Response": resp}) |
| 3864 | return &resp |
| 3865 | } |
| 3866 | |
Gamze Abaka | 85e9a14 | 2021-05-26 13:41:39 +0000 | [diff] [blame] | 3867 | func generateSingleGetValueErrorResponse(err error) *extension.SingleGetValueResponse { |
| 3868 | errResp := func(status extension.GetValueResponse_Status, |
| 3869 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 3870 | return &extension.SingleGetValueResponse{ |
| 3871 | Response: &extension.GetValueResponse{ |
| 3872 | Status: status, |
| 3873 | ErrReason: reason, |
| 3874 | }, |
| 3875 | } |
| 3876 | } |
| 3877 | |
| 3878 | if err != nil { |
| 3879 | if e, ok := status.FromError(err); ok { |
| 3880 | switch e.Code() { |
| 3881 | case codes.Internal: |
| 3882 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 3883 | case codes.DeadlineExceeded: |
| 3884 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_TIMEOUT) |
| 3885 | case codes.Unimplemented: |
| 3886 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_UNSUPPORTED) |
| 3887 | case codes.NotFound: |
| 3888 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE) |
| 3889 | } |
| 3890 | } |
| 3891 | } |
| 3892 | |
| 3893 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_REASON_UNDEFINED) |
| 3894 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3895 | |
| 3896 | /* |
| 3897 | Helper functions to communicate with Core |
| 3898 | */ |
| 3899 | |
| 3900 | func (dh *DeviceHandler) getDeviceFromCore(ctx context.Context, deviceID string) (*voltha.Device, error) { |
| 3901 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3902 | if err != nil || cClient == nil { |
| 3903 | return nil, err |
| 3904 | } |
| 3905 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 3906 | defer cancel() |
| 3907 | return cClient.GetDevice(subCtx, &common.ID{Id: deviceID}) |
| 3908 | } |
| 3909 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3910 | func (dh *DeviceHandler) getChildDeviceFromCore(ctx context.Context, childDeviceFilter *ca.ChildDeviceFilter) (*voltha.Device, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3911 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3912 | if err != nil || cClient == nil { |
| 3913 | return nil, err |
| 3914 | } |
| 3915 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 3916 | defer cancel() |
| 3917 | return cClient.GetChildDevice(subCtx, childDeviceFilter) |
| 3918 | } |
| 3919 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3920 | func (dh *DeviceHandler) updateDeviceStateInCore(ctx context.Context, deviceStateFilter *ca.DeviceStateFilter) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3921 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3922 | if err != nil || cClient == nil { |
| 3923 | return err |
| 3924 | } |
| 3925 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 3926 | defer cancel() |
| 3927 | _, err = cClient.DeviceStateUpdate(subCtx, deviceStateFilter) |
| 3928 | return err |
| 3929 | } |
| 3930 | |
| 3931 | func (dh *DeviceHandler) getChildDevicesFromCore(ctx context.Context, deviceID string) (*voltha.Devices, error) { |
| 3932 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3933 | if err != nil || cClient == nil { |
| 3934 | return nil, err |
| 3935 | } |
| 3936 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 3937 | defer cancel() |
| 3938 | return cClient.GetChildDevices(subCtx, &common.ID{Id: deviceID}) |
| 3939 | } |
| 3940 | |
| 3941 | func (dh *DeviceHandler) listDevicePortsFromCore(ctx context.Context, deviceID string) (*voltha.Ports, error) { |
| 3942 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3943 | if err != nil || cClient == nil { |
| 3944 | return nil, err |
| 3945 | } |
| 3946 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 3947 | defer cancel() |
| 3948 | return cClient.ListDevicePorts(subCtx, &common.ID{Id: deviceID}) |
| 3949 | } |
| 3950 | |
| 3951 | func (dh *DeviceHandler) updateDeviceInCore(ctx context.Context, device *voltha.Device) error { |
| 3952 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3953 | if err != nil || cClient == nil { |
| 3954 | return err |
| 3955 | } |
| 3956 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 3957 | defer cancel() |
| 3958 | _, err = cClient.DeviceUpdate(subCtx, device) |
| 3959 | return err |
| 3960 | } |
| 3961 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3962 | func (dh *DeviceHandler) sendChildDeviceDetectedToCore(ctx context.Context, deviceDiscoveryInfo *ca.DeviceDiscovery) (*voltha.Device, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3963 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3964 | if err != nil || cClient == nil { |
| 3965 | return nil, err |
| 3966 | } |
| 3967 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 3968 | defer cancel() |
| 3969 | return cClient.ChildDeviceDetected(subCtx, deviceDiscoveryInfo) |
| 3970 | } |
| 3971 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3972 | func (dh *DeviceHandler) sendPacketToCore(ctx context.Context, pkt *ca.PacketIn) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3973 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3974 | if err != nil || cClient == nil { |
| 3975 | return err |
| 3976 | } |
| 3977 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 3978 | defer cancel() |
| 3979 | _, err = cClient.SendPacketIn(subCtx, pkt) |
| 3980 | return err |
| 3981 | } |
| 3982 | |
| 3983 | func (dh *DeviceHandler) createPortInCore(ctx context.Context, port *voltha.Port) error { |
| 3984 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3985 | if err != nil || cClient == nil { |
| 3986 | return err |
| 3987 | } |
| 3988 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 3989 | defer cancel() |
| 3990 | _, err = cClient.PortCreated(subCtx, port) |
| 3991 | return err |
| 3992 | } |
| 3993 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3994 | func (dh *DeviceHandler) updatePortsStateInCore(ctx context.Context, portFilter *ca.PortStateFilter) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3995 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3996 | if err != nil || cClient == nil { |
| 3997 | return err |
| 3998 | } |
| 3999 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4000 | defer cancel() |
| 4001 | _, err = cClient.PortsStateUpdate(subCtx, portFilter) |
| 4002 | return err |
| 4003 | } |
| 4004 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4005 | func (dh *DeviceHandler) updatePortStateInCore(ctx context.Context, portState *ca.PortState) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4006 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4007 | if err != nil || cClient == nil { |
| 4008 | return err |
| 4009 | } |
| 4010 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4011 | defer cancel() |
| 4012 | _, err = cClient.PortStateUpdate(subCtx, portState) |
| 4013 | return err |
| 4014 | } |
| 4015 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4016 | func (dh *DeviceHandler) getPortFromCore(ctx context.Context, portFilter *ca.PortFilter) (*voltha.Port, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4017 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4018 | if err != nil || cClient == nil { |
| 4019 | return nil, err |
| 4020 | } |
| 4021 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4022 | defer cancel() |
| 4023 | return cClient.GetDevicePort(subCtx, portFilter) |
| 4024 | } |
| 4025 | |
nikesh.krishnan | c847343 | 2023-06-14 12:14:54 +0530 | [diff] [blame] | 4026 | func (dh *DeviceHandler) getAllPortsFromCore(ctx context.Context, portFilter *ca.PortFilter) (*voltha.Ports, error) { |
| 4027 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4028 | if err != nil || cClient == nil { |
| 4029 | return nil, err |
| 4030 | } |
| 4031 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4032 | defer cancel() |
| 4033 | return cClient.GetPorts(subCtx, portFilter) |
| 4034 | } |
| 4035 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4036 | /* |
| 4037 | Helper functions to communicate with child adapter |
| 4038 | */ |
| 4039 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4040 | func (dh *DeviceHandler) sendOmciIndicationToChildAdapter(ctx context.Context, childEndpoint string, response *ia.OmciMessage) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4041 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 4042 | if err != nil || aClient == nil { |
| 4043 | return err |
| 4044 | } |
| 4045 | logger.Debugw(ctx, "sending-omci-response", log.Fields{"response": response, "child-endpoint": childEndpoint}) |
| 4046 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4047 | defer cancel() |
| 4048 | _, err = aClient.OmciIndication(subCtx, response) |
| 4049 | return err |
| 4050 | } |
| 4051 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4052 | func (dh *DeviceHandler) sendOnuIndicationToChildAdapter(ctx context.Context, childEndpoint string, onuInd *ia.OnuIndicationMessage) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4053 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 4054 | if err != nil || aClient == nil { |
| 4055 | return err |
| 4056 | } |
| 4057 | logger.Debugw(ctx, "sending-onu-indication", log.Fields{"onu-indication": onuInd, "child-endpoint": childEndpoint}) |
| 4058 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4059 | defer cancel() |
| 4060 | _, err = aClient.OnuIndication(subCtx, onuInd) |
| 4061 | return err |
| 4062 | } |
| 4063 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4064 | func (dh *DeviceHandler) sendDeleteTContToChildAdapter(ctx context.Context, childEndpoint string, tContInfo *ia.DeleteTcontMessage) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4065 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 4066 | if err != nil || aClient == nil { |
| 4067 | return err |
| 4068 | } |
| 4069 | logger.Debugw(ctx, "sending-delete-tcont", log.Fields{"tcont": tContInfo, "child-endpoint": childEndpoint}) |
| 4070 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4071 | defer cancel() |
| 4072 | _, err = aClient.DeleteTCont(subCtx, tContInfo) |
| 4073 | return err |
| 4074 | } |
| 4075 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4076 | func (dh *DeviceHandler) sendDeleteGemPortToChildAdapter(ctx context.Context, childEndpoint string, gemPortInfo *ia.DeleteGemPortMessage) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4077 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 4078 | if err != nil || aClient == nil { |
| 4079 | return err |
| 4080 | } |
| 4081 | logger.Debugw(ctx, "sending-delete-gem-port", log.Fields{"gem-port-info": gemPortInfo, "child-endpoint": childEndpoint}) |
| 4082 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4083 | defer cancel() |
| 4084 | _, err = aClient.DeleteGemPort(subCtx, gemPortInfo) |
| 4085 | return err |
| 4086 | } |
| 4087 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4088 | func (dh *DeviceHandler) sendDownloadTechProfileToChildAdapter(ctx context.Context, childEndpoint string, tpDownloadInfo *ia.TechProfileDownloadMessage) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4089 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 4090 | if err != nil || aClient == nil { |
| 4091 | return err |
| 4092 | } |
| 4093 | logger.Debugw(ctx, "sending-tech-profile-download", log.Fields{"tp-download-info": tpDownloadInfo, "child-endpoint": childEndpoint}) |
| 4094 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 4095 | defer cancel() |
| 4096 | _, err = aClient.DownloadTechProfile(subCtx, tpDownloadInfo) |
| 4097 | return err |
| 4098 | } |
| 4099 | |
| 4100 | /* |
| 4101 | Helper functions for remote communication |
| 4102 | */ |
| 4103 | |
| 4104 | // TODO: Use a connection tracker such that the adapter connection is stopped when the last device that adapter |
| 4105 | // supports is deleted |
| 4106 | func (dh *DeviceHandler) setupChildInterAdapterClient(ctx context.Context, endpoint string) error { |
| 4107 | logger.Infow(ctx, "setting-child-adapter-connection", log.Fields{"child-endpoint": endpoint}) |
| 4108 | |
| 4109 | dh.lockChildAdapterClients.Lock() |
| 4110 | defer dh.lockChildAdapterClients.Unlock() |
| 4111 | if _, ok := dh.childAdapterClients[endpoint]; ok { |
| 4112 | // Already set |
| 4113 | return nil |
| 4114 | } |
| 4115 | |
| 4116 | // Setup child's adapter grpc connection |
| 4117 | var err error |
khenaidoo | 27e7ac9 | 2021-12-08 14:43:09 -0500 | [diff] [blame] | 4118 | if dh.childAdapterClients[endpoint], err = vgrpc.NewClient( |
| 4119 | dh.cfg.AdapterEndpoint, |
| 4120 | endpoint, |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 4121 | "onu_inter_adapter_service.OnuInterAdapterService", |
| 4122 | dh.onuInterAdapterRestarted, |
| 4123 | vgrpc.ClientContextData(dh.device.Id)); err != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4124 | logger.Errorw(ctx, "grpc-client-not-created", log.Fields{"error": err, "endpoint": endpoint}) |
| 4125 | return err |
| 4126 | } |
nikesh.krishnan | d981254 | 2023-08-01 18:31:39 +0530 | [diff] [blame] | 4127 | retryCodes := []codes.Code{ |
| 4128 | codes.Unavailable, // server is currently unavailable |
| 4129 | codes.DeadlineExceeded, // deadline for the operation was exceeded |
| 4130 | } |
| 4131 | backoffCtxOption := grpc_retry.WithBackoff(grpc_retry.BackoffLinearWithJitter(dh.cfg.PerRPCRetryTimeout, 0.2)) |
| 4132 | 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] | 4133 | |
nikesh.krishnan | d981254 | 2023-08-01 18:31:39 +0530 | [diff] [blame] | 4134 | go dh.childAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), dh.getOnuInterAdapterServiceClientHandler, grpcRetryOptions) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4135 | // Wait until we have a connection to the child adapter. |
| 4136 | // Unlimited retries or until context expires |
| 4137 | subCtx := log.WithSpanFromContext(context.TODO(), ctx) |
| 4138 | backoff := vgrpc.NewBackoff(dh.cfg.MinBackoffRetryDelay, dh.cfg.MaxBackoffRetryDelay, 0) |
| 4139 | for { |
| 4140 | client, err := dh.childAdapterClients[endpoint].GetOnuInterAdapterServiceClient() |
| 4141 | if err == nil && client != nil { |
| 4142 | logger.Infow(subCtx, "connected-to-child-adapter", log.Fields{"child-endpoint": endpoint}) |
| 4143 | break |
| 4144 | } |
| 4145 | logger.Warnw(subCtx, "connection-to-child-adapter-not-ready", log.Fields{"error": err, "child-endpoint": endpoint}) |
| 4146 | // Backoff |
| 4147 | if err = backoff.Backoff(subCtx); err != nil { |
| 4148 | logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "child-endpoint": endpoint}) |
| 4149 | break |
| 4150 | } |
| 4151 | } |
| 4152 | return nil |
| 4153 | } |
| 4154 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 4155 | func (dh *DeviceHandler) getChildAdapterServiceClient(endpoint string) (onu_inter_adapter_service.OnuInterAdapterServiceClient, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4156 | |
| 4157 | // First check from cache |
| 4158 | dh.lockChildAdapterClients.RLock() |
| 4159 | if cgClient, ok := dh.childAdapterClients[endpoint]; ok { |
| 4160 | dh.lockChildAdapterClients.RUnlock() |
| 4161 | return cgClient.GetOnuInterAdapterServiceClient() |
| 4162 | } |
| 4163 | dh.lockChildAdapterClients.RUnlock() |
| 4164 | |
| 4165 | // Set the child connection - can occur on restarts |
| 4166 | ctx, cancel := context.WithTimeout(context.Background(), dh.cfg.RPCTimeout) |
| 4167 | err := dh.setupChildInterAdapterClient(ctx, endpoint) |
| 4168 | cancel() |
| 4169 | if err != nil { |
| 4170 | return nil, err |
| 4171 | } |
| 4172 | |
| 4173 | // Get the child client now |
| 4174 | dh.lockChildAdapterClients.RLock() |
| 4175 | defer dh.lockChildAdapterClients.RUnlock() |
| 4176 | if cgClient, ok := dh.childAdapterClients[endpoint]; ok { |
| 4177 | return cgClient.GetOnuInterAdapterServiceClient() |
| 4178 | } |
| 4179 | return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint) |
| 4180 | } |
| 4181 | |
| 4182 | func (dh *DeviceHandler) deleteAdapterClients(ctx context.Context) { |
| 4183 | dh.lockChildAdapterClients.Lock() |
| 4184 | defer dh.lockChildAdapterClients.Unlock() |
| 4185 | for key, client := range dh.childAdapterClients { |
| 4186 | client.Stop(ctx) |
| 4187 | delete(dh.childAdapterClients, key) |
| 4188 | } |
| 4189 | } |
| 4190 | |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 4191 | // TODO: Any action the adapter needs to do following a onu adapter inter adapter service restart? |
| 4192 | func (dh *DeviceHandler) onuInterAdapterRestarted(ctx context.Context, endPoint string) error { |
| 4193 | logger.Warnw(ctx, "onu-inter-adapter-service-reconnected", log.Fields{"endpoint": endPoint}) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4194 | return nil |
| 4195 | } |
| 4196 | |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 4197 | // getOnuInterAdapterServiceClientHandler is used to setup the remote gRPC service |
| 4198 | func (dh *DeviceHandler) getOnuInterAdapterServiceClientHandler(ctx context.Context, conn *grpc.ClientConn) interface{} { |
| 4199 | if conn == nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4200 | return nil |
| 4201 | } |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 4202 | return onu_inter_adapter_service.NewOnuInterAdapterServiceClient(conn) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 4203 | } |
Girish Gowdra | 950326e | 2021-11-05 12:43:24 -0700 | [diff] [blame] | 4204 | |
| 4205 | func (dh *DeviceHandler) setDeviceDeletionInProgressFlag(flag bool) { |
| 4206 | dh.lockDevice.Lock() |
| 4207 | defer dh.lockDevice.Unlock() |
| 4208 | dh.isDeviceDeletionInProgress = flag |
| 4209 | } |
| 4210 | |
| 4211 | func (dh *DeviceHandler) getDeviceDeletionInProgressFlag() bool { |
| 4212 | dh.lockDevice.RLock() |
| 4213 | defer dh.lockDevice.RUnlock() |
| 4214 | return dh.isDeviceDeletionInProgress |
| 4215 | } |
Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 4216 | |
| 4217 | // waitForTimeoutOrCompletion waits for the waitgroup for the specified max timeout. |
| 4218 | // Returns false if waiting timed out. |
| 4219 | func (dh *DeviceHandler) waitForTimeoutOrCompletion(wg *sync.WaitGroup, timeout time.Duration) bool { |
| 4220 | c := make(chan struct{}) |
| 4221 | go func() { |
| 4222 | defer close(c) |
| 4223 | wg.Wait() |
| 4224 | }() |
| 4225 | select { |
| 4226 | case <-c: |
| 4227 | return true // completed normally |
| 4228 | case <-time.After(timeout): |
| 4229 | return false // timed out |
| 4230 | } |
| 4231 | } |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 4232 | |
| 4233 | func (dh *DeviceHandler) updateHeartbeatSignature(ctx context.Context, signature uint32) { |
| 4234 | val, err := json.Marshal(signature) |
| 4235 | if err != nil { |
| 4236 | logger.Error(ctx, "failed-to-marshal") |
| 4237 | return |
| 4238 | } |
| 4239 | if err = dh.kvStore.Put(ctx, heartbeatPath, val); err != nil { |
| 4240 | logger.Error(ctx, "failed-to-store-hearbeat-signature") |
| 4241 | } |
| 4242 | } |
| 4243 | |
| 4244 | func (dh *DeviceHandler) getHeartbeatSignature(ctx context.Context) uint32 { |
| 4245 | var signature uint32 |
| 4246 | |
| 4247 | Value, er := dh.kvStore.Get(ctx, heartbeatPath) |
| 4248 | if er == nil { |
| 4249 | if Value != nil { |
| 4250 | Val, er := kvstore.ToByte(Value.Value) |
| 4251 | if er != nil { |
| 4252 | logger.Errorw(ctx, "Failed to convert into byte array", log.Fields{"err": er}) |
| 4253 | return signature |
| 4254 | } |
| 4255 | if er = json.Unmarshal(Val, &signature); er != nil { |
| 4256 | logger.Error(ctx, "Failed to unmarshal signature", log.Fields{"err": er}) |
| 4257 | return signature |
| 4258 | } |
| 4259 | } |
| 4260 | } |
| 4261 | return signature |
| 4262 | } |