Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 16 | |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 17 | //Package core provides the utility for olt devices, flows and statistics |
| 18 | package core |
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" |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 24 | "errors" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 25 | "fmt" |
| 26 | "io" |
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 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 33 | "github.com/golang/protobuf/ptypes/empty" |
| 34 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 35 | "github.com/opencord/voltha-protos/v5/go/adapter_services" |
| 36 | |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 37 | "github.com/cenkalti/backoff/v3" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 38 | "github.com/gogo/protobuf/proto" |
Girish Kumar | 93e9174 | 2020-07-27 16:43:19 +0000 | [diff] [blame] | 39 | grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" |
| 40 | grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 41 | "github.com/opencord/voltha-lib-go/v7/pkg/config" |
| 42 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
| 43 | flow_utils "github.com/opencord/voltha-lib-go/v7/pkg/flows" |
| 44 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| 45 | "github.com/opencord/voltha-lib-go/v7/pkg/pmmetrics" |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 46 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 47 | conf "github.com/opencord/voltha-openolt-adapter/internal/pkg/config" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 48 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 49 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 50 | "github.com/opencord/voltha-protos/v5/go/common" |
| 51 | "github.com/opencord/voltha-protos/v5/go/extension" |
| 52 | ic "github.com/opencord/voltha-protos/v5/go/inter_container" |
| 53 | of "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 54 | oop "github.com/opencord/voltha-protos/v5/go/openolt" |
| 55 | "github.com/opencord/voltha-protos/v5/go/voltha" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 56 | "google.golang.org/grpc" |
Devmalya Paul | a1efa64 | 2020-04-20 01:36:43 -0400 | [diff] [blame] | 57 | "google.golang.org/grpc/codes" |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 58 | "google.golang.org/grpc/status" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 59 | ) |
| 60 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 61 | // Constants for number of retries and for timeout |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 62 | const ( |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 63 | InvalidPort = 0xffffffff |
| 64 | MaxNumOfGroupHandlerChannels = 256 |
| 65 | |
| 66 | McastFlowOrGroupAdd = "McastFlowOrGroupAdd" |
| 67 | McastFlowOrGroupModify = "McastFlowOrGroupModify" |
| 68 | McastFlowOrGroupRemove = "McastFlowOrGroupRemove" |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 69 | oltPortInfoTimeout = 3 |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 70 | ) |
| 71 | |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 72 | //DeviceHandler will interact with the OLT device. |
| 73 | type DeviceHandler struct { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 74 | cm *config.ConfigManager |
| 75 | device *voltha.Device |
| 76 | cfg *conf.AdapterFlags |
| 77 | coreClient *vgrpc.Client |
| 78 | childAdapterClients map[string]*vgrpc.Client |
| 79 | lockChildAdapterClients sync.RWMutex |
| 80 | EventProxy eventif.EventProxy |
| 81 | openOLT *OpenOLT |
| 82 | exitChannel chan int |
| 83 | lockDevice sync.RWMutex |
| 84 | Client oop.OpenoltClient |
| 85 | transitionMap *TransitionMap |
| 86 | clientCon *grpc.ClientConn |
| 87 | flowMgr []*OpenOltFlowMgr |
| 88 | groupMgr *OpenOltGroupMgr |
| 89 | eventMgr *OpenOltEventMgr |
| 90 | resourceMgr []*rsrcMgr.OpenOltResourceMgr |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 91 | |
| 92 | deviceInfo *oop.DeviceInfo |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 93 | |
Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 94 | discOnus sync.Map |
| 95 | onus sync.Map |
| 96 | portStats *OpenOltStatisticsMgr |
| 97 | metrics *pmmetrics.PmMetrics |
| 98 | stopCollector chan bool |
| 99 | stopHeartbeatCheck chan bool |
| 100 | activePorts sync.Map |
| 101 | stopIndications chan bool |
| 102 | isReadIndicationRoutineActive bool |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 103 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 104 | totalPonPorts uint32 |
| 105 | perPonOnuIndicationChannel map[uint32]onuIndicationChannels |
| 106 | perPonOnuIndicationChannelLock sync.Mutex |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 107 | |
| 108 | // Slice of channels. Each channel in slice, index by (mcast-group-id modulo MaxNumOfGroupHandlerChannels) |
| 109 | // 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] | 110 | incomingMcastFlowOrGroup []chan McastFlowOrGroupControlBlock |
| 111 | stopMcastHandlerRoutine []chan bool |
| 112 | mcastHandlerRoutineActive []bool |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 113 | |
| 114 | adapterPreviouslyConnected bool |
| 115 | agentPreviouslyConnected bool |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 118 | //OnuDevice represents ONU related info |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 119 | type OnuDevice struct { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 120 | deviceID string |
| 121 | deviceType string |
| 122 | serialNumber string |
| 123 | onuID uint32 |
| 124 | intfID uint32 |
| 125 | proxyDeviceID string |
| 126 | losRaised bool |
| 127 | rdiRaised bool |
| 128 | adapterEndpoint string |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 131 | type onuIndicationMsg struct { |
| 132 | ctx context.Context |
| 133 | indication *oop.Indication |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | type onuIndicationChannels struct { |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 137 | indicationChannel chan onuIndicationMsg |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 138 | stopChannel chan struct{} |
| 139 | } |
| 140 | |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 141 | //McastFlowOrGroupControlBlock is created per mcast flow/group add/modify/remove and pushed on the incomingMcastFlowOrGroup channel slice |
| 142 | //The McastFlowOrGroupControlBlock is then picked by the mcastFlowOrGroupChannelHandlerRoutine for further processing. |
| 143 | //There are MaxNumOfGroupHandlerChannels number of mcastFlowOrGroupChannelHandlerRoutine routines which monitor for any incoming mcast flow/group messages |
| 144 | //and process them serially. The mcast flow/group are assigned these routines based on formula (group-id modulo MaxNumOfGroupHandlerChannels) |
| 145 | type McastFlowOrGroupControlBlock struct { |
| 146 | ctx context.Context // Flow/group handler context |
| 147 | flowOrGroupAction string // one of McastFlowOrGroupAdd, McastFlowOrGroupModify or McastFlowOrGroupDelete |
| 148 | flow *voltha.OfpFlowStats // Flow message (can be nil or valid flow) |
| 149 | group *voltha.OfpGroupEntry // Group message (can be nil or valid group) |
| 150 | errChan *chan error // channel to report the mcast Flow/group handling error |
| 151 | } |
| 152 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 153 | var pmNames = []string{ |
| 154 | "rx_bytes", |
| 155 | "rx_packets", |
| 156 | "rx_mcast_packets", |
| 157 | "rx_bcast_packets", |
| 158 | "tx_bytes", |
| 159 | "tx_packets", |
| 160 | "tx_mcast_packets", |
| 161 | "tx_bcast_packets", |
| 162 | } |
| 163 | |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 164 | //NewOnuDevice creates a new Onu Device |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 165 | 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] | 166 | var device OnuDevice |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 167 | device.deviceID = devID |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 168 | device.deviceType = deviceTp |
| 169 | device.serialNumber = serialNum |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 170 | device.onuID = onuID |
| 171 | device.intfID = intfID |
| 172 | device.proxyDeviceID = proxyDevID |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 173 | device.losRaised = losRaised |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 174 | device.adapterEndpoint = adapterEndpoint |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 175 | return &device |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | //NewDeviceHandler creates a new device handler |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 179 | 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] | 180 | var dh DeviceHandler |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 181 | dh.cm = cm |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 182 | dh.coreClient = cc |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 183 | dh.EventProxy = ep |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 184 | cloned := (proto.Clone(device)).(*voltha.Device) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 185 | dh.device = cloned |
| 186 | dh.openOLT = adapter |
| 187 | dh.exitChannel = make(chan int, 1) |
| 188 | dh.lockDevice = sync.RWMutex{} |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 189 | dh.stopCollector = make(chan bool, 2) |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 190 | dh.stopHeartbeatCheck = make(chan bool, 2) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 191 | 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] | 192 | dh.activePorts = sync.Map{} |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 193 | dh.stopIndications = make(chan bool, 1) |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 194 | dh.perPonOnuIndicationChannel = make(map[uint32]onuIndicationChannels) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 195 | dh.childAdapterClients = make(map[string]*vgrpc.Client) |
| 196 | dh.cfg = cfg |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 197 | // Create a slice of buffered channels for handling concurrent mcast flow/group. |
| 198 | dh.incomingMcastFlowOrGroup = make([]chan McastFlowOrGroupControlBlock, MaxNumOfGroupHandlerChannels) |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 199 | dh.stopMcastHandlerRoutine = make([]chan bool, MaxNumOfGroupHandlerChannels) |
| 200 | dh.mcastHandlerRoutineActive = make([]bool, MaxNumOfGroupHandlerChannels) |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 201 | for i := range dh.incomingMcastFlowOrGroup { |
| 202 | dh.incomingMcastFlowOrGroup[i] = make(chan McastFlowOrGroupControlBlock, MaxNumOfGroupHandlerChannels) |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 203 | dh.stopMcastHandlerRoutine[i] = make(chan bool, 1) |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 204 | // Spin up a go routine to handling incoming mcast flow/group (add/modify/remove). |
| 205 | // There will be MaxNumOfGroupHandlerChannels number of mcastFlowOrGroupChannelHandlerRoutine go routines. |
| 206 | // These routines will be blocked on the dh.incomingMcastFlowOrGroup[mcast-group-id modulo MaxNumOfGroupHandlerChannels] channel |
| 207 | // for incoming mcast flow/group to be processed serially. |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 208 | dh.mcastHandlerRoutineActive[i] = true |
| 209 | go dh.mcastFlowOrGroupChannelHandlerRoutine(i, dh.incomingMcastFlowOrGroup[i], dh.stopMcastHandlerRoutine[i]) |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 210 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 211 | //TODO initialize the support classes. |
| 212 | return &dh |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | // start save the device to the data model |
| 216 | func (dh *DeviceHandler) start(ctx context.Context) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 217 | dh.lockDevice.Lock() |
| 218 | defer dh.lockDevice.Unlock() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 219 | logger.Debugw(ctx, "starting-device-agent", log.Fields{"device": dh.device}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 220 | // Add the initial device to the local model |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 221 | logger.Debug(ctx, "device-agent-started") |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | // stop stops the device dh. Not much to do for now |
| 225 | func (dh *DeviceHandler) stop(ctx context.Context) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 226 | dh.lockDevice.Lock() |
| 227 | defer dh.lockDevice.Unlock() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 228 | logger.Debug(ctx, "stopping-device-agent") |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 229 | dh.exitChannel <- 1 |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 230 | |
| 231 | // Stop the adapter grpc clients for that parent device |
| 232 | dh.deleteAdapterClients(ctx) |
| 233 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 234 | logger.Debug(ctx, "device-agent-stopped") |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 235 | } |
| 236 | |
ssiddiqui | 04386ee | 2021-08-23 21:58:25 +0530 | [diff] [blame] | 237 | func (dh *DeviceHandler) getPonTechnology(intfID uint32) string { |
| 238 | for _, resourceRanges := range dh.deviceInfo.GetRanges() { |
| 239 | for _, pooledIntfID := range resourceRanges.GetIntfIds() { |
| 240 | if pooledIntfID == intfID { |
| 241 | return resourceRanges.GetTechnology() |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | return "" |
| 246 | } |
| 247 | |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 248 | func macifyIP(ip net.IP) string { |
| 249 | if len(ip) > 0 { |
| 250 | oct1 := strconv.FormatInt(int64(ip[12]), 16) |
| 251 | oct2 := strconv.FormatInt(int64(ip[13]), 16) |
| 252 | oct3 := strconv.FormatInt(int64(ip[14]), 16) |
| 253 | oct4 := strconv.FormatInt(int64(ip[15]), 16) |
| 254 | return fmt.Sprintf("00:00:%02v:%02v:%02v:%02v", oct1, oct2, oct3, oct4) |
| 255 | } |
| 256 | return "" |
| 257 | } |
| 258 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 259 | func generateMacFromHost(ctx context.Context, host string) (string, error) { |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 260 | var genmac string |
| 261 | var addr net.IP |
| 262 | var ips []string |
| 263 | var err error |
| 264 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 265 | logger.Debugw(ctx, "generating-mac-from-host", log.Fields{"host": host}) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 266 | |
| 267 | if addr = net.ParseIP(host); addr == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 268 | logger.Debugw(ctx, "looking-up-hostname", log.Fields{"host": host}) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 269 | |
| 270 | if ips, err = net.LookupHost(host); err == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 271 | logger.Debugw(ctx, "dns-result-ips", log.Fields{"ips": ips}) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 272 | if addr = net.ParseIP(ips[0]); addr == nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 273 | return "", olterrors.NewErrInvalidValue(log.Fields{"ip": ips[0]}, nil) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 274 | } |
| 275 | genmac = macifyIP(addr) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 276 | logger.Debugw(ctx, "using-ip-as-mac", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 277 | log.Fields{"host": ips[0], |
| 278 | "mac": genmac}) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 279 | return genmac, nil |
| 280 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 281 | 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] | 282 | } |
| 283 | |
| 284 | genmac = macifyIP(addr) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 285 | logger.Debugw(ctx, "using-ip-as-mac", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 286 | log.Fields{"host": host, |
| 287 | "mac": genmac}) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 288 | return genmac, nil |
| 289 | } |
| 290 | |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 291 | func macAddressToUint32Array(mac string) []uint32 { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 292 | slist := strings.Split(mac, ":") |
| 293 | result := make([]uint32, len(slist)) |
| 294 | var err error |
| 295 | var tmp int64 |
| 296 | for index, val := range slist { |
| 297 | if tmp, err = strconv.ParseInt(val, 16, 32); err != nil { |
| 298 | return []uint32{1, 2, 3, 4, 5, 6} |
| 299 | } |
| 300 | result[index] = uint32(tmp) |
| 301 | } |
| 302 | return result |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 303 | } |
| 304 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 305 | //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] | 306 | func GetportLabel(portNum uint32, portType voltha.Port_PortType) (string, error) { |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 307 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 308 | switch portType { |
| 309 | case voltha.Port_ETHERNET_NNI: |
| 310 | return fmt.Sprintf("nni-%d", portNum), nil |
| 311 | case voltha.Port_PON_OLT: |
| 312 | return fmt.Sprintf("pon-%d", portNum), nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 313 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 314 | |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 315 | return "", olterrors.NewErrInvalidValue(log.Fields{"port-type": portType}, nil) |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 316 | } |
| 317 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 318 | func (dh *DeviceHandler) addPort(ctx context.Context, intfID uint32, portType voltha.Port_PortType, state string) error { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 319 | var operStatus common.OperStatus_Types |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 320 | if state == "up" { |
| 321 | operStatus = voltha.OperStatus_ACTIVE |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 322 | //populating the intfStatus map |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 323 | dh.activePorts.Store(intfID, true) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 324 | } else { |
| 325 | operStatus = voltha.OperStatus_DISCOVERED |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 326 | dh.activePorts.Store(intfID, false) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 327 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 328 | portNum := IntfIDToPortNo(intfID, portType) |
Chaitrashree G S | c0878ec | 2020-05-21 04:59:53 -0400 | [diff] [blame] | 329 | label, err := GetportLabel(intfID, portType) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 330 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 331 | 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] | 332 | } |
Chaitrashree G S | ded0a83 | 2020-01-09 20:21:48 -0500 | [diff] [blame] | 333 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 334 | // Check if port exists |
| 335 | port, err := dh.getPortFromCore(ctx, &ic.PortFilter{ |
| 336 | DeviceId: dh.device.Id, |
| 337 | Port: portNum, |
| 338 | }) |
| 339 | if err == nil && port.Type == portType { |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 340 | logger.Debug(ctx, "port-already-exists-updating-oper-status-of-port") |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 341 | err = dh.updatePortStateInCore(ctx, &ic.PortState{ |
| 342 | DeviceId: dh.device.Id, |
| 343 | PortType: portType, |
| 344 | PortNo: portNum, |
| 345 | OperStatus: operStatus}) |
| 346 | if err != nil { |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 347 | return olterrors.NewErrAdapter("failed-to-update-port-state", log.Fields{ |
| 348 | "device-id": dh.device.Id, |
| 349 | "port-type": portType, |
| 350 | "port-number": portNum, |
| 351 | "oper-status": operStatus}, err).Log() |
Chaitrashree G S | ded0a83 | 2020-01-09 20:21:48 -0500 | [diff] [blame] | 352 | } |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 353 | return nil |
Chaitrashree G S | ded0a83 | 2020-01-09 20:21:48 -0500 | [diff] [blame] | 354 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 355 | |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 356 | // Now create Port |
Girish Gowdra | 631ef3d | 2020-06-15 10:45:52 -0700 | [diff] [blame] | 357 | capacity := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 358 | port = &voltha.Port{ |
| 359 | DeviceId: dh.device.Id, |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 360 | PortNo: portNum, |
| 361 | Label: label, |
| 362 | Type: portType, |
| 363 | OperStatus: operStatus, |
Girish Gowdra | 631ef3d | 2020-06-15 10:45:52 -0700 | [diff] [blame] | 364 | OfpPort: &of.OfpPort{ |
| 365 | HwAddr: macAddressToUint32Array(dh.device.MacAddress), |
| 366 | Config: 0, |
| 367 | State: uint32(of.OfpPortState_OFPPS_LIVE), |
| 368 | Curr: capacity, |
| 369 | Advertised: capacity, |
| 370 | Peer: capacity, |
| 371 | CurrSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD), |
| 372 | MaxSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD), |
| 373 | }, |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 374 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 375 | logger.Debugw(ctx, "sending-port-update-to-core", log.Fields{"port": port}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 376 | // 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^] | 377 | err = dh.createPortInCore(ctx, port) |
| 378 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 379 | return olterrors.NewErrAdapter("error-creating-port", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 380 | "device-id": dh.device.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 381 | "port-type": portType}, err) |
Girish Gowdru | 1110ef2 | 2019-06-24 11:17:59 -0400 | [diff] [blame] | 382 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 383 | go dh.updateLocalDevice(ctx) |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 384 | return nil |
| 385 | } |
| 386 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 387 | func (dh *DeviceHandler) updateLocalDevice(ctx context.Context) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 388 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 389 | if err != nil || device == nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 390 | logger.Errorf(ctx, "device-not-found", log.Fields{"device-id": dh.device.Id}, err) |
| 391 | return |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 392 | } |
Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 393 | dh.lockDevice.Lock() |
| 394 | defer dh.lockDevice.Unlock() |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 395 | dh.device = device |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 396 | } |
| 397 | |
David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 398 | // nolint: gocyclo |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 399 | // readIndications to read the indications from the OLT device |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 400 | func (dh *DeviceHandler) readIndications(ctx context.Context) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 401 | 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] | 402 | defer func() { |
| 403 | dh.lockDevice.Lock() |
| 404 | dh.isReadIndicationRoutineActive = false |
| 405 | dh.lockDevice.Unlock() |
| 406 | }() |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 407 | indications, err := dh.startOpenOltIndicationStream(ctx) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 408 | if err != nil { |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 409 | return err |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 410 | } |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 411 | |
David Bainbridge | f5879ca | 2019-12-13 21:17:54 +0000 | [diff] [blame] | 412 | // Create an exponential backoff around re-enabling indications. The |
| 413 | // maximum elapsed time for the back off is set to 0 so that we will |
| 414 | // continue to retry. The max interval defaults to 1m, but is set |
| 415 | // here for code clarity |
| 416 | indicationBackoff := backoff.NewExponentialBackOff() |
| 417 | indicationBackoff.MaxElapsedTime = 0 |
| 418 | indicationBackoff.MaxInterval = 1 * time.Minute |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 419 | |
Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 420 | dh.lockDevice.Lock() |
| 421 | dh.isReadIndicationRoutineActive = true |
| 422 | dh.lockDevice.Unlock() |
| 423 | |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 424 | Loop: |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 425 | for { |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 426 | select { |
| 427 | case <-dh.stopIndications: |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 428 | 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] | 429 | break Loop |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 430 | default: |
| 431 | indication, err := indications.Recv() |
| 432 | if err == io.EOF { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 433 | logger.Infow(ctx, "eof-for-indications", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 434 | log.Fields{"err": err, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 435 | "device-id": dh.device.Id}) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 436 | // Use an exponential back off to prevent getting into a tight loop |
| 437 | duration := indicationBackoff.NextBackOff() |
| 438 | if duration == backoff.Stop { |
| 439 | // If we reach a maximum then warn and reset the backoff |
| 440 | // timer and keep attempting. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 441 | logger.Warnw(ctx, "maximum-indication-backoff-reached--resetting-backoff-timer", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 442 | log.Fields{"max-indication-backoff": indicationBackoff.MaxElapsedTime, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 443 | "device-id": dh.device.Id}) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 444 | indicationBackoff.Reset() |
| 445 | } |
David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 446 | |
| 447 | // On failure process a backoff timer while watching for stopIndications |
| 448 | // events |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 449 | backoffTimer := time.NewTimer(indicationBackoff.NextBackOff()) |
David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 450 | select { |
| 451 | case <-dh.stopIndications: |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 452 | 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] | 453 | if !backoffTimer.Stop() { |
| 454 | <-backoffTimer.C |
David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 455 | } |
| 456 | break Loop |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 457 | case <-backoffTimer.C: |
| 458 | // backoffTimer expired continue |
David Bainbridge | 95a3fcf | 2020-06-09 10:49:31 -0700 | [diff] [blame] | 459 | } |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 460 | if indications, err = dh.startOpenOltIndicationStream(ctx); err != nil { |
| 461 | return err |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 462 | } |
| 463 | continue |
David Bainbridge | f5879ca | 2019-12-13 21:17:54 +0000 | [diff] [blame] | 464 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 465 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 466 | logger.Errorw(ctx, "read-indication-error", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 467 | log.Fields{"err": err, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 468 | "device-id": dh.device.Id}) |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 469 | // Close the stream, and re-initialize it |
| 470 | if err = indications.CloseSend(); err != nil { |
| 471 | // Ok to ignore here, because we landed here due to a problem on the stream |
| 472 | // In all probability, the closeSend call may fail |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 473 | logger.Debugw(ctx, "error-closing-send stream--error-ignored", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 474 | log.Fields{"err": err, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 475 | "device-id": dh.device.Id}) |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 476 | } |
Matteo Scandolo | f16389e | 2021-05-18 00:47:08 +0000 | [diff] [blame] | 477 | if indications, err = dh.startOpenOltIndicationStream(ctx); err != nil { |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 478 | return err |
| 479 | } |
| 480 | // once we re-initialized the indication stream, continue to read indications |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 481 | continue |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 482 | } |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 483 | // Reset backoff if we have a successful receive |
| 484 | indicationBackoff.Reset() |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 485 | // When OLT is admin down, ignore all indications. |
Girish Gowdra | 852ad91 | 2021-05-04 00:05:50 -0700 | [diff] [blame] | 486 | if dh.device.AdminState == voltha.AdminState_DISABLED && !isIndicationAllowedDuringOltAdminDown(indication) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 487 | logger.Debugw(ctx, "olt-is-admin-down, ignore indication", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 488 | log.Fields{"indication": indication, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 489 | "device-id": dh.device.Id}) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 490 | continue |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 491 | } |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 492 | dh.handleIndication(ctx, indication) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 493 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 494 | } |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 495 | // Close the send stream |
| 496 | _ = indications.CloseSend() // Ok to ignore error, as we stopping the readIndication anyway |
Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 497 | |
Girish Gowdra | 3f97491 | 2020-03-23 20:35:18 -0700 | [diff] [blame] | 498 | return nil |
| 499 | } |
| 500 | |
| 501 | func (dh *DeviceHandler) startOpenOltIndicationStream(ctx context.Context) (oop.Openolt_EnableIndicationClient, error) { |
Girish Gowdra | 852ad91 | 2021-05-04 00:05:50 -0700 | [diff] [blame] | 502 | 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] | 503 | indications, err := dh.Client.EnableIndication(ctx, new(oop.Empty)) |
| 504 | if err != nil { |
| 505 | return nil, olterrors.NewErrCommunication("indication-read-failure", log.Fields{"device-id": dh.device.Id}, err).Log() |
| 506 | } |
| 507 | if indications == nil { |
| 508 | return nil, olterrors.NewErrInvalidValue(log.Fields{"indications": nil, "device-id": dh.device.Id}, nil).Log() |
| 509 | } |
Girish Gowdra | 852ad91 | 2021-05-04 00:05:50 -0700 | [diff] [blame] | 510 | 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] | 511 | return indications, nil |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | // isIndicationAllowedDuringOltAdminDown returns true if the indication is allowed during OLT Admin down, else false |
| 515 | func isIndicationAllowedDuringOltAdminDown(indication *oop.Indication) bool { |
| 516 | switch indication.Data.(type) { |
| 517 | case *oop.Indication_OltInd, *oop.Indication_IntfInd, *oop.Indication_IntfOperInd: |
| 518 | return true |
| 519 | |
| 520 | default: |
| 521 | return false |
| 522 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 523 | } |
| 524 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 525 | func (dh *DeviceHandler) handleOltIndication(ctx context.Context, oltIndication *oop.OltIndication) error { |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 526 | raisedTs := time.Now().Unix() |
Gamze Abaka | a1a5052 | 2019-10-03 19:28:27 +0000 | [diff] [blame] | 527 | if oltIndication.OperState == "up" && dh.transitionMap.currentDeviceState != deviceStateUp { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 528 | dh.transitionMap.Handle(ctx, DeviceUpInd) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 529 | } else if oltIndication.OperState == "down" { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 530 | dh.transitionMap.Handle(ctx, DeviceDownInd) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 531 | } |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 532 | // Send or clear Alarm |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 533 | 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] | 534 | return olterrors.NewErrAdapter("failed-indication", log.Fields{ |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 535 | "device-id": dh.device.Id, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 536 | "indication": oltIndication, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 537 | "timestamp": raisedTs}, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 538 | } |
| 539 | return nil |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 540 | } |
| 541 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 542 | // nolint: gocyclo |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 543 | func (dh *DeviceHandler) handleIndication(ctx context.Context, indication *oop.Indication) { |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 544 | raisedTs := time.Now().Unix() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 545 | switch indication.Data.(type) { |
| 546 | case *oop.Indication_OltInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 547 | span, ctx := log.CreateChildSpan(ctx, "olt-indication", log.Fields{"device-id": dh.device.Id}) |
| 548 | defer span.Finish() |
Girish Gowdra | 852ad91 | 2021-05-04 00:05:50 -0700 | [diff] [blame] | 549 | 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] | 550 | if err := dh.handleOltIndication(ctx, indication.GetOltInd()); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 551 | _ = 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] | 552 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 553 | case *oop.Indication_IntfInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 554 | span, ctx := log.CreateChildSpan(ctx, "interface-indication", log.Fields{"device-id": dh.device.Id}) |
| 555 | defer span.Finish() |
| 556 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 557 | intfInd := indication.GetIntfInd() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 558 | go func() { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 559 | if err := dh.addPort(ctx, intfInd.GetIntfId(), voltha.Port_PON_OLT, intfInd.GetOperState()); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 560 | _ = 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] | 561 | } |
| 562 | }() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 563 | 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] | 564 | case *oop.Indication_IntfOperInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 565 | span, ctx := log.CreateChildSpan(ctx, "interface-oper-indication", log.Fields{"device-id": dh.device.Id}) |
| 566 | defer span.Finish() |
| 567 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 568 | intfOperInd := indication.GetIntfOperInd() |
| 569 | if intfOperInd.GetType() == "nni" { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 570 | go func() { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 571 | if err := dh.addPort(ctx, intfOperInd.GetIntfId(), voltha.Port_ETHERNET_NNI, intfOperInd.GetOperState()); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 572 | _ = 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] | 573 | } |
| 574 | }() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 575 | } else if intfOperInd.GetType() == "pon" { |
| 576 | // TODO: Check what needs to be handled here for When PON PORT down, ONU will be down |
| 577 | // Handle pon port update |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 578 | go func() { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 579 | if err := dh.addPort(ctx, intfOperInd.GetIntfId(), voltha.Port_PON_OLT, intfOperInd.GetOperState()); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 580 | _ = 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] | 581 | } |
| 582 | }() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 583 | go dh.eventMgr.oltIntfOperIndication(ctx, indication.GetIntfOperInd(), dh.device.Id, raisedTs) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 584 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 585 | logger.Infow(ctx, "received-interface-oper-indication", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 586 | log.Fields{"interfaceOperInd": intfOperInd, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 587 | "device-id": dh.device.Id}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 588 | case *oop.Indication_OnuDiscInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 589 | span, ctx := log.CreateChildSpan(ctx, "onu-discovery-indication", log.Fields{"device-id": dh.device.Id}) |
| 590 | defer span.Finish() |
| 591 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 592 | onuDiscInd := indication.GetOnuDiscInd() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 593 | 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] | 594 | //put message to channel and return immediately |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 595 | dh.putOnuIndicationToChannel(ctx, indication, onuDiscInd.GetIntfId()) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 596 | case *oop.Indication_OnuInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 597 | span, ctx := log.CreateChildSpan(ctx, "onu-indication", log.Fields{"device-id": dh.device.Id}) |
| 598 | defer span.Finish() |
| 599 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 600 | onuInd := indication.GetOnuInd() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 601 | 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] | 602 | //put message to channel and return immediately |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 603 | dh.putOnuIndicationToChannel(ctx, indication, onuInd.GetIntfId()) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 604 | case *oop.Indication_OmciInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 605 | span, ctx := log.CreateChildSpan(ctx, "omci-indication", log.Fields{"device-id": dh.device.Id}) |
| 606 | defer span.Finish() |
| 607 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 608 | omciInd := indication.GetOmciInd() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 609 | 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] | 610 | go func() { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 611 | if err := dh.omciIndication(ctx, omciInd); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 612 | _ = 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] | 613 | } |
| 614 | }() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 615 | case *oop.Indication_PktInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 616 | span, ctx := log.CreateChildSpan(ctx, "packet-indication", log.Fields{"device-id": dh.device.Id}) |
| 617 | defer span.Finish() |
| 618 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 619 | pktInd := indication.GetPktInd() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 620 | logger.Debugw(ctx, "received-packet-indication", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 621 | "intf-type": pktInd.IntfId, |
| 622 | "intf-id": pktInd.IntfId, |
| 623 | "gem-port-id": pktInd.GemportId, |
| 624 | "port-no": pktInd.PortNo, |
| 625 | "device-id": dh.device.Id, |
| 626 | }) |
| 627 | |
| 628 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 629 | logger.Debugw(ctx, "received-packet-indication-packet", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 630 | "intf-type": pktInd.IntfId, |
| 631 | "intf-id": pktInd.IntfId, |
| 632 | "gem-port-id": pktInd.GemportId, |
| 633 | "port-no": pktInd.PortNo, |
| 634 | "packet": hex.EncodeToString(pktInd.Pkt), |
| 635 | "device-id": dh.device.Id, |
| 636 | }) |
| 637 | } |
| 638 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 639 | go func() { |
| 640 | if err := dh.handlePacketIndication(ctx, pktInd); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 641 | _ = 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] | 642 | } |
| 643 | }() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 644 | case *oop.Indication_PortStats: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 645 | span, ctx := log.CreateChildSpan(ctx, "port-statistics-indication", log.Fields{"device-id": dh.device.Id}) |
| 646 | defer span.Finish() |
| 647 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 648 | portStats := indication.GetPortStats() |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 649 | go dh.portStats.PortStatisticsIndication(ctx, portStats, dh.totalPonPorts) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 650 | case *oop.Indication_FlowStats: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 651 | span, ctx := log.CreateChildSpan(ctx, "flow-stats-indication", log.Fields{"device-id": dh.device.Id}) |
| 652 | defer span.Finish() |
| 653 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 654 | flowStats := indication.GetFlowStats() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 655 | 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] | 656 | case *oop.Indication_AlarmInd: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 657 | span, ctx := log.CreateChildSpan(ctx, "alarm-indication", log.Fields{"device-id": dh.device.Id}) |
| 658 | defer span.Finish() |
| 659 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 660 | alarmInd := indication.GetAlarmInd() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 661 | logger.Infow(ctx, "received-alarm-indication", log.Fields{"AlarmInd": alarmInd, "device-id": dh.device.Id}) |
| 662 | go dh.eventMgr.ProcessEvents(ctx, alarmInd, dh.device.Id, raisedTs) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 663 | } |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | // doStateUp handle the olt up indication and update to voltha core |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 667 | func (dh *DeviceHandler) doStateUp(ctx context.Context) error { |
Thomas Lee S | 85f3731 | 2020-04-03 17:06:12 +0530 | [diff] [blame] | 668 | //starting the stat collector |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 669 | go startCollector(ctx, dh) |
Thomas Lee S | 85f3731 | 2020-04-03 17:06:12 +0530 | [diff] [blame] | 670 | |
Girish Gowdra | 618fa57 | 2021-09-01 17:19:29 -0700 | [diff] [blame] | 671 | // instantiate the mcast handler routines. |
| 672 | for i := range dh.incomingMcastFlowOrGroup { |
| 673 | // We land inside the below "if" code path, after the OLT comes back from a reboot, otherwise the routines |
| 674 | // are already active when the DeviceHandler module is first instantiated (as part of Adopt_device RPC invocation). |
| 675 | if !dh.mcastHandlerRoutineActive[i] { |
| 676 | // Spin up a go routine to handling incoming mcast flow/group (add/modify/remove). |
| 677 | // There will be MaxNumOfGroupHandlerChannels number of mcastFlowOrGroupChannelHandlerRoutine go routines. |
| 678 | // These routines will be blocked on the dh.incomingMcastFlowOrGroup[mcast-group-id modulo MaxNumOfGroupHandlerChannels] channel |
| 679 | // for incoming mcast flow/group to be processed serially. |
| 680 | dh.mcastHandlerRoutineActive[i] = true |
| 681 | go dh.mcastFlowOrGroupChannelHandlerRoutine(i, dh.incomingMcastFlowOrGroup[i], dh.stopMcastHandlerRoutine[i]) |
| 682 | } |
| 683 | } |
| 684 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 685 | // Synchronous call to update device state - this method is run in its own go routine |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 686 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
| 687 | DeviceId: dh.device.Id, |
| 688 | OperStatus: voltha.OperStatus_ACTIVE, |
| 689 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 690 | }); err != nil { |
| 691 | 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] | 692 | } |
Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 693 | |
| 694 | //Clear olt communication failure event |
| 695 | dh.device.ConnectStatus = voltha.ConnectStatus_REACHABLE |
| 696 | dh.device.OperStatus = voltha.OperStatus_ACTIVE |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 697 | raisedTs := time.Now().Unix() |
Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 698 | go dh.eventMgr.oltCommunicationEvent(ctx, dh.device, raisedTs) |
| 699 | |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 700 | //check adapter and agent reconcile status |
| 701 | //reboot olt if needed (olt disconnection case) |
| 702 | if dh.adapterPreviouslyConnected != dh.agentPreviouslyConnected { |
| 703 | logger.Warnw(ctx, "different-reconcile-status-between-adapter-and-agent-rebooting-device", |
| 704 | log.Fields{ |
| 705 | "device-id": dh.device.Id, |
| 706 | "adapter-status": dh.adapterPreviouslyConnected, |
| 707 | "agent-status": dh.agentPreviouslyConnected, |
| 708 | }) |
| 709 | _ = dh.RebootDevice(ctx, dh.device) |
| 710 | } |
| 711 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 712 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | // doStateDown handle the olt down indication |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 716 | func (dh *DeviceHandler) doStateDown(ctx context.Context) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 717 | 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] | 718 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 719 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 720 | if err != nil || device == nil { |
| 721 | /*TODO: needs to handle error scenarios */ |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 722 | return olterrors.NewErrNotFound("device", log.Fields{"device-id": dh.device.Id}, err) |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | cloned := proto.Clone(device).(*voltha.Device) |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 726 | |
| 727 | //Update the device oper state and connection status |
| 728 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 729 | dh.lockDevice.Lock() |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 730 | dh.device = cloned |
Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 731 | dh.lockDevice.Unlock() |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 732 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 733 | if err = dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
| 734 | DeviceId: cloned.Id, |
| 735 | OperStatus: cloned.OperStatus, |
| 736 | ConnStatus: cloned.ConnectStatus, |
| 737 | }); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 738 | 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] | 739 | } |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 740 | |
| 741 | //get the child device for the parent device |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 742 | onuDevices, err := dh.getChildDevicesFromCore(ctx, dh.device.Id) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 743 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 744 | 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] | 745 | } |
| 746 | for _, onuDevice := range onuDevices.Items { |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 747 | // Update onu state as down in onu adapter |
| 748 | onuInd := oop.OnuIndication{} |
| 749 | onuInd.OperState = "down" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 750 | |
| 751 | ogClient, err := dh.getChildAdapterServiceClient(onuDevice.AdapterEndpoint) |
| 752 | if err != nil { |
| 753 | return err |
| 754 | } |
| 755 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 756 | _, err = ogClient.OnuIndication(subCtx, &ic.OnuIndicationMessage{ |
| 757 | DeviceId: onuDevice.Id, |
| 758 | OnuIndication: &onuInd, |
| 759 | }) |
| 760 | cancel() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 761 | if err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 762 | _ = olterrors.NewErrCommunication("inter-adapter-send-failed", log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 763 | "source": dh.openOLT.config.AdapterEndpoint, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 764 | "onu-indicator": onuInd, |
| 765 | "device-type": onuDevice.Type, |
| 766 | "device-id": onuDevice.Id}, err).LogAt(log.ErrorLevel) |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 767 | //Do not return here and continue to process other ONUs |
Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 768 | } else { |
| 769 | 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] | 770 | } |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 771 | } |
Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 772 | dh.lockDevice.Lock() |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 773 | /* Discovered ONUs entries need to be cleared , since after OLT |
| 774 | is up, it starts sending discovery indications again*/ |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 775 | dh.discOnus = sync.Map{} |
Girish Gowdra | be811ff | 2021-01-26 17:12:12 -0800 | [diff] [blame] | 776 | dh.lockDevice.Unlock() |
| 777 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 778 | logger.Debugw(ctx, "do-state-down-end", log.Fields{"device-id": device.Id}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 779 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | // doStateInit dial the grpc before going to init state |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 783 | func (dh *DeviceHandler) doStateInit(ctx context.Context) error { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 784 | var err error |
Gamze Abaka | 49c40b3 | 2021-05-06 09:30:41 +0000 | [diff] [blame] | 785 | |
| 786 | // if the connection is already available, close the previous connection (olt reboot case) |
| 787 | if dh.clientCon != nil { |
| 788 | if err = dh.clientCon.Close(); err != nil { |
| 789 | logger.Errorw(ctx, "failed-to-close-previous-connection", log.Fields{"device-id": dh.device.Id}) |
| 790 | } else { |
| 791 | logger.Debugw(ctx, "previous-grpc-channel-closed-successfully", log.Fields{"device-id": dh.device.Id}) |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | // 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] | 796 | dh.clientCon, err = grpc.Dial(dh.device.GetHostAndPort(), |
| 797 | grpc.WithInsecure(), |
| 798 | grpc.WithBlock(), |
| 799 | grpc.WithStreamInterceptor(grpc_middleware.ChainStreamClient( |
Girish Kumar | 935f7af | 2020-08-18 11:59:42 +0000 | [diff] [blame] | 800 | grpc_opentracing.StreamClientInterceptor(grpc_opentracing.WithTracer(log.ActiveTracerProxy{})), |
Girish Kumar | 93e9174 | 2020-07-27 16:43:19 +0000 | [diff] [blame] | 801 | )), |
| 802 | grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient( |
Girish Kumar | 935f7af | 2020-08-18 11:59:42 +0000 | [diff] [blame] | 803 | grpc_opentracing.UnaryClientInterceptor(grpc_opentracing.WithTracer(log.ActiveTracerProxy{})), |
Girish Kumar | 93e9174 | 2020-07-27 16:43:19 +0000 | [diff] [blame] | 804 | ))) |
| 805 | |
| 806 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 807 | return olterrors.NewErrCommunication("dial-failure", log.Fields{ |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 808 | "device-id": dh.device.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 809 | "host-and-port": dh.device.GetHostAndPort()}, err) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 810 | } |
| 811 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | // postInit create olt client instance to invoke RPC on the olt device |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 815 | func (dh *DeviceHandler) postInit(ctx context.Context) error { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 816 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 817 | dh.transitionMap.Handle(ctx, GrpcConnected) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 818 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | // doStateConnected get the device info and update to voltha core |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 822 | func (dh *DeviceHandler) doStateConnected(ctx context.Context) error { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 823 | var err error |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 824 | 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] | 825 | |
| 826 | // Case where OLT is disabled and then rebooted. |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 827 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 828 | if err != nil || device == nil { |
| 829 | /*TODO: needs to handle error scenarios */ |
| 830 | return olterrors.NewErrAdapter("device-fetch-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
| 831 | } |
| 832 | if device.AdminState == voltha.AdminState_DISABLED { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 833 | logger.Debugln(ctx, "do-state-connected--device-admin-state-down") |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 834 | |
| 835 | cloned := proto.Clone(device).(*voltha.Device) |
| 836 | cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE |
| 837 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 838 | dh.device = cloned |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 839 | |
| 840 | if err = dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
| 841 | DeviceId: cloned.Id, |
| 842 | OperStatus: cloned.OperStatus, |
| 843 | ConnStatus: cloned.ConnectStatus, |
| 844 | }); err != nil { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 845 | 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] | 846 | } |
| 847 | |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 848 | // 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] | 849 | _, err = dh.Client.DisableOlt(ctx, new(oop.Empty)) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 850 | if err != nil { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 851 | 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] | 852 | } |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 853 | // We should still go ahead an initialize various device handler modules so that when OLT is re-enabled, we have |
| 854 | // all the modules initialized and ready to handle incoming ONUs. |
| 855 | |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 856 | err = dh.initializeDeviceHandlerModules(ctx) |
| 857 | if err != nil { |
| 858 | 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] | 859 | } |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 860 | |
| 861 | // Start reading indications |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 862 | go func() { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 863 | if err = dh.readIndications(ctx); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 864 | _ = olterrors.NewErrAdapter("indication-read-failure", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 865 | } |
| 866 | }() |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 867 | |
| 868 | go startHeartbeatCheck(ctx, dh) |
| 869 | |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 870 | return nil |
| 871 | } |
| 872 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 873 | ports, err := dh.listDevicePortsFromCore(ctx, dh.device.Id) |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 874 | if err != nil { |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 875 | /*TODO: needs to handle error scenarios */ |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 876 | 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] | 877 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 878 | dh.populateActivePorts(ctx, ports.Items) |
| 879 | if err := dh.disableAdminDownPorts(ctx, ports.Items); err != nil { |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 880 | return olterrors.NewErrAdapter("port-status-update-failed", log.Fields{"ports": ports}, err) |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 881 | } |
| 882 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 883 | if err := dh.initializeDeviceHandlerModules(ctx); err != nil { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 884 | 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] | 885 | } |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 886 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 887 | // Start reading indications |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 888 | go func() { |
| 889 | if err := dh.readIndications(ctx); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 890 | _ = olterrors.NewErrAdapter("read-indications-failure", log.Fields{"device-id": dh.device.Id}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 891 | } |
| 892 | }() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 893 | go dh.updateLocalDevice(ctx) |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 894 | |
| 895 | if device.PmConfigs != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 896 | dh.UpdatePmConfig(ctx, device.PmConfigs) |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 897 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 898 | |
| 899 | go startHeartbeatCheck(ctx, dh) |
| 900 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 901 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 902 | } |
| 903 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 904 | func (dh *DeviceHandler) initializeDeviceHandlerModules(ctx context.Context) error { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 905 | var err error |
| 906 | dh.deviceInfo, err = dh.populateDeviceInfo(ctx) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 907 | |
| 908 | if err != nil { |
| 909 | return olterrors.NewErrAdapter("populate-device-info-failed", log.Fields{"device-id": dh.device.Id}, err) |
| 910 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 911 | dh.totalPonPorts = dh.deviceInfo.GetPonPorts() |
| 912 | dh.agentPreviouslyConnected = dh.deviceInfo.PreviouslyConnected |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 913 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 914 | dh.resourceMgr = make([]*rsrcMgr.OpenOltResourceMgr, dh.totalPonPorts) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 915 | dh.flowMgr = make([]*OpenOltFlowMgr, dh.totalPonPorts) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 916 | var i uint32 |
| 917 | for i = 0; i < dh.totalPonPorts; i++ { |
| 918 | // Instantiate resource manager |
| 919 | 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] | 920 | return olterrors.ErrResourceManagerInstantiating |
| 921 | } |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 922 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 923 | // GroupManager instance is per OLT. But it needs a reference to any instance of resourceMgr to interface with |
| 924 | // the KV store to manage mcast group data. Provide the first instance (0th index) |
| 925 | if dh.groupMgr = NewGroupManager(ctx, dh, dh.resourceMgr[0]); dh.groupMgr == nil { |
| 926 | return olterrors.ErrGroupManagerInstantiating |
| 927 | } |
| 928 | for i = 0; i < dh.totalPonPorts; i++ { |
| 929 | // Instantiate flow manager |
| 930 | if dh.flowMgr[i] = NewFlowManager(ctx, dh, dh.resourceMgr[i], dh.groupMgr, i); dh.flowMgr[i] == nil { |
| 931 | return olterrors.ErrFlowManagerInstantiating |
| 932 | } |
Girish Gowdra | 76a1b09 | 2021-07-28 10:07:04 -0700 | [diff] [blame] | 933 | dh.resourceMgr[i].TechprofileRef = dh.flowMgr[i].techprofile |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 934 | } |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 935 | /* TODO: Instantiate Alarm , stats , BW managers */ |
| 936 | /* Instantiating Event Manager to handle Alarms and KPIs */ |
| 937 | dh.eventMgr = NewEventMgr(dh.EventProxy, dh) |
| 938 | |
| 939 | // Stats config for new device |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 940 | dh.portStats = NewOpenOltStatsMgr(ctx, dh) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 941 | |
| 942 | return nil |
| 943 | |
| 944 | } |
| 945 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 946 | func (dh *DeviceHandler) populateDeviceInfo(ctx context.Context) (*oop.DeviceInfo, error) { |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 947 | var err error |
| 948 | var deviceInfo *oop.DeviceInfo |
| 949 | |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 950 | 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] | 951 | |
| 952 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 953 | return nil, olterrors.NewErrPersistence("get", "device", 0, nil, err) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 954 | } |
| 955 | if deviceInfo == nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 956 | return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 957 | } |
| 958 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 959 | 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] | 960 | dh.device.Root = true |
| 961 | dh.device.Vendor = deviceInfo.Vendor |
| 962 | dh.device.Model = deviceInfo.Model |
| 963 | dh.device.SerialNumber = deviceInfo.DeviceSerialNumber |
| 964 | dh.device.HardwareVersion = deviceInfo.HardwareVersion |
| 965 | dh.device.FirmwareVersion = deviceInfo.FirmwareVersion |
| 966 | |
| 967 | if deviceInfo.DeviceId == "" { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 968 | 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] | 969 | host := strings.Split(dh.device.GetHostAndPort(), ":")[0] |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 970 | genmac, err := generateMacFromHost(ctx, host) |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 971 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 972 | 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] | 973 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 974 | 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] | 975 | dh.device.MacAddress = genmac |
| 976 | } else { |
| 977 | dh.device.MacAddress = deviceInfo.DeviceId |
| 978 | } |
| 979 | |
| 980 | // 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^] | 981 | if err = dh.updateDeviceInCore(ctx, dh.device); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 982 | 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] | 983 | } |
| 984 | |
| 985 | return deviceInfo, nil |
| 986 | } |
| 987 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 988 | func startCollector(ctx context.Context, dh *DeviceHandler) { |
Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 989 | logger.Debugw(ctx, "starting-collector", log.Fields{"device-id": dh.device.Id}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 990 | for { |
| 991 | select { |
| 992 | case <-dh.stopCollector: |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 993 | 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] | 994 | return |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 995 | case <-time.After(time.Duration(dh.metrics.ToPmConfigs().DefaultFreq) * time.Second): |
Girish Gowdra | 34815db | 2020-05-11 17:18:04 -0700 | [diff] [blame] | 996 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 997 | ports, err := dh.listDevicePortsFromCore(ctx, dh.device.Id) |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 998 | if err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 999 | 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] | 1000 | continue |
| 1001 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1002 | for _, port := range ports.Items { |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1003 | // NNI Stats |
| 1004 | if port.Type == voltha.Port_ETHERNET_NNI { |
| 1005 | intfID := PortNoToIntfID(port.PortNo, voltha.Port_ETHERNET_NNI) |
| 1006 | cmnni := dh.portStats.collectNNIMetrics(intfID) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1007 | logger.Debugw(ctx, "collect-nni-metrics", log.Fields{"metrics": cmnni}) |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 1008 | 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] | 1009 | logger.Debugw(ctx, "publish-nni-metrics", log.Fields{"nni-port": port.Label}) |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1010 | } |
| 1011 | // PON Stats |
| 1012 | if port.Type == voltha.Port_PON_OLT { |
| 1013 | intfID := PortNoToIntfID(port.PortNo, voltha.Port_PON_OLT) |
| 1014 | if val, ok := dh.activePorts.Load(intfID); ok && val == true { |
| 1015 | cmpon := dh.portStats.collectPONMetrics(intfID) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1016 | logger.Debugw(ctx, "collect-pon-metrics", log.Fields{"metrics": cmpon}) |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 1017 | 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] | 1018 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1019 | logger.Debugw(ctx, "publish-pon-metrics", log.Fields{"pon-port": port.Label}) |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 1020 | |
Girish Gowdra | bcf98af | 2021-07-01 08:24:42 -0700 | [diff] [blame] | 1021 | onuGemInfoLst := dh.flowMgr[intfID].getOnuGemInfoList(ctx) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1022 | if len(onuGemInfoLst) > 0 { |
| 1023 | go dh.portStats.collectOnuAndGemStats(ctx, onuGemInfoLst) |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 1024 | } |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 1025 | } |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1031 | //AdoptDevice adopts the OLT device |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1032 | func (dh *DeviceHandler) AdoptDevice(ctx context.Context, device *voltha.Device) { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1033 | dh.transitionMap = NewTransitionMap(dh) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1034 | 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] | 1035 | dh.transitionMap.Handle(ctx, DeviceInit) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1036 | |
| 1037 | // Now, set the initial PM configuration for that device |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1038 | cgClient, err := dh.coreClient.GetCoreServiceClient() |
| 1039 | if err != nil { |
| 1040 | logger.Errorw(ctx, "no-core-connection", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 1041 | return |
| 1042 | } |
| 1043 | |
| 1044 | // Now, set the initial PM configuration for that device |
| 1045 | if _, err := cgClient.DevicePMConfigUpdate(ctx, dh.metrics.ToPmConfigs()); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1046 | _ = 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] | 1047 | } |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1048 | } |
| 1049 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1050 | //GetOfpDeviceInfo Gets the Ofp information of the given device |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1051 | func (dh *DeviceHandler) GetOfpDeviceInfo(device *voltha.Device) (*ic.SwitchCapability, error) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1052 | return &ic.SwitchCapability{ |
| 1053 | Desc: &of.OfpDesc{ |
Devmalya Paul | 70dd497 | 2019-06-10 15:19:17 +0530 | [diff] [blame] | 1054 | MfrDesc: "VOLTHA Project", |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1055 | HwDesc: "open_pon", |
| 1056 | SwDesc: "open_pon", |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1057 | SerialNum: device.SerialNumber, |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1058 | }, |
| 1059 | SwitchFeatures: &of.OfpSwitchFeatures{ |
| 1060 | NBuffers: 256, |
| 1061 | NTables: 2, |
| 1062 | Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS | |
| 1063 | of.OfpCapabilities_OFPC_TABLE_STATS | |
| 1064 | of.OfpCapabilities_OFPC_PORT_STATS | |
| 1065 | of.OfpCapabilities_OFPC_GROUP_STATS), |
| 1066 | }, |
| 1067 | }, nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1068 | } |
| 1069 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1070 | // GetTechProfileDownloadMessage fetches the TechProfileDownloadMessage for the caller. |
| 1071 | func (dh *DeviceHandler) GetTechProfileDownloadMessage(ctx context.Context, request *ic.TechProfileInstanceRequestMessage) (*ic.TechProfileDownloadMessage, error) { |
| 1072 | ifID, err := IntfIDFromPonPortNum(ctx, request.ParentPonPort) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1073 | if err != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1074 | return nil, err |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1075 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1076 | return dh.flowMgr[ifID].getTechProfileDownloadMessage(ctx, request.TpInstancePath, request.OnuId, request.DeviceId) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1079 | func (dh *DeviceHandler) omciIndication(ctx context.Context, omciInd *oop.OmciIndication) error { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1080 | 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] | 1081 | var deviceType string |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1082 | var deviceID string |
| 1083 | var proxyDeviceID string |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1084 | var childAdapterEndpoint string |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1085 | |
Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1086 | transid := extractOmciTransactionID(omciInd.Pkt) |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1087 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1088 | 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] | 1089 | "omci-transaction-id": transid, "omci-msg": hex.EncodeToString(omciInd.Pkt)}) |
| 1090 | } |
Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1091 | |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1092 | onuKey := dh.formOnuKey(omciInd.IntfId, omciInd.OnuId) |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1093 | |
| 1094 | if onuInCache, ok := dh.onus.Load(onuKey); !ok { |
| 1095 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1096 | 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}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1097 | ponPort := IntfIDToPortNo(omciInd.GetIntfId(), voltha.Port_PON_OLT) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1098 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1099 | onuDevice, err := dh.getChildDeviceFromCore(ctx, &ic.ChildDeviceFilter{ |
| 1100 | ParentId: dh.device.Id, |
| 1101 | OnuId: omciInd.OnuId, |
| 1102 | ParentPortNo: ponPort, |
| 1103 | }) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1104 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1105 | return olterrors.NewErrNotFound("onu", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1106 | "intf-id": omciInd.IntfId, |
| 1107 | "onu-id": omciInd.OnuId}, err) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1108 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1109 | deviceType = onuDevice.Type |
| 1110 | deviceID = onuDevice.Id |
| 1111 | proxyDeviceID = onuDevice.ProxyAddress.DeviceId |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1112 | childAdapterEndpoint = onuDevice.AdapterEndpoint |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1113 | //if not exist in cache, then add to cache. |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1114 | 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] | 1115 | } else { |
| 1116 | //found in cache |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1117 | 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] | 1118 | deviceType = onuInCache.(*OnuDevice).deviceType |
| 1119 | deviceID = onuInCache.(*OnuDevice).deviceID |
| 1120 | proxyDeviceID = onuInCache.(*OnuDevice).proxyDeviceID |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1121 | childAdapterEndpoint = onuInCache.(*OnuDevice).adapterEndpoint |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1122 | } |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1123 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1124 | if err := dh.sendOmciIndicationToChildAdapter(ctx, childAdapterEndpoint, &ic.OmciMessage{ |
| 1125 | ParentDeviceId: proxyDeviceID, |
| 1126 | ChildDeviceId: deviceID, |
| 1127 | Message: omciInd.Pkt, |
| 1128 | }); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1129 | return olterrors.NewErrCommunication("omci-request", log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1130 | "source": dh.openOLT.config.AdapterEndpoint, |
| 1131 | "device-type": deviceType, |
| 1132 | "destination": childAdapterEndpoint, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1133 | "onu-id": deviceID, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1134 | "proxy-device-id": proxyDeviceID}, err) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1135 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1136 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1137 | } |
| 1138 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1139 | // //ProcessInterAdapterMessage sends the proxied messages to the target device |
| 1140 | // // If the proxy address is not found in the unmarshalled message, it first fetches the onu device for which the message |
| 1141 | // // is meant, and then send the unmarshalled omci message to this onu |
| 1142 | // func (dh *DeviceHandler) ProcessInterAdapterMessage(ctx context.Context, msg *ic.InterAdapterMessage) error { |
| 1143 | // logger.Debugw(ctx, "process-inter-adapter-message", log.Fields{"msgID": msg.Header.Id}) |
| 1144 | // if msg.Header.Type == ic.InterAdapterMessageType_OMCI_REQUEST { |
| 1145 | // return dh.handleInterAdapterOmciMsg(ctx, msg) |
| 1146 | // } |
| 1147 | // return olterrors.NewErrInvalidValue(log.Fields{"inter-adapter-message-type": msg.Header.Type}, nil) |
| 1148 | // } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1149 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1150 | // ProxyOmciMessage sends the proxied OMCI message to the target device |
| 1151 | func (dh *DeviceHandler) ProxyOmciMessage(ctx context.Context, omciMsg *ic.OmciMessage) error { |
| 1152 | 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] | 1153 | |
| 1154 | if omciMsg.GetProxyAddress() == nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1155 | onuDevice, err := dh.getDeviceFromCore(ctx, omciMsg.ChildDeviceId) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1156 | if err != nil { |
| 1157 | return olterrors.NewErrNotFound("onu", log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1158 | "parent-device-id": dh.device.Id, |
| 1159 | "child-device-id": omciMsg.ChildDeviceId}, err) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1160 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1161 | logger.Debugw(ctx, "device-retrieved-from-core", log.Fields{"onu-device-proxy-address": onuDevice.ProxyAddress}) |
| 1162 | 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] | 1163 | return olterrors.NewErrCommunication("send-failed", log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1164 | "parent-device-id": dh.device.Id, |
| 1165 | "child-device-id": omciMsg.ChildDeviceId}, err) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1166 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1167 | } else { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1168 | logger.Debugw(ctx, "proxy-address-found-in-omci-message", log.Fields{"onu-device-proxy-address": omciMsg.ProxyAddress}) |
| 1169 | 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] | 1170 | return olterrors.NewErrCommunication("send-failed", log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1171 | "parent-device-id": dh.device.Id, |
| 1172 | "child-device-id": omciMsg.ChildDeviceId}, err) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1173 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1174 | } |
| 1175 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 1176 | } |
| 1177 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1178 | func (dh *DeviceHandler) sendProxiedMessage(ctx context.Context, onuDevice *voltha.Device, omciMsg *ic.OmciMessage) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1179 | var intfID uint32 |
| 1180 | var onuID uint32 |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1181 | var connectStatus common.ConnectStatus_Types |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1182 | if onuDevice != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1183 | intfID = onuDevice.ProxyAddress.GetChannelId() |
| 1184 | onuID = onuDevice.ProxyAddress.GetOnuId() |
| 1185 | connectStatus = onuDevice.ConnectStatus |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1186 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1187 | intfID = omciMsg.GetProxyAddress().GetChannelId() |
| 1188 | onuID = omciMsg.GetProxyAddress().GetOnuId() |
| 1189 | connectStatus = omciMsg.GetConnectStatus() |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1190 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1191 | if connectStatus != voltha.ConnectStatus_REACHABLE { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1192 | 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] | 1193 | |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1194 | return olterrors.NewErrCommunication("unreachable", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1195 | "intf-id": intfID, |
| 1196 | "onu-id": onuID}, nil) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1199 | // TODO: OpenOLT Agent oop.OmciMsg expects a hex encoded string for OMCI packets rather than the actual bytes. |
| 1200 | // Fix this in the agent and then we can pass byte array as Pkt: omciMsg.Message. |
lcui | e24ef18 | 2019-04-29 22:58:36 -0700 | [diff] [blame] | 1201 | var omciMessage *oop.OmciMsg |
Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 1202 | hexPkt := make([]byte, hex.EncodedLen(len(omciMsg.Message))) |
| 1203 | hex.Encode(hexPkt, omciMsg.Message) |
| 1204 | omciMessage = &oop.OmciMsg{IntfId: intfID, OnuId: onuID, Pkt: hexPkt} |
| 1205 | |
| 1206 | // TODO: Below logging illustrates the "stringify" of the omci Pkt. |
| 1207 | // once above is fixed this log line can change to just use hex.EncodeToString(omciMessage.Pkt) |
| 1208 | transid := extractOmciTransactionID(omciMsg.Message) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1209 | 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] | 1210 | "omciTransactionID": transid, "omciMsg": string(omciMessage.Pkt)}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1211 | |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1212 | _, err := dh.Client.OmciMsgOut(log.WithSpanFromContext(context.Background(), ctx), omciMessage) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1213 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1214 | return olterrors.NewErrCommunication("omci-send-failed", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1215 | "intf-id": intfID, |
| 1216 | "onu-id": onuID, |
| 1217 | "message": omciMessage}, err) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1218 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1219 | return nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1222 | 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] | 1223 | 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}) |
Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 1224 | if err := dh.flowMgr[intfID].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, intfID, uint32(onuID), serialNumber); err != nil { |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1225 | 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] | 1226 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1227 | var pir uint32 = 1000000 |
kesavand | 494c208 | 2020-08-31 11:16:12 +0530 | [diff] [blame] | 1228 | 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] | 1229 | if _, err := dh.Client.ActivateOnu(ctx, &Onu); err != nil { |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1230 | st, _ := status.FromError(err) |
| 1231 | if st.Code() == codes.AlreadyExists { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1232 | logger.Debugw(ctx, "onu-activation-in-progress", log.Fields{"SerialNumber": serialNumber, "onu-id": onuID, "device-id": dh.device.Id}) |
| 1233 | |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1234 | } else { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1235 | 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] | 1236 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1237 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1238 | 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] | 1239 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1240 | return nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 1243 | func (dh *DeviceHandler) onuDiscIndication(ctx context.Context, onuDiscInd *oop.OnuDiscIndication) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1244 | channelID := onuDiscInd.GetIntfId() |
| 1245 | parentPortNo := IntfIDToPortNo(onuDiscInd.GetIntfId(), voltha.Port_PON_OLT) |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 1246 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 1247 | sn := dh.stringifySerialNumber(onuDiscInd.SerialNumber) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1248 | logger.Infow(ctx, "new-discovery-indication", log.Fields{"sn": sn}) |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1249 | |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 1250 | var alarmInd oop.OnuAlarmIndication |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 1251 | raisedTs := time.Now().Unix() |
Amit Ghosh | e5c6a85 | 2020-02-10 15:09:46 +0000 | [diff] [blame] | 1252 | if _, loaded := dh.discOnus.LoadOrStore(sn, true); loaded { |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 1253 | |
| 1254 | /* When PON cable disconnected and connected back from OLT, it was expected OnuAlarmIndication |
| 1255 | with "los_status: off" should be raised but BAL does not raise this Alarm hence manually sending |
| 1256 | OnuLosClear event on receiving OnuDiscoveryIndication for the Onu after checking whether |
| 1257 | OnuLosRaise event sent for it */ |
| 1258 | dh.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool { |
| 1259 | if onuInCache.(*OnuDevice).serialNumber == sn && onuInCache.(*OnuDevice).losRaised { |
| 1260 | if onuDiscInd.GetIntfId() != onuInCache.(*OnuDevice).intfID { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1261 | logger.Warnw(ctx, "onu-is-on-a-different-intf-id-now", log.Fields{ |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 1262 | "previousIntfId": onuInCache.(*OnuDevice).intfID, |
| 1263 | "currentIntfId": onuDiscInd.GetIntfId()}) |
| 1264 | // TODO:: Should we need to ignore raising OnuLosClear event |
| 1265 | // when onu connected to different PON? |
| 1266 | } |
| 1267 | alarmInd.IntfId = onuInCache.(*OnuDevice).intfID |
| 1268 | alarmInd.OnuId = onuInCache.(*OnuDevice).onuID |
| 1269 | alarmInd.LosStatus = statusCheckOff |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1270 | go func() { |
| 1271 | if err := dh.eventMgr.onuAlarmIndication(ctx, &alarmInd, onuInCache.(*OnuDevice).deviceID, raisedTs); err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1272 | logger.Debugw(ctx, "indication-failed", log.Fields{"err": err}) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1273 | } |
| 1274 | }() |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 1275 | } |
| 1276 | return true |
| 1277 | }) |
| 1278 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1279 | logger.Warnw(ctx, "onu-sn-is-already-being-processed", log.Fields{"sn": sn}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1280 | return nil |
Amit Ghosh | e5c6a85 | 2020-02-10 15:09:46 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 1283 | var onuID uint32 |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1284 | |
| 1285 | // check the ONU is already know to the OLT |
| 1286 | // NOTE the second time the ONU is discovered this should return a device |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1287 | onuDevice, err := dh.getChildDeviceFromCore(ctx, &ic.ChildDeviceFilter{ |
| 1288 | ParentId: dh.device.Id, |
| 1289 | SerialNumber: sn, |
| 1290 | }) |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1291 | |
| 1292 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1293 | 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] | 1294 | if e, ok := status.FromError(err); ok { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1295 | 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] | 1296 | switch e.Code() { |
| 1297 | case codes.Internal: |
| 1298 | // this probably means NOT FOUND, so just create a new device |
| 1299 | onuDevice = nil |
| 1300 | case codes.DeadlineExceeded: |
| 1301 | // if the call times out, cleanup and exit |
| 1302 | dh.discOnus.Delete(sn) |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1303 | 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] | 1304 | } |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | if onuDevice == nil { |
| 1309 | // 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] | 1310 | logger.Debugw(ctx, "creating-new-onu", log.Fields{"sn": sn}) |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1311 | // we need to create a new ChildDevice |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 1312 | ponintfid := onuDiscInd.GetIntfId() |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1313 | onuID, err = dh.resourceMgr[ponintfid].GetONUID(ctx, ponintfid) |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 1314 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1315 | 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] | 1316 | |
| 1317 | if err != nil { |
| 1318 | // if we can't create an ID in resource manager, |
| 1319 | // cleanup and exit |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1320 | dh.discOnus.Delete(sn) |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1321 | return olterrors.NewErrAdapter("resource-manager-get-onu-id-failed", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1322 | "pon-intf-id": ponintfid, |
| 1323 | "serial-number": sn}, err) |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1324 | } |
| 1325 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1326 | if onuDevice, err = dh.sendChildDeviceDetectedToCore(ctx, &ic.DeviceDiscovery{ |
| 1327 | ParentId: dh.device.Id, |
| 1328 | ParentPortNo: parentPortNo, |
| 1329 | ChannelId: channelID, |
| 1330 | VendorId: string(onuDiscInd.SerialNumber.GetVendorId()), |
| 1331 | SerialNumber: sn, |
| 1332 | OnuId: onuID, |
| 1333 | }); err != nil { |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1334 | dh.discOnus.Delete(sn) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1335 | dh.resourceMgr[ponintfid].FreeonuID(ctx, ponintfid, []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] | 1336 | return olterrors.NewErrAdapter("core-proxy-child-device-detected-failed", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1337 | "pon-intf-id": ponintfid, |
| 1338 | "serial-number": sn}, err) |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1339 | } |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 1340 | 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] | 1341 | logger.Warnw(ctx, "discovery-indication-failed", log.Fields{"err": err}) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1342 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1343 | logger.Infow(ctx, "onu-child-device-added", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1344 | log.Fields{"onuDevice": onuDevice, |
| 1345 | "sn": sn, |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1346 | "onu-id": onuID, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1347 | "device-id": dh.device.Id}) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 1348 | } |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1349 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1350 | // Setup the gRPC connection to the adapter responsible for that onuDevice, if not setup yet |
| 1351 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 1352 | err = dh.setupChildInterAdapterClient(subCtx, onuDevice.AdapterEndpoint) |
| 1353 | cancel() |
| 1354 | if err != nil { |
| 1355 | return olterrors.NewErrCommunication("no-connection-to-child-adapter", log.Fields{"device-id": onuDevice.Id}, err) |
| 1356 | } |
| 1357 | |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 1358 | // we can now use the existing ONU Id |
| 1359 | onuID = onuDevice.ProxyAddress.OnuId |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1360 | //Insert the ONU into cache to use in OnuIndication. |
| 1361 | //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] | 1362 | logger.Debugw(ctx, "onu-discovery-indication-key-create", |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1363 | log.Fields{"onu-id": onuID, |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1364 | "intfId": onuDiscInd.GetIntfId(), |
| 1365 | "sn": sn}) |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1366 | onuKey := dh.formOnuKey(onuDiscInd.GetIntfId(), onuID) |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 1367 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1368 | 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] | 1369 | dh.onus.Store(onuKey, onuDev) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1370 | logger.Debugw(ctx, "new-onu-device-discovered", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1371 | log.Fields{"onu": onuDev, |
| 1372 | "sn": sn}) |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 1373 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1374 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
| 1375 | DeviceId: onuDevice.Id, |
| 1376 | ParentDeviceId: dh.device.Id, |
| 1377 | OperStatus: common.OperStatus_DISCOVERED, |
| 1378 | ConnStatus: common.ConnectStatus_REACHABLE, |
| 1379 | }); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1380 | return olterrors.NewErrAdapter("failed-to-update-device-state", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1381 | "device-id": onuDevice.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1382 | "serial-number": sn}, err) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1383 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1384 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1385 | 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] | 1386 | 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] | 1387 | return olterrors.NewErrAdapter("onu-activation-failed", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1388 | "device-id": onuDevice.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1389 | "serial-number": sn}, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1390 | } |
| 1391 | return nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 1394 | func (dh *DeviceHandler) onuIndication(ctx context.Context, onuInd *oop.OnuIndication) error { |
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 | ponPort := IntfIDToPortNo(onuInd.GetIntfId(), voltha.Port_PON_OLT) |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1397 | var onuDevice *voltha.Device |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1398 | var err error |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1399 | foundInCache := false |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1400 | logger.Debugw(ctx, "onu-indication-key-create", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1401 | log.Fields{"onuId": onuInd.OnuId, |
| 1402 | "intfId": onuInd.GetIntfId(), |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1403 | "device-id": dh.device.Id}) |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1404 | onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.OnuId) |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 1405 | serialNumber := dh.stringifySerialNumber(onuInd.SerialNumber) |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1406 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1407 | errFields := log.Fields{"device-id": dh.device.Id} |
| 1408 | |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1409 | if onuInCache, ok := dh.onus.Load(onuKey); ok { |
| 1410 | |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1411 | //If ONU id is discovered before then use GetDevice to get onuDevice because it is cheaper. |
| 1412 | foundInCache = true |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1413 | errFields["onu-id"] = onuInCache.(*OnuDevice).deviceID |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1414 | onuDevice, err = dh.getDeviceFromCore(ctx, onuInCache.(*OnuDevice).deviceID) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1415 | } else { |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1416 | //If ONU not found in adapter cache then we have to use GetChildDevice to get onuDevice |
| 1417 | if serialNumber != "" { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1418 | errFields["serial-number"] = serialNumber |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1419 | } else { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1420 | errFields["onu-id"] = onuInd.OnuId |
| 1421 | errFields["parent-port-no"] = ponPort |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1422 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1423 | onuDevice, err = dh.getChildDeviceFromCore(ctx, &ic.ChildDeviceFilter{ |
| 1424 | ParentId: dh.device.Id, |
| 1425 | SerialNumber: serialNumber, |
| 1426 | OnuId: onuInd.OnuId, |
| 1427 | ParentPortNo: ponPort, |
| 1428 | }) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1429 | } |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 1430 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1431 | if err != nil || onuDevice == nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1432 | return olterrors.NewErrNotFound("onu-device", errFields, err) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1435 | if onuDevice.ParentPortNo != ponPort { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1436 | 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] | 1437 | "previousIntfId": onuDevice.ParentPortNo, |
| 1438 | "currentIntfId": ponPort}) |
| 1439 | } |
| 1440 | |
| 1441 | if onuDevice.ProxyAddress.OnuId != onuInd.OnuId { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1442 | 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] | 1443 | "expected-onu-id": onuDevice.ProxyAddress.OnuId, |
| 1444 | "received-onu-id": onuInd.OnuId, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1445 | "device-id": dh.device.Id}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1446 | } |
| 1447 | if !foundInCache { |
| 1448 | onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.GetOnuId()) |
| 1449 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1450 | 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] | 1451 | |
| 1452 | } |
kesavand | 7cf3a05 | 2020-08-28 12:49:18 +0530 | [diff] [blame] | 1453 | 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] | 1454 | 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] | 1455 | logger.Warnw(ctx, "onu-activation-indication-reporting-failed", log.Fields{"err": err}) |
kesavand | 7cf3a05 | 2020-08-28 12:49:18 +0530 | [diff] [blame] | 1456 | } |
| 1457 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1458 | if err := dh.updateOnuStates(ctx, onuDevice, onuInd); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1459 | return olterrors.NewErrCommunication("state-update-failed", errFields, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1460 | } |
| 1461 | return nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1464 | 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] | 1465 | 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] | 1466 | if onuInd.AdminState == "down" || onuInd.OperState == "down" { |
| 1467 | // The ONU has gone admin_state "down" or oper_state "down" - we expect the ONU to send discovery again |
| 1468 | // The ONU admin_state is "up" while "oper_state" is down in cases where ONU activation fails. In this case |
| 1469 | // the ONU sends Discovery again. |
Girish Gowdra | 429f950 | 2020-05-04 13:22:16 -0700 | [diff] [blame] | 1470 | dh.discOnus.Delete(onuDevice.SerialNumber) |
Amit Ghosh | 9bbc565 | 2020-02-17 13:37:32 +0000 | [diff] [blame] | 1471 | // Tests have shown that we sometimes get OperState as NOT down even if AdminState is down, forcing it |
| 1472 | if onuInd.OperState != "down" { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1473 | logger.Warnw(ctx, "onu-admin-state-down", log.Fields{"operState": onuInd.OperState}) |
Amit Ghosh | 9bbc565 | 2020-02-17 13:37:32 +0000 | [diff] [blame] | 1474 | onuInd.OperState = "down" |
| 1475 | } |
| 1476 | } |
| 1477 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1478 | switch onuInd.OperState { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1479 | case "up", "down": |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1480 | 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^] | 1481 | |
| 1482 | err := dh.sendOnuIndicationToChildAdapter(ctx, onuDevice.AdapterEndpoint, &ic.OnuIndicationMessage{ |
| 1483 | DeviceId: onuDevice.Id, |
| 1484 | OnuIndication: onuInd, |
| 1485 | }) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1486 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1487 | return olterrors.NewErrCommunication("inter-adapter-send-failed", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1488 | "onu-indicator": onuInd, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1489 | "source": dh.openOLT.config.AdapterEndpoint, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1490 | "device-type": onuDevice.Type, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1491 | "device-id": onuDevice.Id}, err) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1492 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1493 | default: |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1494 | return olterrors.NewErrInvalidValue(log.Fields{"oper-state": onuInd.OperState}, nil) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1495 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1496 | return nil |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1499 | func (dh *DeviceHandler) stringifySerialNumber(serialNum *oop.SerialNumber) string { |
| 1500 | if serialNum != nil { |
| 1501 | return string(serialNum.VendorId) + dh.stringifyVendorSpecific(serialNum.VendorSpecific) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1502 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1503 | return "" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1504 | } |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 1505 | func (dh *DeviceHandler) deStringifySerialNumber(serialNum string) (*oop.SerialNumber, error) { |
| 1506 | decodedStr, err := hex.DecodeString(serialNum[4:]) |
| 1507 | if err != nil { |
| 1508 | return nil, err |
| 1509 | } |
| 1510 | return &oop.SerialNumber{ |
| 1511 | VendorId: []byte(serialNum[:4]), |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1512 | VendorSpecific: decodedStr, |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 1513 | }, nil |
| 1514 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1515 | |
| 1516 | func (dh *DeviceHandler) stringifyVendorSpecific(vendorSpecific []byte) string { |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 1517 | if len(vendorSpecific) > 3 { |
| 1518 | tmp := fmt.Sprintf("%x", (uint32(vendorSpecific[0])>>4)&0x0f) + |
| 1519 | fmt.Sprintf("%x", uint32(vendorSpecific[0]&0x0f)) + |
| 1520 | fmt.Sprintf("%x", (uint32(vendorSpecific[1])>>4)&0x0f) + |
| 1521 | fmt.Sprintf("%x", (uint32(vendorSpecific[1]))&0x0f) + |
| 1522 | fmt.Sprintf("%x", (uint32(vendorSpecific[2])>>4)&0x0f) + |
| 1523 | fmt.Sprintf("%x", (uint32(vendorSpecific[2]))&0x0f) + |
| 1524 | fmt.Sprintf("%x", (uint32(vendorSpecific[3])>>4)&0x0f) + |
| 1525 | fmt.Sprintf("%x", (uint32(vendorSpecific[3]))&0x0f) |
| 1526 | return tmp |
| 1527 | } |
| 1528 | return "" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1531 | //UpdateFlowsBulk upates the bulk flow |
| 1532 | func (dh *DeviceHandler) UpdateFlowsBulk() error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1533 | return olterrors.ErrNotImplemented |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 1534 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1535 | |
| 1536 | //GetChildDevice returns the child device for given parent port and onu id |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1537 | func (dh *DeviceHandler) GetChildDevice(ctx context.Context, parentPort, onuID uint32) (*voltha.Device, error) { |
| 1538 | logger.Debugw(ctx, "getchilddevice", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1539 | log.Fields{"pon-port": parentPort, |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1540 | "onu-id": onuID, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1541 | "device-id": dh.device.Id}) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1542 | |
| 1543 | onuDevice, err := dh.getChildDeviceFromCore(ctx, &ic.ChildDeviceFilter{ |
| 1544 | ParentId: dh.device.Id, |
| 1545 | OnuId: onuID, |
| 1546 | ParentPortNo: parentPort, |
| 1547 | }) |
| 1548 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1549 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1550 | return nil, olterrors.NewErrNotFound("onu-device", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1551 | "intf-id": parentPort, |
| 1552 | "onu-id": onuID}, err) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1553 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1554 | 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] | 1555 | return onuDevice, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1556 | } |
| 1557 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1558 | // SendPacketInToCore sends packet-in to core |
| 1559 | // For this, it calls SendPacketIn of the core-proxy which uses a device specific topic to send the request. |
| 1560 | // The adapter handling the device creates a device specific topic |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1561 | func (dh *DeviceHandler) SendPacketInToCore(ctx context.Context, logicalPort uint32, packetPayload []byte) error { |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1562 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1563 | logger.Debugw(ctx, "send-packet-in-to-core", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1564 | "port": logicalPort, |
| 1565 | "packet": hex.EncodeToString(packetPayload), |
| 1566 | "device-id": dh.device.Id, |
| 1567 | }) |
| 1568 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1569 | |
| 1570 | if err := dh.sendPacketToCore(ctx, &ic.PacketIn{ |
| 1571 | DeviceId: dh.device.Id, |
| 1572 | Port: logicalPort, |
| 1573 | Packet: packetPayload, |
| 1574 | }); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1575 | return olterrors.NewErrCommunication("packet-send-failed", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1576 | "source": "adapter", |
| 1577 | "destination": "core", |
| 1578 | "device-id": dh.device.Id, |
| 1579 | "logical-port": logicalPort, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1580 | "packet": hex.EncodeToString(packetPayload)}, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1581 | } |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1582 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1583 | logger.Debugw(ctx, "sent-packet-in-to-core-successfully", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1584 | "packet": hex.EncodeToString(packetPayload), |
| 1585 | "device-id": dh.device.Id, |
| 1586 | }) |
| 1587 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1588 | return nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1589 | } |
| 1590 | |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 1591 | // UpdatePmConfig updates the pm metrics. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1592 | func (dh *DeviceHandler) UpdatePmConfig(ctx context.Context, pmConfigs *voltha.PmConfigs) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1593 | 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] | 1594 | |
| 1595 | if pmConfigs.DefaultFreq != dh.metrics.ToPmConfigs().DefaultFreq { |
| 1596 | dh.metrics.UpdateFrequency(pmConfigs.DefaultFreq) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1597 | logger.Debugf(ctx, "frequency-updated") |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1600 | if !pmConfigs.Grouped { |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 1601 | metrics := dh.metrics.GetSubscriberMetrics() |
| 1602 | for _, m := range pmConfigs.Metrics { |
| 1603 | metrics[m.Name].Enabled = m.Enabled |
| 1604 | |
| 1605 | } |
| 1606 | } |
| 1607 | } |
| 1608 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1609 | //UpdateFlowsIncrementally updates the device flow |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1610 | func (dh *DeviceHandler) UpdateFlowsIncrementally(ctx context.Context, device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1611 | logger.Debugw(ctx, "received-incremental-flowupdate-in-device-handler", log.Fields{"device-id": device.Id, "flows": flows, "groups": groups, "flowMetadata": flowMetadata}) |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 1612 | |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 1613 | var err error |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 1614 | var errorsList []error |
| 1615 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1616 | if flows != nil { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1617 | for _, flow := range flows.ToRemove.Items { |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1618 | ponIf := dh.getPonIfFromFlow(flow) |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 1619 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1620 | logger.Debugw(ctx, "removing-flow", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1621 | log.Fields{"device-id": device.Id, |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1622 | "ponIf": ponIf, |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1623 | "flowToRemove": flow}) |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 1624 | if flow_utils.HasGroup(flow) { |
| 1625 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, flow, nil, McastFlowOrGroupRemove) |
| 1626 | } else { |
| 1627 | err = dh.flowMgr[ponIf].RouteFlowToOnuChannel(ctx, flow, false, nil) |
| 1628 | } |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 1629 | if err != nil { |
| 1630 | errorsList = append(errorsList, err) |
| 1631 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1632 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1633 | |
| 1634 | for _, flow := range flows.ToAdd.Items { |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1635 | ponIf := dh.getPonIfFromFlow(flow) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1636 | logger.Debugw(ctx, "adding-flow", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1637 | log.Fields{"device-id": device.Id, |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1638 | "ponIf": ponIf, |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 1639 | "flowToAdd": flow}) |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 1640 | if flow_utils.HasGroup(flow) { |
| 1641 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, flow, nil, McastFlowOrGroupAdd) |
| 1642 | } else { |
| 1643 | err = dh.flowMgr[ponIf].RouteFlowToOnuChannel(ctx, flow, true, flowMetadata) |
| 1644 | } |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 1645 | if err != nil { |
| 1646 | errorsList = append(errorsList, err) |
| 1647 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1648 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1649 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1650 | |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 1651 | // 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] | 1652 | if groups != nil { |
| 1653 | for _, group := range groups.ToAdd.Items { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 1654 | // err = dh.groupMgr.AddGroup(ctx, group) |
| 1655 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, nil, group, McastFlowOrGroupAdd) |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 1656 | if err != nil { |
| 1657 | errorsList = append(errorsList, err) |
| 1658 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1659 | } |
| 1660 | for _, group := range groups.ToUpdate.Items { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 1661 | // err = dh.groupMgr.ModifyGroup(ctx, group) |
| 1662 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, nil, group, McastFlowOrGroupModify) |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 1663 | if err != nil { |
| 1664 | errorsList = append(errorsList, err) |
| 1665 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1666 | } |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1667 | for _, group := range groups.ToRemove.Items { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 1668 | // err = dh.groupMgr.DeleteGroup(ctx, group) |
| 1669 | err = dh.RouteMcastFlowOrGroupMsgToChannel(ctx, nil, group, McastFlowOrGroupRemove) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1670 | if err != nil { |
| 1671 | errorsList = append(errorsList, err) |
| 1672 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1673 | } |
| 1674 | } |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 1675 | if len(errorsList) > 0 { |
| 1676 | return fmt.Errorf("errors-installing-flows-groups, errors:%v", errorsList) |
| 1677 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1678 | 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] | 1679 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1680 | } |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1681 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1682 | //DisableDevice disables the given device |
| 1683 | //It marks the following for the given device: |
| 1684 | //Device-Handler Admin-State : down |
| 1685 | //Device Port-State: UNKNOWN |
| 1686 | //Device Oper-State: UNKNOWN |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1687 | func (dh *DeviceHandler) DisableDevice(ctx context.Context, device *voltha.Device) error { |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 1688 | /* On device disable ,admin state update has to be done prior sending request to agent since |
| 1689 | the indication thread may processes invalid indications of ONU and OLT*/ |
Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 1690 | if dh.Client != nil { |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1691 | 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] | 1692 | if e, ok := status.FromError(err); ok && e.Code() == codes.Internal { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1693 | 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] | 1694 | } |
Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 1695 | } |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 1696 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1697 | logger.Debugw(ctx, "olt-disabled", log.Fields{"device-id": device.Id}) |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 1698 | /* 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] | 1699 | UNREACHABLE state which needs to be configured again*/ |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1700 | |
| 1701 | dh.discOnus = sync.Map{} |
| 1702 | dh.onus = sync.Map{} |
| 1703 | |
Thomas Lee S | 85f3731 | 2020-04-03 17:06:12 +0530 | [diff] [blame] | 1704 | //stopping the stats collector |
| 1705 | dh.stopCollector <- true |
| 1706 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1707 | go dh.notifyChildDevices(ctx, "unreachable") |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1708 | cloned := proto.Clone(device).(*voltha.Device) |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1709 | //Update device Admin state |
| 1710 | dh.device = cloned |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1711 | |
kdarapu | 1afeceb | 2020-02-12 01:38:09 -0500 | [diff] [blame] | 1712 | // Update the all pon ports state on that device to disable and NNI remains active as NNI remains active in openolt agent. |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1713 | if err := dh.updatePortsStateInCore(ctx, &ic.PortStateFilter{ |
| 1714 | DeviceId: cloned.Id, |
| 1715 | PortTypeFilter: ^uint32(1 << voltha.Port_PON_OLT), |
| 1716 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 1717 | }); err != nil { |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 1718 | 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] | 1719 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1720 | logger.Debugw(ctx, "disable-device-end", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1721 | return nil |
| 1722 | } |
| 1723 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1724 | func (dh *DeviceHandler) notifyChildDevices(ctx context.Context, state string) { |
Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 1725 | // Update onu state as unreachable in onu adapter |
| 1726 | onuInd := oop.OnuIndication{} |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 1727 | onuInd.OperState = state |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1728 | |
Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 1729 | //get the child device for the parent device |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1730 | onuDevices, err := dh.getChildDevicesFromCore(ctx, dh.device.Id) |
Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 1731 | if err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1732 | 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] | 1733 | } |
| 1734 | if onuDevices != nil { |
| 1735 | for _, onuDevice := range onuDevices.Items { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1736 | err := dh.sendOnuIndicationToChildAdapter(ctx, onuDevice.AdapterEndpoint, &ic.OnuIndicationMessage{ |
| 1737 | DeviceId: onuDevice.Id, |
| 1738 | OnuIndication: &onuInd, |
| 1739 | }) |
Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 1740 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1741 | logger.Errorw(ctx, "failed-to-send-inter-adapter-message", log.Fields{"OnuInd": onuInd, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1742 | "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] | 1743 | } |
| 1744 | |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | } |
| 1749 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1750 | //ReenableDevice re-enables the olt device after disable |
| 1751 | //It marks the following for the given device: |
| 1752 | //Device-Handler Admin-State : up |
| 1753 | //Device Port-State: ACTIVE |
| 1754 | //Device Oper-State: ACTIVE |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1755 | func (dh *DeviceHandler) ReenableDevice(ctx context.Context, device *voltha.Device) error { |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1756 | if _, err := dh.Client.ReenableOlt(log.WithSpanFromContext(context.Background(), ctx), new(oop.Empty)); err != nil { |
Abhilash Laxmeshwar | 5b302e1 | 2020-01-09 15:15:14 +0530 | [diff] [blame] | 1757 | if e, ok := status.FromError(err); ok && e.Code() == codes.Internal { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1758 | return olterrors.NewErrAdapter("olt-reenable-failed", log.Fields{"device-id": dh.device.Id}, err) |
Abhilash Laxmeshwar | 5b302e1 | 2020-01-09 15:15:14 +0530 | [diff] [blame] | 1759 | } |
| 1760 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1761 | logger.Debug(ctx, "olt-reenabled") |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1762 | |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1763 | // Update the all ports state on that device to enable |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1764 | ports, err := dh.listDevicePortsFromCore(ctx, device.Id) |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 1765 | if err != nil { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 1766 | return olterrors.NewErrAdapter("list-ports-failed", log.Fields{"device-id": device.Id}, err) |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 1767 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1768 | if err := dh.disableAdminDownPorts(ctx, ports.Items); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1769 | return olterrors.NewErrAdapter("port-status-update-failed-after-olt-reenable", log.Fields{"device": device}, err) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1770 | } |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1771 | //Update the device oper status as ACTIVE |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 1772 | device.OperStatus = voltha.OperStatus_ACTIVE |
| 1773 | dh.device = device |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1774 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1775 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
| 1776 | DeviceId: device.Id, |
| 1777 | OperStatus: device.OperStatus, |
| 1778 | ConnStatus: device.ConnectStatus, |
| 1779 | }); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1780 | return olterrors.NewErrAdapter("state-update-failed", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1781 | "device-id": device.Id, |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 1782 | "connect-status": device.ConnectStatus, |
| 1783 | "oper-status": device.OperStatus}, err) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1784 | } |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 1785 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1786 | logger.Debugw(ctx, "reenabledevice-end", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1787 | |
| 1788 | return nil |
| 1789 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1790 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1791 | func (dh *DeviceHandler) clearUNIData(ctx context.Context, onu *rsrcMgr.OnuGemInfo) error { |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1792 | var uniID uint32 |
| 1793 | var err error |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1794 | for _, port := range onu.UniPorts { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1795 | uniID = UniIDFromPortNum(port) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1796 | 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] | 1797 | /* Delete tech-profile instance from the KV store */ |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1798 | if err = dh.flowMgr[onu.IntfID].DeleteTechProfileInstances(ctx, onu.IntfID, onu.OnuID, uniID); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1799 | logger.Debugw(ctx, "failed-to-remove-tech-profile-instance-for-onu", log.Fields{"onu-id": onu.OnuID}) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1800 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1801 | logger.Debugw(ctx, "deleted-tech-profile-instance-for-onu", log.Fields{"onu-id": onu.OnuID}) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1802 | tpIDList := dh.resourceMgr[onu.IntfID].GetTechProfileIDForOnu(ctx, onu.IntfID, onu.OnuID, uniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1803 | for _, tpID := range tpIDList { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1804 | if err = dh.resourceMgr[onu.IntfID].RemoveMeterInfoForOnu(ctx, "upstream", onu.IntfID, onu.OnuID, uniID, tpID); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1805 | logger.Debugw(ctx, "failed-to-remove-meter-id-for-onu-upstream", log.Fields{"onu-id": onu.OnuID}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1806 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1807 | logger.Debugw(ctx, "removed-meter-id-for-onu-upstream", log.Fields{"onu-id": onu.OnuID}) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1808 | if err = dh.resourceMgr[onu.IntfID].RemoveMeterInfoForOnu(ctx, "downstream", onu.IntfID, onu.OnuID, uniID, tpID); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1809 | logger.Debugw(ctx, "failed-to-remove-meter-id-for-onu-downstream", log.Fields{"onu-id": onu.OnuID}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1810 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1811 | 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] | 1812 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1813 | dh.resourceMgr[onu.IntfID].FreePONResourcesForONU(ctx, onu.IntfID, onu.OnuID, uniID) |
| 1814 | if err = dh.resourceMgr[onu.IntfID].RemoveTechProfileIDsForOnu(ctx, onu.IntfID, onu.OnuID, uniID); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1815 | logger.Debugw(ctx, "failed-to-remove-tech-profile-id-for-onu", log.Fields{"onu-id": onu.OnuID}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1816 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1817 | logger.Debugw(ctx, "removed-tech-profile-id-for-onu", log.Fields{"onu-id": onu.OnuID}) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1818 | if err = dh.resourceMgr[onu.IntfID].DeletePacketInGemPortForOnu(ctx, onu.IntfID, onu.OnuID, port); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1819 | logger.Debugw(ctx, "failed-to-remove-gemport-pkt-in", log.Fields{"intfid": onu.IntfID, "onuid": onu.OnuID, "uniId": uniID}) |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 1820 | } |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1821 | } |
| 1822 | return nil |
| 1823 | } |
| 1824 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1825 | // 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] | 1826 | func (dh *DeviceHandler) DeleteDevice(ctx context.Context, device *voltha.Device) error { |
Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 1827 | 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] | 1828 | /* Clear the KV store data associated with the all the UNI ports |
| 1829 | This clears up flow data and also resource map data for various |
| 1830 | other pon resources like alloc_id and gemport_id |
| 1831 | */ |
Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 1832 | dh.cleanupDeviceResources(ctx) |
| 1833 | logger.Debugw(ctx, "removed-device-from-Resource-manager-KV-store", log.Fields{"device-id": dh.device.Id}) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1834 | // Stop the Stats collector |
| 1835 | dh.stopCollector <- true |
| 1836 | // stop the heartbeat check routine |
| 1837 | dh.stopHeartbeatCheck <- true |
Himani Chawla | 49a5d56 | 2020-11-25 11:53:44 +0530 | [diff] [blame] | 1838 | dh.lockDevice.RLock() |
| 1839 | // Stop the read indication only if it the routine is active |
| 1840 | if dh.isReadIndicationRoutineActive { |
| 1841 | dh.stopIndications <- true |
| 1842 | } |
| 1843 | dh.lockDevice.RUnlock() |
Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 1844 | dh.removeOnuIndicationChannels(ctx) |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 1845 | go dh.StopAllMcastHandlerRoutines(ctx) |
| 1846 | for _, flMgr := range dh.flowMgr { |
| 1847 | go flMgr.StopAllFlowHandlerRoutines(ctx) |
| 1848 | } |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1849 | //Reset the state |
| 1850 | if dh.Client != nil { |
| 1851 | if _, err := dh.Client.Reboot(ctx, new(oop.Empty)); err != nil { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1852 | return olterrors.NewErrAdapter("olt-reboot-failed", log.Fields{"device-id": dh.device.Id}, err).Log() |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1853 | } |
| 1854 | } |
Girish Gowdra | b1caa44 | 2020-10-19 12:24:39 -0700 | [diff] [blame] | 1855 | // There is no need to update the core about operation status and connection status of the OLT. |
| 1856 | // The OLT is getting deleted anyway and the core might have already cleared the OLT device from its DB. |
| 1857 | // So any attempt to update the operation status and connection status of the OLT will result in core throwing an error back, |
| 1858 | // because the device does not exist in DB. |
Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 1859 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1860 | return nil |
| 1861 | } |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1862 | func (dh *DeviceHandler) cleanupDeviceResources(ctx context.Context) { |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1863 | |
Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 1864 | if dh.resourceMgr != nil { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1865 | var ponPort uint32 |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1866 | for ponPort = 0; ponPort < dh.totalPonPorts; ponPort++ { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1867 | var err error |
Girish Gowdra | bcf98af | 2021-07-01 08:24:42 -0700 | [diff] [blame] | 1868 | onuGemData := dh.flowMgr[ponPort].getOnuGemInfoList(ctx) |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 1869 | for i, onu := range onuGemData { |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1870 | onuID := make([]uint32, 1) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1871 | logger.Debugw(ctx, "onu-data", log.Fields{"onu": onu}) |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame] | 1872 | if err = dh.clearUNIData(ctx, &onuGemData[i]); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1873 | logger.Errorw(ctx, "failed-to-clear-data-for-onu", log.Fields{"onu-device": onu}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1874 | } |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1875 | // Clear flowids for gem cache. |
| 1876 | for _, gem := range onu.GemPorts { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1877 | dh.resourceMgr[ponPort].DeleteFlowIDsForGem(ctx, ponPort, gem) |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1878 | } |
| 1879 | onuID[0] = onu.OnuID |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1880 | dh.resourceMgr[ponPort].FreeonuID(ctx, ponPort, onuID) |
| 1881 | err = dh.resourceMgr[ponPort].DelOnuGemInfo(ctx, ponPort, onu.OnuID) |
| 1882 | if err != nil { |
| 1883 | logger.Errorw(ctx, "failed-to-update-onugem-info", log.Fields{"intfid": ponPort, "onugeminfo": onuGemData}) |
| 1884 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1885 | } |
Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 1886 | if err := dh.resourceMgr[ponPort].Delete(ctx, ponPort); err != nil { |
| 1887 | logger.Debug(ctx, err) |
| 1888 | } |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1889 | } |
Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 1890 | } |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 1891 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1892 | /*Delete ONU map for the device*/ |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1893 | dh.onus.Range(func(key interface{}, value interface{}) bool { |
| 1894 | dh.onus.Delete(key) |
| 1895 | return true |
| 1896 | }) |
| 1897 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 1898 | /*Delete discovered ONU map for the device*/ |
| 1899 | dh.discOnus.Range(func(key interface{}, value interface{}) bool { |
| 1900 | dh.discOnus.Delete(key) |
| 1901 | return true |
| 1902 | }) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1903 | } |
| 1904 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1905 | //RebootDevice reboots the given device |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1906 | func (dh *DeviceHandler) RebootDevice(ctx context.Context, device *voltha.Device) error { |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1907 | if _, err := dh.Client.Reboot(log.WithSpanFromContext(context.Background(), ctx), new(oop.Empty)); err != nil { |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1908 | return olterrors.NewErrAdapter("olt-reboot-failed", log.Fields{"device-id": dh.device.Id}, err) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1909 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1910 | logger.Debugw(ctx, "rebooted-device-successfully", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1911 | return nil |
| 1912 | } |
| 1913 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1914 | func (dh *DeviceHandler) handlePacketIndication(ctx context.Context, packetIn *oop.PacketIndication) error { |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1915 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1916 | logger.Debugw(ctx, "received-packet-in", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1917 | "packet-indication": *packetIn, |
| 1918 | "device-id": dh.device.Id, |
| 1919 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 1920 | }) |
| 1921 | } |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1922 | logicalPortNum, err := dh.flowMgr[packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, packetIn) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1923 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1924 | 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] | 1925 | } |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1926 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1927 | logger.Debugw(ctx, "sending-packet-in-to-core", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1928 | "logical-port-num": logicalPortNum, |
| 1929 | "device-id": dh.device.Id, |
| 1930 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 1931 | }) |
| 1932 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1933 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1934 | if err := dh.sendPacketToCore(ctx, &ic.PacketIn{ |
| 1935 | DeviceId: dh.device.Id, |
| 1936 | Port: logicalPortNum, |
| 1937 | Packet: packetIn.Pkt, |
| 1938 | }); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1939 | return olterrors.NewErrCommunication("send-packet-in", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1940 | "destination": "core", |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1941 | "source": dh.device.Type, |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1942 | "device-id": dh.device.Id, |
| 1943 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 1944 | }, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1945 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1946 | |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1947 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1948 | logger.Debugw(ctx, "success-sending-packet-in-to-core!", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1949 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 1950 | "device-id": dh.device.Id, |
| 1951 | }) |
| 1952 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1953 | return nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1954 | } |
| 1955 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1956 | // PacketOut sends packet-out from VOLTHA to OLT on the egress port provided |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1957 | 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] | 1958 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1959 | logger.Debugw(ctx, "incoming-packet-out", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1960 | "device-id": dh.device.Id, |
| 1961 | "egress-port-no": egressPortNo, |
| 1962 | "pkt-length": len(packet.Data), |
| 1963 | "packet": hex.EncodeToString(packet.Data), |
| 1964 | }) |
| 1965 | } |
Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 1966 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1967 | egressPortType := IntfIDToPortTypeName(uint32(egressPortNo)) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1968 | if egressPortType == voltha.Port_ETHERNET_UNI { |
Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 1969 | outerEthType := (uint16(packet.Data[12]) << 8) | uint16(packet.Data[13]) |
| 1970 | innerEthType := (uint16(packet.Data[16]) << 8) | uint16(packet.Data[17]) |
Girish Gowdra | 6e1534a | 2019-11-15 19:24:04 +0530 | [diff] [blame] | 1971 | if outerEthType == 0x8942 || outerEthType == 0x88cc { |
| 1972 | // Do not packet-out lldp packets on uni port. |
| 1973 | // ONOS has no clue about uni/nni ports, it just packets out on all |
| 1974 | // available ports on the Logical Switch. It should not be interested |
| 1975 | // in the UNI links. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1976 | logger.Debugw(ctx, "dropping-lldp-packet-out-on-uni", log.Fields{ |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1977 | "device-id": dh.device.Id, |
| 1978 | }) |
Girish Gowdra | 6e1534a | 2019-11-15 19:24:04 +0530 | [diff] [blame] | 1979 | return nil |
| 1980 | } |
Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 1981 | if outerEthType == 0x88a8 || outerEthType == 0x8100 { |
| 1982 | if innerEthType == 0x8100 { |
| 1983 | // q-in-q 802.1ad or 802.1q double tagged packet. |
| 1984 | // slice out the outer tag. |
| 1985 | packet.Data = append(packet.Data[:12], packet.Data[16:]...) |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1986 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1987 | logger.Debugw(ctx, "packet-now-single-tagged", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1988 | "packet-data": hex.EncodeToString(packet.Data), |
| 1989 | "device-id": dh.device.Id, |
| 1990 | }) |
| 1991 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1992 | } |
| 1993 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1994 | intfID := IntfIDFromUniPortNum(uint32(egressPortNo)) |
| 1995 | onuID := OnuIDFromPortNum(uint32(egressPortNo)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1996 | uniID := UniIDFromPortNum(uint32(egressPortNo)) |
| 1997 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1998 | gemPortID, err := dh.flowMgr[intfID].GetPacketOutGemPortID(ctx, intfID, onuID, uint32(egressPortNo), packet.Data) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1999 | if err != nil { |
| 2000 | // In this case the openolt agent will receive the gemPortID as 0. |
| 2001 | // The agent tries to retrieve the gemPortID in this case. |
| 2002 | // This may not always succeed at the agent and packetOut may fail. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2003 | logger.Errorw(ctx, "failed-to-retrieve-gemport-id-for-packet-out", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2004 | "intf-id": intfID, |
| 2005 | "onu-id": onuID, |
| 2006 | "uni-id": uniID, |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 2007 | "packet": hex.EncodeToString(packet.Data), |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2008 | "device-id": dh.device.Id, |
Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 2009 | }) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | onuPkt := oop.OnuPacket{IntfId: intfID, OnuId: onuID, PortNo: uint32(egressPortNo), GemportId: gemPortID, Pkt: packet.Data} |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2013 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2014 | logger.Debugw(ctx, "sending-packet-to-onu", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2015 | "egress-port-no": egressPortNo, |
| 2016 | "intf-id": intfID, |
| 2017 | "onu-id": onuID, |
| 2018 | "uni-id": uniID, |
| 2019 | "gem-port-id": gemPortID, |
| 2020 | "packet": hex.EncodeToString(packet.Data), |
| 2021 | "device-id": dh.device.Id, |
| 2022 | }) |
| 2023 | } |
Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 2024 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2025 | if _, err := dh.Client.OnuPacketOut(ctx, &onuPkt); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2026 | return olterrors.NewErrCommunication("packet-out-send", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2027 | "source": "adapter", |
| 2028 | "destination": "onu", |
| 2029 | "egress-port-number": egressPortNo, |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2030 | "intf-id": intfID, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2031 | "oni-id": onuID, |
| 2032 | "uni-id": uniID, |
| 2033 | "gem-port-id": gemPortID, |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 2034 | "packet": hex.EncodeToString(packet.Data), |
| 2035 | "device-id": dh.device.Id, |
| 2036 | }, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2037 | } |
| 2038 | } else if egressPortType == voltha.Port_ETHERNET_NNI { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2039 | nniIntfID, err := IntfIDFromNniPortNum(ctx, uint32(egressPortNo)) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2040 | if err != nil { |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 2041 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 2042 | "egress-nni-port": egressPortNo, |
| 2043 | "device-id": dh.device.Id, |
| 2044 | }, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2045 | } |
| 2046 | uplinkPkt := oop.UplinkPacket{IntfId: nniIntfID, Pkt: packet.Data} |
Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 2047 | |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2048 | if logger.V(log.DebugLevel) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2049 | logger.Debugw(ctx, "sending-packet-to-nni", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2050 | "uplink-pkt": uplinkPkt, |
| 2051 | "packet": hex.EncodeToString(packet.Data), |
| 2052 | "device-id": dh.device.Id, |
| 2053 | }) |
| 2054 | } |
Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 2055 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2056 | if _, err := dh.Client.UplinkPacketOut(ctx, &uplinkPkt); err != nil { |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 2057 | return olterrors.NewErrCommunication("packet-out-to-nni", log.Fields{ |
| 2058 | "packet": hex.EncodeToString(packet.Data), |
| 2059 | "device-id": dh.device.Id, |
| 2060 | }, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2061 | } |
| 2062 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2063 | 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] | 2064 | "egress-port-no": egressPortNo, |
Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 2065 | "egressPortType": egressPortType, |
| 2066 | "packet": hex.EncodeToString(packet.Data), |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2067 | "device-id": dh.device.Id, |
Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 2068 | }) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2069 | } |
| 2070 | return nil |
| 2071 | } |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 2072 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2073 | func (dh *DeviceHandler) formOnuKey(intfID, onuID uint32) string { |
| 2074 | return "" + strconv.Itoa(int(intfID)) + "." + strconv.Itoa(int(onuID)) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 2075 | } |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2076 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2077 | func startHeartbeatCheck(ctx context.Context, dh *DeviceHandler) { |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 2078 | |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2079 | // start the heartbeat check towards the OLT. |
| 2080 | var timerCheck *time.Timer |
| 2081 | |
| 2082 | for { |
| 2083 | heartbeatTimer := time.NewTimer(dh.openOLT.HeartbeatCheckInterval) |
| 2084 | select { |
| 2085 | case <-heartbeatTimer.C: |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 2086 | 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] | 2087 | if heartBeat, err := dh.Client.HeartbeatCheck(ctxWithTimeout, new(oop.Empty)); err != nil { |
Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2088 | logger.Warnw(ctx, "heartbeat-failed", log.Fields{"device-id": dh.device.Id}) |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2089 | if timerCheck == nil { |
| 2090 | // 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] | 2091 | timerCheck = time.AfterFunc(dh.openOLT.HeartbeatFailReportInterval, func() { dh.updateStateUnreachable(ctx) }) |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2092 | } |
| 2093 | } else { |
| 2094 | if timerCheck != nil { |
| 2095 | if timerCheck.Stop() { |
Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2096 | 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] | 2097 | } |
| 2098 | timerCheck = nil |
| 2099 | } |
Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2100 | logger.Debugw(ctx, "heartbeat", |
Shrey Baid | 807a2a0 | 2020-04-09 12:52:45 +0530 | [diff] [blame] | 2101 | log.Fields{"signature": heartBeat, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2102 | "device-id": dh.device.Id}) |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2103 | } |
| 2104 | cancel() |
| 2105 | case <-dh.stopHeartbeatCheck: |
Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2106 | 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] | 2107 | return |
| 2108 | } |
| 2109 | } |
| 2110 | } |
| 2111 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2112 | func (dh *DeviceHandler) updateStateUnreachable(ctx context.Context) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 2113 | device, err := dh.getDeviceFromCore(ctx, dh.device.Id) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2114 | if err != nil || device == nil { |
Girish Gowdra | b1caa44 | 2020-10-19 12:24:39 -0700 | [diff] [blame] | 2115 | // One case where we have seen core returning an error for GetDevice call is after OLT device delete. |
| 2116 | // After OLT delete, the adapter asks for OLT to reboot. When OLT is rebooted, shortly we loose heartbeat. |
| 2117 | // The 'startHeartbeatCheck' then asks the device to be marked unreachable towards the core, but the core |
| 2118 | // has already deleted the device and returns error. In this particular scenario, it is Ok because any necessary |
| 2119 | // cleanup in the adapter was already done during DeleteDevice API handler routine. |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2120 | _ = olterrors.NewErrNotFound("device", log.Fields{"device-id": dh.device.Id}, err).Log() |
Girish Gowdra | b1caa44 | 2020-10-19 12:24:39 -0700 | [diff] [blame] | 2121 | // Immediately return, otherwise accessing a null 'device' struct would cause panic |
| 2122 | return |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2123 | } |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2124 | |
Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2125 | logger.Debugw(ctx, "update-state-unreachable", log.Fields{"device-id": dh.device.Id, "connect-status": device.ConnectStatus, |
| 2126 | "admin-state": device.AdminState, "oper-status": device.OperStatus}) |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2127 | if device.ConnectStatus == voltha.ConnectStatus_REACHABLE { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 2128 | if err = dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
| 2129 | DeviceId: dh.device.Id, |
| 2130 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2131 | ConnStatus: voltha.ConnectStatus_UNREACHABLE, |
| 2132 | }); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2133 | _ = 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] | 2134 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 2135 | |
| 2136 | if err = dh.updatePortsStateInCore(ctx, &ic.PortStateFilter{ |
| 2137 | DeviceId: dh.device.Id, |
| 2138 | PortTypeFilter: 0, |
| 2139 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2140 | }); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2141 | _ = olterrors.NewErrAdapter("port-update-failed", log.Fields{"device-id": dh.device.Id}, err).Log() |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2142 | } |
Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 2143 | |
| 2144 | //raise olt communication failure event |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 2145 | raisedTs := time.Now().Unix() |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 2146 | cloned := proto.Clone(device).(*voltha.Device) |
| 2147 | cloned.ConnectStatus = voltha.ConnectStatus_UNREACHABLE |
| 2148 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 2149 | dh.device = cloned // update local copy of the device |
| 2150 | go dh.eventMgr.oltCommunicationEvent(ctx, cloned, raisedTs) |
Gamze Abaka | 07868a5 | 2020-12-17 14:19:28 +0000 | [diff] [blame] | 2151 | |
Girish Gowdra | b8f1b5a | 2021-06-27 20:42:40 -0700 | [diff] [blame] | 2152 | dh.cleanupDeviceResources(ctx) |
Matteo Scandolo | 861e06e | 2021-05-26 11:51:46 -0700 | [diff] [blame] | 2153 | // Stop the Stats collector |
| 2154 | dh.stopCollector <- true |
| 2155 | // stop the heartbeat check routine |
| 2156 | dh.stopHeartbeatCheck <- true |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2157 | |
Girish Gowdra | 3ab6d21 | 2020-03-24 17:33:15 -0700 | [diff] [blame] | 2158 | dh.lockDevice.RLock() |
| 2159 | // Stop the read indication only if it the routine is active |
| 2160 | // The read indication would have already stopped due to failure on the gRPC stream following OLT going unreachable |
| 2161 | // Sending message on the 'stopIndication' channel again will cause the readIndication routine to immediately stop |
| 2162 | // on next execution of the readIndication routine. |
| 2163 | if dh.isReadIndicationRoutineActive { |
| 2164 | dh.stopIndications <- true |
| 2165 | } |
| 2166 | dh.lockDevice.RUnlock() |
| 2167 | |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2168 | go dh.StopAllMcastHandlerRoutines(ctx) |
| 2169 | for _, flMgr := range dh.flowMgr { |
| 2170 | go flMgr.StopAllFlowHandlerRoutines(ctx) |
| 2171 | } |
| 2172 | |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 2173 | //reset adapter reconcile flag |
| 2174 | dh.adapterPreviouslyConnected = false |
| 2175 | |
Chaitrashree G S | a464925 | 2020-03-11 21:24:11 -0400 | [diff] [blame] | 2176 | dh.transitionMap.Handle(ctx, DeviceInit) |
| 2177 | |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 2178 | } |
| 2179 | } |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2180 | |
| 2181 | // EnablePort to enable Pon interface |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2182 | func (dh *DeviceHandler) EnablePort(ctx context.Context, port *voltha.Port) error { |
| 2183 | logger.Debugw(ctx, "enable-port", log.Fields{"Device": dh.device, "port": port}) |
| 2184 | return dh.modifyPhyPort(ctx, port, true) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | // DisablePort to disable pon interface |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2188 | func (dh *DeviceHandler) DisablePort(ctx context.Context, port *voltha.Port) error { |
| 2189 | logger.Debugw(ctx, "disable-port", log.Fields{"Device": dh.device, "port": port}) |
| 2190 | return dh.modifyPhyPort(ctx, port, false) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2191 | } |
| 2192 | |
kdarapu | 1afeceb | 2020-02-12 01:38:09 -0500 | [diff] [blame] | 2193 | //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] | 2194 | func (dh *DeviceHandler) modifyPhyPort(ctx context.Context, port *voltha.Port, enablePort bool) error { |
| 2195 | 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] | 2196 | if port.GetType() == voltha.Port_ETHERNET_NNI { |
| 2197 | // Bug is opened for VOL-2505 to support NNI disable feature. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2198 | 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] | 2199 | log.Fields{"device": dh.device, "port": port}) |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2200 | return olterrors.NewErrAdapter("illegal-port-request", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2201 | "port-type": port.GetType, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2202 | "enable-state": enablePort}, nil) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2203 | } |
| 2204 | // fetch interfaceid from PortNo |
| 2205 | ponID := PortNoToIntfID(port.GetPortNo(), voltha.Port_PON_OLT) |
| 2206 | ponIntf := &oop.Interface{IntfId: ponID} |
| 2207 | var operStatus voltha.OperStatus_Types |
| 2208 | if enablePort { |
| 2209 | operStatus = voltha.OperStatus_ACTIVE |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2210 | out, err := dh.Client.EnablePonIf(ctx, ponIntf) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2211 | |
| 2212 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2213 | return olterrors.NewErrAdapter("pon-port-enable-failed", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2214 | "device-id": dh.device.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2215 | "port": port}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2216 | } |
| 2217 | // updating interface local cache for collecting stats |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 2218 | dh.activePorts.Store(ponID, true) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2219 | 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] | 2220 | } else { |
| 2221 | operStatus = voltha.OperStatus_UNKNOWN |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2222 | out, err := dh.Client.DisablePonIf(ctx, ponIntf) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2223 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2224 | return olterrors.NewErrAdapter("pon-port-disable-failed", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2225 | "device-id": dh.device.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2226 | "port": port}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2227 | } |
| 2228 | // updating interface local cache for collecting stats |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 2229 | dh.activePorts.Store(ponID, false) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2230 | 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] | 2231 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 2232 | if err := dh.updatePortStateInCore(ctx, &ic.PortState{ |
| 2233 | DeviceId: dh.device.Id, |
| 2234 | PortType: voltha.Port_PON_OLT, |
| 2235 | PortNo: port.PortNo, |
| 2236 | OperStatus: operStatus, |
| 2237 | }); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2238 | return olterrors.NewErrAdapter("port-state-update-failed", log.Fields{ |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2239 | "device-id": dh.device.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2240 | "port": port.PortNo}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2241 | } |
| 2242 | return nil |
| 2243 | } |
| 2244 | |
kdarapu | 1afeceb | 2020-02-12 01:38:09 -0500 | [diff] [blame] | 2245 | //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] | 2246 | func (dh *DeviceHandler) disableAdminDownPorts(ctx context.Context, ports []*voltha.Port) error { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2247 | // Disable the port and update the oper_port_status to core |
| 2248 | // 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] | 2249 | for _, port := range ports { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2250 | if port.AdminState == common.AdminState_DISABLED { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2251 | if err := dh.DisablePort(ctx, port); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2252 | return olterrors.NewErrAdapter("port-disable-failed", log.Fields{ |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2253 | "device-id": dh.device.Id, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2254 | "port": port}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2255 | } |
| 2256 | } |
| 2257 | } |
| 2258 | return nil |
| 2259 | } |
| 2260 | |
| 2261 | //populateActivePorts to populate activePorts map |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 2262 | func (dh *DeviceHandler) populateActivePorts(ctx context.Context, ports []*voltha.Port) { |
| 2263 | logger.Infow(ctx, "populateActivePorts", log.Fields{"device-id": dh.device.Id}) |
| 2264 | for _, port := range ports { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2265 | if port.Type == voltha.Port_ETHERNET_NNI { |
| 2266 | if port.OperStatus == voltha.OperStatus_ACTIVE { |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 2267 | dh.activePorts.Store(PortNoToIntfID(port.PortNo, voltha.Port_ETHERNET_NNI), true) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2268 | } else { |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 2269 | dh.activePorts.Store(PortNoToIntfID(port.PortNo, voltha.Port_ETHERNET_NNI), false) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2270 | } |
| 2271 | } |
| 2272 | if port.Type == voltha.Port_PON_OLT { |
| 2273 | if port.OperStatus == voltha.OperStatus_ACTIVE { |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 2274 | dh.activePorts.Store(PortNoToIntfID(port.PortNo, voltha.Port_PON_OLT), true) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2275 | } else { |
Chaitrashree G S | ef08811 | 2020-02-03 21:39:27 -0500 | [diff] [blame] | 2276 | dh.activePorts.Store(PortNoToIntfID(port.PortNo, voltha.Port_PON_OLT), false) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 2277 | } |
| 2278 | } |
| 2279 | } |
| 2280 | } |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 2281 | |
| 2282 | // ChildDeviceLost deletes ONU and clears pon resources related to it. |
Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 2283 | 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] | 2284 | logger.Debugw(ctx, "child-device-lost", log.Fields{"parent-device-id": dh.device.Id}) |
Girish Gowdra | 89ae6d8 | 2020-05-28 23:40:53 -0700 | [diff] [blame] | 2285 | intfID := PortNoToIntfID(pPortNo, voltha.Port_PON_OLT) |
| 2286 | onuKey := dh.formOnuKey(intfID, onuID) |
Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 2287 | |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 2288 | var sn *oop.SerialNumber |
| 2289 | var err error |
Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 2290 | if sn, err = dh.deStringifySerialNumber(onuSn); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2291 | return olterrors.NewErrAdapter("failed-to-destringify-serial-number", |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 2292 | log.Fields{ |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2293 | "devicer-id": dh.device.Id, |
Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 2294 | "serial-number": onuSn}, err).Log() |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 2295 | } |
Girish Gowdra | 89ae6d8 | 2020-05-28 23:40:53 -0700 | [diff] [blame] | 2296 | |
Girish Gowdra | 89ae6d8 | 2020-05-28 23:40:53 -0700 | [diff] [blame] | 2297 | onu := &oop.Onu{IntfId: intfID, OnuId: onuID, SerialNumber: sn} |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2298 | //clear PON resources associated with ONU |
| 2299 | onuGem, err := dh.resourceMgr[intfID].GetOnuGemInfo(ctx, intfID, onuID) |
| 2300 | if err != nil || onuGem == nil || onuGem.OnuID != onuID { |
| 2301 | logger.Warnw(ctx, "failed-to-get-onu-info-for-pon-port", log.Fields{ |
| 2302 | "device-id": dh.device.Id, |
| 2303 | "intf-id": intfID, |
| 2304 | "onuID": onuID, |
| 2305 | "err": err}) |
| 2306 | } else { |
| 2307 | logger.Debugw(ctx, "onu-data", log.Fields{"onu": onu}) |
| 2308 | if err := dh.clearUNIData(ctx, onuGem); err != nil { |
| 2309 | logger.Warnw(ctx, "failed-to-clear-uni-data-for-onu", log.Fields{ |
| 2310 | "device-id": dh.device.Id, |
| 2311 | "onu-device": onu, |
| 2312 | "err": err}) |
| 2313 | } |
| 2314 | // Clear flowids for gem cache. |
| 2315 | for _, gem := range onuGem.GemPorts { |
| 2316 | dh.resourceMgr[intfID].DeleteFlowIDsForGem(ctx, intfID, gem) |
| 2317 | } |
Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 2318 | if err := dh.flowMgr[intfID].RemoveOnuInfoFromFlowMgrCacheAndKvStore(ctx, intfID, onuID); err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2319 | logger.Warnw(ctx, "persistence-update-onu-gem-info-failed", log.Fields{ |
| 2320 | "intf-id": intfID, |
| 2321 | "onu-device": onu, |
| 2322 | "onu-gem": onuGem, |
| 2323 | "err": err}) |
| 2324 | //Not returning error on cleanup. |
| 2325 | } |
| 2326 | logger.Debugw(ctx, "removed-onu-gem-info", log.Fields{"intf": intfID, "onu-device": onu, "onugem": onuGem}) |
| 2327 | dh.resourceMgr[intfID].FreeonuID(ctx, intfID, []uint32{onuGem.OnuID}) |
| 2328 | } |
| 2329 | dh.onus.Delete(onuKey) |
| 2330 | dh.discOnus.Delete(onuSn) |
| 2331 | |
| 2332 | // Now clear the ONU on the OLT |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 2333 | 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] | 2334 | return olterrors.NewErrAdapter("failed-to-delete-onu", log.Fields{ |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2335 | "device-id": dh.device.Id, |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 2336 | "onu-id": onuID}, err).Log() |
| 2337 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2338 | |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 2339 | return nil |
| 2340 | } |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2341 | |
| 2342 | func getInPortFromFlow(flow *of.OfpFlowStats) uint32 { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2343 | for _, field := range flow_utils.GetOfbFields(flow) { |
| 2344 | if field.Type == flow_utils.IN_PORT { |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2345 | return field.GetPort() |
| 2346 | } |
| 2347 | } |
| 2348 | return InvalidPort |
| 2349 | } |
| 2350 | |
| 2351 | func getOutPortFromFlow(flow *of.OfpFlowStats) uint32 { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2352 | for _, action := range flow_utils.GetActions(flow) { |
| 2353 | if action.Type == flow_utils.OUTPUT { |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2354 | if out := action.GetOutput(); out != nil { |
| 2355 | return out.GetPort() |
| 2356 | } |
| 2357 | } |
| 2358 | } |
| 2359 | return InvalidPort |
| 2360 | } |
| 2361 | |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2362 | func getPorts(flow *of.OfpFlowStats) (uint32, uint32) { |
| 2363 | inPort := getInPortFromFlow(flow) |
| 2364 | outPort := getOutPortFromFlow(flow) |
| 2365 | |
| 2366 | if inPort == InvalidPort || outPort == InvalidPort { |
| 2367 | return inPort, outPort |
| 2368 | } |
| 2369 | |
| 2370 | if isControllerFlow := IsControllerBoundFlow(outPort); isControllerFlow { |
| 2371 | /* Get UNI port/ IN Port from tunnel ID field for upstream controller bound flows */ |
| 2372 | if portType := IntfIDToPortTypeName(inPort); portType == voltha.Port_PON_OLT { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2373 | if uniPort := flow_utils.GetChildPortFromTunnelId(flow); uniPort != 0 { |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2374 | return uniPort, outPort |
| 2375 | } |
| 2376 | } |
| 2377 | } else { |
| 2378 | // Downstream flow from NNI to PON port , Use tunnel ID as new OUT port / UNI port |
| 2379 | if portType := IntfIDToPortTypeName(outPort); portType == voltha.Port_PON_OLT { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2380 | if uniPort := flow_utils.GetChildPortFromTunnelId(flow); uniPort != 0 { |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2381 | return inPort, uniPort |
| 2382 | } |
| 2383 | // Upstream flow from PON to NNI port , Use tunnel ID as new IN port / UNI port |
| 2384 | } else if portType := IntfIDToPortTypeName(inPort); portType == voltha.Port_PON_OLT { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2385 | if uniPort := flow_utils.GetChildPortFromTunnelId(flow); uniPort != 0 { |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2386 | return uniPort, outPort |
| 2387 | } |
| 2388 | } |
| 2389 | } |
| 2390 | |
| 2391 | return InvalidPort, InvalidPort |
| 2392 | } |
Matt Jeanneret | ceea2e0 | 2020-03-27 14:19:57 -0400 | [diff] [blame] | 2393 | |
| 2394 | func extractOmciTransactionID(omciPkt []byte) uint16 { |
| 2395 | if len(omciPkt) > 3 { |
| 2396 | d := omciPkt[0:2] |
| 2397 | transid := binary.BigEndian.Uint16(d) |
| 2398 | return transid |
| 2399 | } |
| 2400 | return 0 |
| 2401 | } |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 2402 | |
| 2403 | // StoreOnuDevice stores the onu parameters to the local cache. |
| 2404 | func (dh *DeviceHandler) StoreOnuDevice(onuDevice *OnuDevice) { |
| 2405 | onuKey := dh.formOnuKey(onuDevice.intfID, onuDevice.onuID) |
| 2406 | dh.onus.Store(onuKey, onuDevice) |
| 2407 | } |
Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 2408 | |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 2409 | func (dh *DeviceHandler) getExtValue(ctx context.Context, device *voltha.Device, value voltha.ValueType_Type) (*voltha.ReturnValues, error) { |
Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 2410 | var err error |
Andrea Campanella | 9931ad6 | 2020-04-28 15:11:06 +0200 | [diff] [blame] | 2411 | var sn *oop.SerialNumber |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 2412 | var ID uint32 |
Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 2413 | resp := new(voltha.ReturnValues) |
| 2414 | valueparam := new(oop.ValueParam) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 2415 | ctx = log.WithSpanFromContext(context.Background(), ctx) |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 2416 | 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] | 2417 | if sn, err = dh.deStringifySerialNumber(device.SerialNumber); err != nil { |
| 2418 | return nil, err |
| 2419 | } |
| 2420 | ID = device.ProxyAddress.GetOnuId() |
| 2421 | Onu := oop.Onu{IntfId: device.ParentPortNo, OnuId: ID, SerialNumber: sn} |
| 2422 | valueparam.Onu = &Onu |
| 2423 | valueparam.Value = value |
| 2424 | |
| 2425 | // This API is unsupported until agent patch is added |
| 2426 | resp.Unsupported = uint32(value) |
| 2427 | _ = ctx |
| 2428 | |
| 2429 | // Uncomment this code once agent changes are complete and tests |
| 2430 | /* |
| 2431 | resp, err = dh.Client.GetValue(ctx, valueparam) |
| 2432 | if err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2433 | 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] | 2434 | return nil, err |
| 2435 | } |
| 2436 | */ |
| 2437 | |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 2438 | 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] | 2439 | return resp, nil |
| 2440 | } |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2441 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2442 | func (dh *DeviceHandler) getPonIfFromFlow(flow *of.OfpFlowStats) uint32 { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2443 | // Default to PON0 |
| 2444 | var intfID uint32 |
| 2445 | inPort, outPort := getPorts(flow) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2446 | if inPort != InvalidPort && outPort != InvalidPort { |
| 2447 | _, intfID, _, _ = ExtractAccessFromFlow(inPort, outPort) |
| 2448 | } |
| 2449 | return intfID |
| 2450 | } |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2451 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2452 | func (dh *DeviceHandler) getOnuIndicationChannel(ctx context.Context, intfID uint32) chan onuIndicationMsg { |
| 2453 | dh.perPonOnuIndicationChannelLock.Lock() |
| 2454 | if ch, ok := dh.perPonOnuIndicationChannel[intfID]; ok { |
| 2455 | dh.perPonOnuIndicationChannelLock.Unlock() |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2456 | return ch.indicationChannel |
| 2457 | } |
| 2458 | channels := onuIndicationChannels{ |
| 2459 | //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] | 2460 | //in case of multiple indications from the ONUs, |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2461 | //especially in the case where indications are buffered in OLT. |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2462 | indicationChannel: make(chan onuIndicationMsg, 500), |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2463 | stopChannel: make(chan struct{}), |
| 2464 | } |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2465 | dh.perPonOnuIndicationChannel[intfID] = channels |
| 2466 | dh.perPonOnuIndicationChannelLock.Unlock() |
| 2467 | go dh.onuIndicationsRoutine(&channels) |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2468 | return channels.indicationChannel |
| 2469 | |
| 2470 | } |
| 2471 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2472 | func (dh *DeviceHandler) removeOnuIndicationChannels(ctx context.Context) { |
| 2473 | logger.Debug(ctx, "remove-onu-indication-channels", log.Fields{"device-id": dh.device.Id}) |
| 2474 | dh.perPonOnuIndicationChannelLock.Lock() |
| 2475 | defer dh.perPonOnuIndicationChannelLock.Unlock() |
| 2476 | for _, v := range dh.perPonOnuIndicationChannel { |
| 2477 | close(v.stopChannel) |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2478 | } |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2479 | dh.perPonOnuIndicationChannel = make(map[uint32]onuIndicationChannels) |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2480 | } |
| 2481 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2482 | func (dh *DeviceHandler) putOnuIndicationToChannel(ctx context.Context, indication *oop.Indication, intfID uint32) { |
| 2483 | ind := onuIndicationMsg{ |
| 2484 | ctx: ctx, |
| 2485 | indication: indication, |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2486 | } |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2487 | 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] | 2488 | // Send the onuIndication on the ONU channel |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2489 | dh.getOnuIndicationChannel(ctx, intfID) <- ind |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2490 | } |
| 2491 | |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2492 | func (dh *DeviceHandler) onuIndicationsRoutine(onuChannels *onuIndicationChannels) { |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2493 | for { |
| 2494 | select { |
| 2495 | // process one indication per onu, before proceeding to the next one |
| 2496 | case onuInd := <-onuChannels.indicationChannel: |
| 2497 | logger.Debugw(onuInd.ctx, "calling-indication", log.Fields{"device-id": dh.device.Id, |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2498 | "ind": onuInd.indication}) |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2499 | switch onuInd.indication.Data.(type) { |
| 2500 | case *oop.Indication_OnuInd: |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2501 | if err := dh.onuIndication(onuInd.ctx, onuInd.indication.GetOnuInd()); err != nil { |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2502 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{ |
| 2503 | "type": "onu-indication", |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2504 | "device-id": dh.device.Id}, err).Log() |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2505 | } |
| 2506 | case *oop.Indication_OnuDiscInd: |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2507 | if err := dh.onuDiscIndication(onuInd.ctx, onuInd.indication.GetOnuDiscInd()); err != nil { |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2508 | _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{ |
| 2509 | "type": "onu-discovery", |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 2510 | "device-id": dh.device.Id}, err).Log() |
Mahir Gunyel | 2fb8147 | 2020-12-16 23:18:34 -0800 | [diff] [blame] | 2511 | } |
| 2512 | } |
| 2513 | case <-onuChannels.stopChannel: |
| 2514 | logger.Debugw(context.Background(), "stop-signal-received-for-onu-channel", log.Fields{"device-id": dh.device.Id}) |
| 2515 | close(onuChannels.indicationChannel) |
| 2516 | return |
| 2517 | } |
| 2518 | } |
| 2519 | } |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2520 | |
| 2521 | // RouteMcastFlowOrGroupMsgToChannel routes incoming mcast flow or group to a channel to be handled by the a specific |
| 2522 | // instance of mcastFlowOrGroupChannelHandlerRoutine meant to handle messages for that group. |
| 2523 | func (dh *DeviceHandler) RouteMcastFlowOrGroupMsgToChannel(ctx context.Context, flow *voltha.OfpFlowStats, group *voltha.OfpGroupEntry, action string) error { |
| 2524 | // Step1 : Fill McastFlowOrGroupControlBlock |
| 2525 | // Step2 : Push the McastFlowOrGroupControlBlock to appropriate channel |
| 2526 | // Step3 : Wait on response channel for response |
| 2527 | // Step4 : Return error value |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2528 | startTime := time.Now() |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2529 | logger.Debugw(ctx, "process-flow-or-group", log.Fields{"flow": flow, "group": group, "action": action}) |
| 2530 | errChan := make(chan error) |
| 2531 | var groupID uint32 |
| 2532 | mcastFlowOrGroupCb := McastFlowOrGroupControlBlock{ |
| 2533 | ctx: ctx, |
| 2534 | flowOrGroupAction: action, |
| 2535 | flow: flow, |
| 2536 | group: group, |
| 2537 | errChan: &errChan, |
| 2538 | } |
| 2539 | if flow != nil { |
| 2540 | groupID = flow_utils.GetGroup(flow) |
| 2541 | } else if group != nil { |
| 2542 | groupID = group.Desc.GroupId |
| 2543 | } else { |
| 2544 | return errors.New("flow-and-group-both-nil") |
| 2545 | } |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2546 | mcastRoutineIdx := groupID % MaxNumOfGroupHandlerChannels |
| 2547 | if dh.mcastHandlerRoutineActive[mcastRoutineIdx] { |
| 2548 | // Derive the appropriate go routine to handle the request by a simple module operation. |
| 2549 | // There are only MaxNumOfGroupHandlerChannels number of channels to handle the mcast flow or group |
| 2550 | dh.incomingMcastFlowOrGroup[groupID%MaxNumOfGroupHandlerChannels] <- mcastFlowOrGroupCb |
| 2551 | // Wait for handler to return error value |
| 2552 | err := <-errChan |
| 2553 | logger.Debugw(ctx, "process-flow-or-group--received-resp", log.Fields{"err": err, "totalTimeInSeconds": time.Since(startTime).Milliseconds()}) |
| 2554 | return err |
| 2555 | } |
| 2556 | logger.Errorw(ctx, "mcast handler routine not active for onu", log.Fields{"mcastRoutineIdx": mcastRoutineIdx}) |
| 2557 | return fmt.Errorf("mcast-handler-routine-not-active-for-index-%v", mcastRoutineIdx) |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | // mcastFlowOrGroupChannelHandlerRoutine routine to handle incoming mcast flow/group message |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2561 | func (dh *DeviceHandler) mcastFlowOrGroupChannelHandlerRoutine(routineIndex int, mcastFlowOrGroupChannel chan McastFlowOrGroupControlBlock, stopHandler chan bool) { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2562 | for { |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2563 | select { |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2564 | // block on the channel to receive an incoming mcast flow/group |
| 2565 | // process the flow completely before proceeding to handle the next flow |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2566 | case mcastFlowOrGroupCb := <-mcastFlowOrGroupChannel: |
| 2567 | if mcastFlowOrGroupCb.flow != nil { |
| 2568 | if mcastFlowOrGroupCb.flowOrGroupAction == McastFlowOrGroupAdd { |
| 2569 | logger.Debugw(mcastFlowOrGroupCb.ctx, "adding-mcast-flow", |
| 2570 | log.Fields{"device-id": dh.device.Id, |
| 2571 | "flowToAdd": mcastFlowOrGroupCb.flow}) |
| 2572 | // The mcast flow is not unique to any particular PON port, so it is OK to default to PON0 |
| 2573 | err := dh.flowMgr[0].AddFlow(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.flow, nil) |
| 2574 | // Pass the return value over the return channel |
| 2575 | *mcastFlowOrGroupCb.errChan <- err |
| 2576 | } else { // flow remove |
| 2577 | logger.Debugw(mcastFlowOrGroupCb.ctx, "removing-mcast-flow", |
| 2578 | log.Fields{"device-id": dh.device.Id, |
| 2579 | "flowToRemove": mcastFlowOrGroupCb.flow}) |
| 2580 | // The mcast flow is not unique to any particular PON port, so it is OK to default to PON0 |
| 2581 | err := dh.flowMgr[0].RemoveFlow(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.flow) |
| 2582 | // Pass the return value over the return channel |
| 2583 | *mcastFlowOrGroupCb.errChan <- err |
| 2584 | } |
| 2585 | } else { // mcast group |
| 2586 | if mcastFlowOrGroupCb.flowOrGroupAction == McastFlowOrGroupAdd { |
| 2587 | logger.Debugw(mcastFlowOrGroupCb.ctx, "adding-mcast-group", |
| 2588 | log.Fields{"device-id": dh.device.Id, |
| 2589 | "groupToAdd": mcastFlowOrGroupCb.group}) |
| 2590 | err := dh.groupMgr.AddGroup(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.group) |
| 2591 | // Pass the return value over the return channel |
| 2592 | *mcastFlowOrGroupCb.errChan <- err |
| 2593 | } else if mcastFlowOrGroupCb.flowOrGroupAction == McastFlowOrGroupModify { // group modify |
| 2594 | logger.Debugw(mcastFlowOrGroupCb.ctx, "modifying-mcast-group", |
| 2595 | log.Fields{"device-id": dh.device.Id, |
| 2596 | "groupToModify": mcastFlowOrGroupCb.group}) |
| 2597 | err := dh.groupMgr.ModifyGroup(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.group) |
| 2598 | // Pass the return value over the return channel |
| 2599 | *mcastFlowOrGroupCb.errChan <- err |
| 2600 | } else { // group remove |
| 2601 | logger.Debugw(mcastFlowOrGroupCb.ctx, "removing-mcast-group", |
| 2602 | log.Fields{"device-id": dh.device.Id, |
| 2603 | "groupToRemove": mcastFlowOrGroupCb.group}) |
| 2604 | err := dh.groupMgr.DeleteGroup(mcastFlowOrGroupCb.ctx, mcastFlowOrGroupCb.group) |
| 2605 | // Pass the return value over the return channel |
| 2606 | *mcastFlowOrGroupCb.errChan <- err |
| 2607 | } |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2608 | } |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2609 | case <-stopHandler: |
| 2610 | dh.mcastHandlerRoutineActive[routineIndex] = false |
| 2611 | return |
Girish Gowdra | 491a9c6 | 2021-01-06 16:43:07 -0800 | [diff] [blame] | 2612 | } |
| 2613 | } |
| 2614 | } |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 2615 | |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2616 | // StopAllMcastHandlerRoutines stops all flow handler routines. Call this when device is being rebooted or deleted |
| 2617 | func (dh *DeviceHandler) StopAllMcastHandlerRoutines(ctx context.Context) { |
| 2618 | for i, v := range dh.stopMcastHandlerRoutine { |
| 2619 | if dh.mcastHandlerRoutineActive[i] { |
| 2620 | v <- true |
| 2621 | } |
| 2622 | } |
| 2623 | logger.Debug(ctx, "stopped all mcast handler routines") |
| 2624 | } |
| 2625 | |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 2626 | func (dh *DeviceHandler) getOltPortCounters(ctx context.Context, oltPortInfo *extension.GetOltPortCounters) *extension.SingleGetValueResponse { |
| 2627 | |
| 2628 | singleValResp := extension.SingleGetValueResponse{ |
| 2629 | Response: &extension.GetValueResponse{ |
| 2630 | Response: &extension.GetValueResponse_PortCoutners{ |
| 2631 | PortCoutners: &extension.GetOltPortCountersResponse{}, |
| 2632 | }, |
| 2633 | }, |
| 2634 | } |
| 2635 | |
| 2636 | errResp := func(status extension.GetValueResponse_Status, |
| 2637 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 2638 | return &extension.SingleGetValueResponse{ |
| 2639 | Response: &extension.GetValueResponse{ |
| 2640 | Status: status, |
| 2641 | ErrReason: reason, |
| 2642 | }, |
| 2643 | } |
| 2644 | } |
| 2645 | |
| 2646 | if oltPortInfo.PortType != extension.GetOltPortCounters_Port_ETHERNET_NNI && |
| 2647 | oltPortInfo.PortType != extension.GetOltPortCounters_Port_PON_OLT { |
| 2648 | //send error response |
| 2649 | logger.Debugw(ctx, "getOltPortCounters invalid portType", log.Fields{"oltPortInfo": oltPortInfo.PortType}) |
| 2650 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_PORT_TYPE) |
| 2651 | } |
| 2652 | statIndChn := make(chan bool, 1) |
| 2653 | dh.portStats.RegisterForStatIndication(ctx, portStatsType, statIndChn, oltPortInfo.PortNo, oltPortInfo.PortType) |
| 2654 | defer dh.portStats.DeRegisterFromStatIndication(ctx, portStatsType, statIndChn) |
| 2655 | //request openOlt agent to send the the port statistics indication |
| 2656 | |
| 2657 | go func() { |
| 2658 | _, err := dh.Client.CollectStatistics(ctx, new(oop.Empty)) |
| 2659 | if err != nil { |
| 2660 | logger.Errorw(ctx, "getOltPortCounters CollectStatistics failed ", log.Fields{"err": err}) |
| 2661 | } |
| 2662 | }() |
| 2663 | select { |
| 2664 | case <-statIndChn: |
| 2665 | //indication received for ports stats |
| 2666 | logger.Debugw(ctx, "getOltPortCounters recvd statIndChn", log.Fields{"oltPortInfo": oltPortInfo}) |
| 2667 | case <-time.After(oltPortInfoTimeout * time.Second): |
| 2668 | logger.Debugw(ctx, "getOltPortCounters timeout happened", log.Fields{"oltPortInfo": oltPortInfo}) |
| 2669 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_TIMEOUT) |
| 2670 | case <-ctx.Done(): |
| 2671 | logger.Debugw(ctx, "getOltPortCounters ctx Done ", log.Fields{"oltPortInfo": oltPortInfo}) |
| 2672 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_TIMEOUT) |
| 2673 | } |
| 2674 | if oltPortInfo.PortType == extension.GetOltPortCounters_Port_ETHERNET_NNI { |
| 2675 | //get nni stats |
| 2676 | intfID := PortNoToIntfID(oltPortInfo.PortNo, voltha.Port_ETHERNET_NNI) |
| 2677 | logger.Debugw(ctx, "getOltPortCounters intfID ", log.Fields{"intfID": intfID}) |
| 2678 | cmnni := dh.portStats.collectNNIMetrics(intfID) |
| 2679 | if cmnni == nil { |
| 2680 | //TODO define the error reason |
| 2681 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 2682 | } |
| 2683 | dh.portStats.updateGetOltPortCountersResponse(ctx, &singleValResp, cmnni) |
| 2684 | return &singleValResp |
| 2685 | |
| 2686 | } else if oltPortInfo.PortType == extension.GetOltPortCounters_Port_PON_OLT { |
| 2687 | // get pon stats |
| 2688 | intfID := PortNoToIntfID(oltPortInfo.PortNo, voltha.Port_PON_OLT) |
| 2689 | if val, ok := dh.activePorts.Load(intfID); ok && val == true { |
| 2690 | cmpon := dh.portStats.collectPONMetrics(intfID) |
| 2691 | if cmpon == nil { |
| 2692 | //TODO define the error reason |
| 2693 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 2694 | } |
| 2695 | dh.portStats.updateGetOltPortCountersResponse(ctx, &singleValResp, cmpon) |
| 2696 | return &singleValResp |
| 2697 | } |
| 2698 | } |
| 2699 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 2700 | } |
Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 2701 | |
| 2702 | func (dh *DeviceHandler) getOnuPonCounters(ctx context.Context, onuPonInfo *extension.GetOnuCountersRequest) *extension.SingleGetValueResponse { |
| 2703 | |
| 2704 | singleValResp := extension.SingleGetValueResponse{ |
| 2705 | Response: &extension.GetValueResponse{ |
| 2706 | Response: &extension.GetValueResponse_OnuPonCounters{ |
| 2707 | OnuPonCounters: &extension.GetOnuCountersResponse{}, |
| 2708 | }, |
| 2709 | }, |
| 2710 | } |
| 2711 | |
| 2712 | errResp := func(status extension.GetValueResponse_Status, |
| 2713 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 2714 | return &extension.SingleGetValueResponse{ |
| 2715 | Response: &extension.GetValueResponse{ |
| 2716 | Status: status, |
| 2717 | ErrReason: reason, |
| 2718 | }, |
| 2719 | } |
| 2720 | } |
| 2721 | intfID := onuPonInfo.IntfId |
| 2722 | onuID := onuPonInfo.OnuId |
| 2723 | onuKey := dh.formOnuKey(intfID, onuID) |
| 2724 | |
| 2725 | if _, ok := dh.onus.Load(onuKey); !ok { |
| 2726 | logger.Errorw(ctx, "get-onui-pon-counters-request-invalid-request-received", log.Fields{"intfID": intfID, "onuID": onuID}) |
| 2727 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE) |
| 2728 | } |
| 2729 | logger.Debugw(ctx, "get-onui-pon-counters-request-received", log.Fields{"intfID": intfID, "onuID": onuID}) |
| 2730 | cmnni := dh.portStats.collectOnDemandOnuStats(ctx, intfID, onuID) |
| 2731 | if cmnni == nil { |
| 2732 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 2733 | } |
| 2734 | dh.portStats.updateGetOnuPonCountersResponse(ctx, &singleValResp, cmnni) |
| 2735 | return &singleValResp |
| 2736 | |
| 2737 | } |
Gamze Abaka | 85e9a14 | 2021-05-26 13:41:39 +0000 | [diff] [blame] | 2738 | |
| 2739 | func (dh *DeviceHandler) getRxPower(ctx context.Context, rxPowerRequest *extension.GetRxPowerRequest) *extension.SingleGetValueResponse { |
| 2740 | |
| 2741 | Onu := oop.Onu{IntfId: rxPowerRequest.IntfId, OnuId: rxPowerRequest.OnuId} |
| 2742 | rxPower, err := dh.Client.GetPonRxPower(ctx, &Onu) |
| 2743 | if err != nil { |
| 2744 | logger.Errorw(ctx, "error-while-getting-rx-power", log.Fields{"Onu": Onu, "err": err}) |
| 2745 | return generateSingleGetValueErrorResponse(err) |
| 2746 | } |
| 2747 | return &extension.SingleGetValueResponse{ |
| 2748 | Response: &extension.GetValueResponse{ |
| 2749 | Status: extension.GetValueResponse_OK, |
| 2750 | Response: &extension.GetValueResponse_RxPower{ |
| 2751 | RxPower: &extension.GetRxPowerResponse{ |
| 2752 | IntfId: rxPowerRequest.IntfId, |
| 2753 | OnuId: rxPowerRequest.OnuId, |
| 2754 | Status: rxPower.Status, |
| 2755 | FailReason: rxPower.FailReason.String(), |
| 2756 | RxPower: rxPower.RxPowerMeanDbm, |
| 2757 | }, |
| 2758 | }, |
| 2759 | }, |
| 2760 | } |
| 2761 | } |
| 2762 | |
| 2763 | func generateSingleGetValueErrorResponse(err error) *extension.SingleGetValueResponse { |
| 2764 | errResp := func(status extension.GetValueResponse_Status, |
| 2765 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 2766 | return &extension.SingleGetValueResponse{ |
| 2767 | Response: &extension.GetValueResponse{ |
| 2768 | Status: status, |
| 2769 | ErrReason: reason, |
| 2770 | }, |
| 2771 | } |
| 2772 | } |
| 2773 | |
| 2774 | if err != nil { |
| 2775 | if e, ok := status.FromError(err); ok { |
| 2776 | switch e.Code() { |
| 2777 | case codes.Internal: |
| 2778 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INTERNAL_ERROR) |
| 2779 | case codes.DeadlineExceeded: |
| 2780 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_TIMEOUT) |
| 2781 | case codes.Unimplemented: |
| 2782 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_UNSUPPORTED) |
| 2783 | case codes.NotFound: |
| 2784 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE) |
| 2785 | } |
| 2786 | } |
| 2787 | } |
| 2788 | |
| 2789 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_REASON_UNDEFINED) |
| 2790 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 2791 | |
| 2792 | /* |
| 2793 | Helper functions to communicate with Core |
| 2794 | */ |
| 2795 | |
| 2796 | func (dh *DeviceHandler) getDeviceFromCore(ctx context.Context, deviceID string) (*voltha.Device, error) { |
| 2797 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 2798 | if err != nil || cClient == nil { |
| 2799 | return nil, err |
| 2800 | } |
| 2801 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2802 | defer cancel() |
| 2803 | return cClient.GetDevice(subCtx, &common.ID{Id: deviceID}) |
| 2804 | } |
| 2805 | |
| 2806 | func (dh *DeviceHandler) getChildDeviceFromCore(ctx context.Context, childDeviceFilter *ic.ChildDeviceFilter) (*voltha.Device, error) { |
| 2807 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 2808 | if err != nil || cClient == nil { |
| 2809 | return nil, err |
| 2810 | } |
| 2811 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2812 | defer cancel() |
| 2813 | return cClient.GetChildDevice(subCtx, childDeviceFilter) |
| 2814 | } |
| 2815 | |
| 2816 | func (dh *DeviceHandler) updateDeviceStateInCore(ctx context.Context, deviceStateFilter *ic.DeviceStateFilter) error { |
| 2817 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 2818 | if err != nil || cClient == nil { |
| 2819 | return err |
| 2820 | } |
| 2821 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2822 | defer cancel() |
| 2823 | _, err = cClient.DeviceStateUpdate(subCtx, deviceStateFilter) |
| 2824 | return err |
| 2825 | } |
| 2826 | |
| 2827 | func (dh *DeviceHandler) getChildDevicesFromCore(ctx context.Context, deviceID string) (*voltha.Devices, error) { |
| 2828 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 2829 | if err != nil || cClient == nil { |
| 2830 | return nil, err |
| 2831 | } |
| 2832 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2833 | defer cancel() |
| 2834 | return cClient.GetChildDevices(subCtx, &common.ID{Id: deviceID}) |
| 2835 | } |
| 2836 | |
| 2837 | func (dh *DeviceHandler) listDevicePortsFromCore(ctx context.Context, deviceID string) (*voltha.Ports, error) { |
| 2838 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 2839 | if err != nil || cClient == nil { |
| 2840 | return nil, err |
| 2841 | } |
| 2842 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2843 | defer cancel() |
| 2844 | return cClient.ListDevicePorts(subCtx, &common.ID{Id: deviceID}) |
| 2845 | } |
| 2846 | |
| 2847 | func (dh *DeviceHandler) updateDeviceInCore(ctx context.Context, device *voltha.Device) error { |
| 2848 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 2849 | if err != nil || cClient == nil { |
| 2850 | return err |
| 2851 | } |
| 2852 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2853 | defer cancel() |
| 2854 | _, err = cClient.DeviceUpdate(subCtx, device) |
| 2855 | return err |
| 2856 | } |
| 2857 | |
| 2858 | func (dh *DeviceHandler) sendChildDeviceDetectedToCore(ctx context.Context, deviceDiscoveryInfo *ic.DeviceDiscovery) (*voltha.Device, error) { |
| 2859 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 2860 | if err != nil || cClient == nil { |
| 2861 | return nil, err |
| 2862 | } |
| 2863 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2864 | defer cancel() |
| 2865 | return cClient.ChildDeviceDetected(subCtx, deviceDiscoveryInfo) |
| 2866 | } |
| 2867 | |
| 2868 | func (dh *DeviceHandler) sendPacketToCore(ctx context.Context, pkt *ic.PacketIn) error { |
| 2869 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 2870 | if err != nil || cClient == nil { |
| 2871 | return err |
| 2872 | } |
| 2873 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2874 | defer cancel() |
| 2875 | _, err = cClient.SendPacketIn(subCtx, pkt) |
| 2876 | return err |
| 2877 | } |
| 2878 | |
| 2879 | func (dh *DeviceHandler) createPortInCore(ctx context.Context, port *voltha.Port) error { |
| 2880 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 2881 | if err != nil || cClient == nil { |
| 2882 | return err |
| 2883 | } |
| 2884 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2885 | defer cancel() |
| 2886 | _, err = cClient.PortCreated(subCtx, port) |
| 2887 | return err |
| 2888 | } |
| 2889 | |
| 2890 | func (dh *DeviceHandler) updatePortsStateInCore(ctx context.Context, portFilter *ic.PortStateFilter) error { |
| 2891 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 2892 | if err != nil || cClient == nil { |
| 2893 | return err |
| 2894 | } |
| 2895 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2896 | defer cancel() |
| 2897 | _, err = cClient.PortsStateUpdate(subCtx, portFilter) |
| 2898 | return err |
| 2899 | } |
| 2900 | |
| 2901 | func (dh *DeviceHandler) updatePortStateInCore(ctx context.Context, portState *ic.PortState) error { |
| 2902 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 2903 | if err != nil || cClient == nil { |
| 2904 | return err |
| 2905 | } |
| 2906 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2907 | defer cancel() |
| 2908 | _, err = cClient.PortStateUpdate(subCtx, portState) |
| 2909 | return err |
| 2910 | } |
| 2911 | |
| 2912 | func (dh *DeviceHandler) getPortFromCore(ctx context.Context, portFilter *ic.PortFilter) (*voltha.Port, error) { |
| 2913 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 2914 | if err != nil || cClient == nil { |
| 2915 | return nil, err |
| 2916 | } |
| 2917 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2918 | defer cancel() |
| 2919 | return cClient.GetDevicePort(subCtx, portFilter) |
| 2920 | } |
| 2921 | |
| 2922 | /* |
| 2923 | Helper functions to communicate with child adapter |
| 2924 | */ |
| 2925 | |
| 2926 | func (dh *DeviceHandler) sendOmciIndicationToChildAdapter(ctx context.Context, childEndpoint string, response *ic.OmciMessage) error { |
| 2927 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 2928 | if err != nil || aClient == nil { |
| 2929 | return err |
| 2930 | } |
| 2931 | logger.Debugw(ctx, "sending-omci-response", log.Fields{"response": response, "child-endpoint": childEndpoint}) |
| 2932 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2933 | defer cancel() |
| 2934 | _, err = aClient.OmciIndication(subCtx, response) |
| 2935 | return err |
| 2936 | } |
| 2937 | |
| 2938 | func (dh *DeviceHandler) sendOnuIndicationToChildAdapter(ctx context.Context, childEndpoint string, onuInd *ic.OnuIndicationMessage) error { |
| 2939 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 2940 | if err != nil || aClient == nil { |
| 2941 | return err |
| 2942 | } |
| 2943 | logger.Debugw(ctx, "sending-onu-indication", log.Fields{"onu-indication": onuInd, "child-endpoint": childEndpoint}) |
| 2944 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2945 | defer cancel() |
| 2946 | _, err = aClient.OnuIndication(subCtx, onuInd) |
| 2947 | return err |
| 2948 | } |
| 2949 | |
| 2950 | func (dh *DeviceHandler) sendDeleteTContToChildAdapter(ctx context.Context, childEndpoint string, tContInfo *ic.DeleteTcontMessage) error { |
| 2951 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 2952 | if err != nil || aClient == nil { |
| 2953 | return err |
| 2954 | } |
| 2955 | logger.Debugw(ctx, "sending-delete-tcont", log.Fields{"tcont": tContInfo, "child-endpoint": childEndpoint}) |
| 2956 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2957 | defer cancel() |
| 2958 | _, err = aClient.DeleteTCont(subCtx, tContInfo) |
| 2959 | return err |
| 2960 | } |
| 2961 | |
| 2962 | func (dh *DeviceHandler) sendDeleteGemPortToChildAdapter(ctx context.Context, childEndpoint string, gemPortInfo *ic.DeleteGemPortMessage) error { |
| 2963 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 2964 | if err != nil || aClient == nil { |
| 2965 | return err |
| 2966 | } |
| 2967 | logger.Debugw(ctx, "sending-delete-gem-port", log.Fields{"gem-port-info": gemPortInfo, "child-endpoint": childEndpoint}) |
| 2968 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2969 | defer cancel() |
| 2970 | _, err = aClient.DeleteGemPort(subCtx, gemPortInfo) |
| 2971 | return err |
| 2972 | } |
| 2973 | |
| 2974 | func (dh *DeviceHandler) sendDownloadTechProfileToChildAdapter(ctx context.Context, childEndpoint string, tpDownloadInfo *ic.TechProfileDownloadMessage) error { |
| 2975 | aClient, err := dh.getChildAdapterServiceClient(childEndpoint) |
| 2976 | if err != nil || aClient == nil { |
| 2977 | return err |
| 2978 | } |
| 2979 | logger.Debugw(ctx, "sending-tech-profile-download", log.Fields{"tp-download-info": tpDownloadInfo, "child-endpoint": childEndpoint}) |
| 2980 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.cfg.RPCTimeout) |
| 2981 | defer cancel() |
| 2982 | _, err = aClient.DownloadTechProfile(subCtx, tpDownloadInfo) |
| 2983 | return err |
| 2984 | } |
| 2985 | |
| 2986 | /* |
| 2987 | Helper functions for remote communication |
| 2988 | */ |
| 2989 | |
| 2990 | // TODO: Use a connection tracker such that the adapter connection is stopped when the last device that adapter |
| 2991 | // supports is deleted |
| 2992 | func (dh *DeviceHandler) setupChildInterAdapterClient(ctx context.Context, endpoint string) error { |
| 2993 | logger.Infow(ctx, "setting-child-adapter-connection", log.Fields{"child-endpoint": endpoint}) |
| 2994 | |
| 2995 | dh.lockChildAdapterClients.Lock() |
| 2996 | defer dh.lockChildAdapterClients.Unlock() |
| 2997 | if _, ok := dh.childAdapterClients[endpoint]; ok { |
| 2998 | // Already set |
| 2999 | return nil |
| 3000 | } |
| 3001 | |
| 3002 | // Setup child's adapter grpc connection |
| 3003 | var err error |
| 3004 | if dh.childAdapterClients[endpoint], err = vgrpc.NewClient(endpoint, |
| 3005 | dh.onuAdapterRestarted, |
| 3006 | vgrpc.ActivityCheck(true)); err != nil { |
| 3007 | logger.Errorw(ctx, "grpc-client-not-created", log.Fields{"error": err, "endpoint": endpoint}) |
| 3008 | return err |
| 3009 | } |
| 3010 | go dh.childAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), setAndTestAdapterServiceHandler) |
| 3011 | |
| 3012 | // Wait until we have a connection to the child adapter. |
| 3013 | // Unlimited retries or until context expires |
| 3014 | subCtx := log.WithSpanFromContext(context.TODO(), ctx) |
| 3015 | backoff := vgrpc.NewBackoff(dh.cfg.MinBackoffRetryDelay, dh.cfg.MaxBackoffRetryDelay, 0) |
| 3016 | for { |
| 3017 | client, err := dh.childAdapterClients[endpoint].GetOnuInterAdapterServiceClient() |
| 3018 | if err == nil && client != nil { |
| 3019 | logger.Infow(subCtx, "connected-to-child-adapter", log.Fields{"child-endpoint": endpoint}) |
| 3020 | break |
| 3021 | } |
| 3022 | logger.Warnw(subCtx, "connection-to-child-adapter-not-ready", log.Fields{"error": err, "child-endpoint": endpoint}) |
| 3023 | // Backoff |
| 3024 | if err = backoff.Backoff(subCtx); err != nil { |
| 3025 | logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "child-endpoint": endpoint}) |
| 3026 | break |
| 3027 | } |
| 3028 | } |
| 3029 | return nil |
| 3030 | } |
| 3031 | |
| 3032 | // func (dh *DeviceHandler) getChildAdapterServiceClient(endpoint string) (adapter_services.OnuInterAdapterServiceClient, error) { |
| 3033 | // dh.lockChildAdapterClients.RLock() |
| 3034 | // defer dh.lockChildAdapterClients.RUnlock() |
| 3035 | // if cgClient, ok := dh.childAdapterClients[endpoint]; ok { |
| 3036 | // return cgClient.GetOnuInterAdapterServiceClient() |
| 3037 | // } |
| 3038 | // return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint) |
| 3039 | // } |
| 3040 | |
| 3041 | func (dh *DeviceHandler) getChildAdapterServiceClient(endpoint string) (adapter_services.OnuInterAdapterServiceClient, error) { |
| 3042 | |
| 3043 | // First check from cache |
| 3044 | dh.lockChildAdapterClients.RLock() |
| 3045 | if cgClient, ok := dh.childAdapterClients[endpoint]; ok { |
| 3046 | dh.lockChildAdapterClients.RUnlock() |
| 3047 | return cgClient.GetOnuInterAdapterServiceClient() |
| 3048 | } |
| 3049 | dh.lockChildAdapterClients.RUnlock() |
| 3050 | |
| 3051 | // Set the child connection - can occur on restarts |
| 3052 | ctx, cancel := context.WithTimeout(context.Background(), dh.cfg.RPCTimeout) |
| 3053 | err := dh.setupChildInterAdapterClient(ctx, endpoint) |
| 3054 | cancel() |
| 3055 | if err != nil { |
| 3056 | return nil, err |
| 3057 | } |
| 3058 | |
| 3059 | // Get the child client now |
| 3060 | dh.lockChildAdapterClients.RLock() |
| 3061 | defer dh.lockChildAdapterClients.RUnlock() |
| 3062 | if cgClient, ok := dh.childAdapterClients[endpoint]; ok { |
| 3063 | return cgClient.GetOnuInterAdapterServiceClient() |
| 3064 | } |
| 3065 | return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint) |
| 3066 | } |
| 3067 | |
| 3068 | func (dh *DeviceHandler) deleteAdapterClients(ctx context.Context) { |
| 3069 | dh.lockChildAdapterClients.Lock() |
| 3070 | defer dh.lockChildAdapterClients.Unlock() |
| 3071 | for key, client := range dh.childAdapterClients { |
| 3072 | client.Stop(ctx) |
| 3073 | delete(dh.childAdapterClients, key) |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | // TODO: Any action the adapter needs to do following a onu adapter restart? |
| 3078 | func (dh *DeviceHandler) onuAdapterRestarted(ctx context.Context, endPoint string) error { |
| 3079 | logger.Warnw(ctx, "onu-adapter-restarted", log.Fields{"endpoint": endPoint}) |
| 3080 | return nil |
| 3081 | } |
| 3082 | |
| 3083 | // setAndTestAdapterServiceHandler is used to test whether the remote gRPC service is up |
| 3084 | func setAndTestAdapterServiceHandler(ctx context.Context, conn *grpc.ClientConn) interface{} { |
| 3085 | svc := adapter_services.NewOnuInterAdapterServiceClient(conn) |
| 3086 | if h, err := svc.GetHealthStatus(ctx, &empty.Empty{}); err != nil || h.State != voltha.HealthStatus_HEALTHY { |
| 3087 | return nil |
| 3088 | } |
| 3089 | return svc |
| 3090 | } |