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