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