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