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