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