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