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 | |
| 17 | //Package adaptercore provides the utility for olt devices, flows and statistics |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 18 | package adaptercore |
| 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 | "errors" |
| 24 | "fmt" |
| 25 | "io" |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 26 | "net" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 27 | "strconv" |
| 28 | "strings" |
| 29 | "sync" |
| 30 | "time" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 31 | |
Chaitrashree G S | b2b62dd | 2019-07-24 21:47:04 -0400 | [diff] [blame] | 32 | "google.golang.org/grpc/codes" |
| 33 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 34 | "github.com/gogo/protobuf/proto" |
| 35 | "github.com/golang/protobuf/ptypes" |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 36 | "github.com/opencord/voltha-go/adapters/adapterif" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 37 | "github.com/opencord/voltha-go/common/log" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 38 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 39 | "github.com/opencord/voltha-protos/go/common" |
| 40 | ic "github.com/opencord/voltha-protos/go/inter_container" |
| 41 | of "github.com/opencord/voltha-protos/go/openflow_13" |
| 42 | oop "github.com/opencord/voltha-protos/go/openolt" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 43 | "github.com/opencord/voltha-protos/go/voltha" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 44 | "google.golang.org/grpc" |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 45 | "google.golang.org/grpc/status" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 46 | ) |
| 47 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 48 | // Constants for number of retries and for timeout |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 49 | const ( |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 50 | MaxRetry = 10 |
| 51 | MaxTimeOutInMs = 500 |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 52 | ) |
| 53 | |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 54 | func init() { |
| 55 | _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 56 | } |
| 57 | |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 58 | //DeviceHandler will interact with the OLT device. |
| 59 | type DeviceHandler struct { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 60 | deviceID string |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 61 | deviceType string |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 62 | adminState string |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 63 | device *voltha.Device |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 64 | coreProxy adapterif.CoreProxy |
| 65 | AdapterProxy adapterif.AdapterProxy |
| 66 | EventProxy adapterif.EventProxy |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 67 | openOLT *OpenOLT |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 68 | exitChannel chan int |
| 69 | lockDevice sync.RWMutex |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 70 | Client oop.OpenoltClient |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 71 | transitionMap *TransitionMap |
| 72 | clientCon *grpc.ClientConn |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 73 | flowMgr *OpenOltFlowMgr |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 74 | eventMgr *OpenOltEventMgr |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 75 | resourceMgr *rsrcMgr.OpenOltResourceMgr |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 76 | discOnus map[string]bool |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 77 | onus map[string]*OnuDevice |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 78 | nniIntfID int |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 81 | //OnuDevice represents ONU related info |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 82 | type OnuDevice struct { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 83 | deviceID string |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 84 | deviceType string |
| 85 | serialNumber string |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 86 | onuID uint32 |
| 87 | intfID uint32 |
| 88 | proxyDeviceID string |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | //NewOnuDevice creates a new Onu Device |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 92 | func NewOnuDevice(devID, deviceTp, serialNum string, onuID, intfID uint32, proxyDevID string) *OnuDevice { |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 93 | var device OnuDevice |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 94 | device.deviceID = devID |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 95 | device.deviceType = deviceTp |
| 96 | device.serialNumber = serialNum |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 97 | device.onuID = onuID |
| 98 | device.intfID = intfID |
| 99 | device.proxyDeviceID = proxyDevID |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 100 | return &device |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | //NewDeviceHandler creates a new device handler |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 104 | 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] | 105 | var dh DeviceHandler |
| 106 | dh.coreProxy = cp |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 107 | dh.AdapterProxy = ap |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 108 | dh.EventProxy = ep |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 109 | cloned := (proto.Clone(device)).(*voltha.Device) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 110 | dh.deviceID = cloned.Id |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 111 | dh.deviceType = cloned.Type |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 112 | dh.adminState = "up" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 113 | dh.device = cloned |
| 114 | dh.openOLT = adapter |
| 115 | dh.exitChannel = make(chan int, 1) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 116 | dh.discOnus = make(map[string]bool) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 117 | dh.lockDevice = sync.RWMutex{} |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 118 | dh.onus = make(map[string]*OnuDevice) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 119 | // The nniIntfID is initialized to -1 (invalid) and set to right value |
Girish Gowdru | 1110ef2 | 2019-06-24 11:17:59 -0400 | [diff] [blame] | 120 | // when the first IntfOperInd with status as "up" is received for |
| 121 | // any one of the available NNI port on the OLT device. |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 122 | dh.nniIntfID = -1 |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 123 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 124 | //TODO initialize the support classes. |
| 125 | return &dh |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | // start save the device to the data model |
| 129 | func (dh *DeviceHandler) start(ctx context.Context) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 130 | dh.lockDevice.Lock() |
| 131 | defer dh.lockDevice.Unlock() |
| 132 | log.Debugw("starting-device-agent", log.Fields{"device": dh.device}) |
| 133 | // Add the initial device to the local model |
| 134 | log.Debug("device-agent-started") |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | // stop stops the device dh. Not much to do for now |
| 138 | func (dh *DeviceHandler) stop(ctx context.Context) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 139 | dh.lockDevice.Lock() |
| 140 | defer dh.lockDevice.Unlock() |
| 141 | log.Debug("stopping-device-agent") |
| 142 | dh.exitChannel <- 1 |
| 143 | log.Debug("device-agent-stopped") |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 144 | } |
| 145 | |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 146 | func macifyIP(ip net.IP) string { |
| 147 | if len(ip) > 0 { |
| 148 | oct1 := strconv.FormatInt(int64(ip[12]), 16) |
| 149 | oct2 := strconv.FormatInt(int64(ip[13]), 16) |
| 150 | oct3 := strconv.FormatInt(int64(ip[14]), 16) |
| 151 | oct4 := strconv.FormatInt(int64(ip[15]), 16) |
| 152 | return fmt.Sprintf("00:00:%02v:%02v:%02v:%02v", oct1, oct2, oct3, oct4) |
| 153 | } |
| 154 | return "" |
| 155 | } |
| 156 | |
| 157 | func generateMacFromHost(host string) (string, error) { |
| 158 | var genmac string |
| 159 | var addr net.IP |
| 160 | var ips []string |
| 161 | var err error |
| 162 | |
| 163 | log.Debugw("generating-mac-from-host", log.Fields{"host": host}) |
| 164 | |
| 165 | if addr = net.ParseIP(host); addr == nil { |
| 166 | log.Debugw("looking-up-hostname", log.Fields{"host": host}) |
| 167 | |
| 168 | if ips, err = net.LookupHost(host); err == nil { |
| 169 | log.Debugw("dns-result-ips", log.Fields{"ips": ips}) |
| 170 | if addr = net.ParseIP(ips[0]); addr == nil { |
| 171 | log.Errorw("unable-to-parse-ip", log.Fields{"ip": ips[0]}) |
| 172 | return "", errors.New("unable-to-parse-ip") |
| 173 | } |
| 174 | genmac = macifyIP(addr) |
| 175 | log.Debugw("using-ip-as-mac", log.Fields{"host": ips[0], "mac": genmac}) |
| 176 | return genmac, nil |
| 177 | } |
| 178 | log.Errorw("cannot-resolve-hostname-to-ip", log.Fields{"host": host}) |
| 179 | return "", err |
| 180 | } |
| 181 | |
| 182 | genmac = macifyIP(addr) |
| 183 | log.Debugw("using-ip-as-mac", log.Fields{"host": host, "mac": genmac}) |
| 184 | return genmac, nil |
| 185 | } |
| 186 | |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 187 | func macAddressToUint32Array(mac string) []uint32 { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 188 | slist := strings.Split(mac, ":") |
| 189 | result := make([]uint32, len(slist)) |
| 190 | var err error |
| 191 | var tmp int64 |
| 192 | for index, val := range slist { |
| 193 | if tmp, err = strconv.ParseInt(val, 16, 32); err != nil { |
| 194 | return []uint32{1, 2, 3, 4, 5, 6} |
| 195 | } |
| 196 | result[index] = uint32(tmp) |
| 197 | } |
| 198 | return result |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 199 | } |
| 200 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 201 | //GetportLabel returns the label for the NNI and the PON port based on port number and port type |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 202 | func GetportLabel(portNum uint32, portType voltha.Port_PortType) string { |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 203 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 204 | if portType == voltha.Port_ETHERNET_NNI { |
| 205 | return fmt.Sprintf("nni-%d", portNum) |
| 206 | } else if portType == voltha.Port_PON_OLT { |
| 207 | return fmt.Sprintf("pon-%d", portNum) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 208 | } else if portType == voltha.Port_ETHERNET_UNI { |
| 209 | log.Errorw("local UNI management not supported", log.Fields{}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 210 | return "" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 211 | } |
| 212 | return "" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 213 | } |
| 214 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 215 | func (dh *DeviceHandler) addPort(intfID uint32, portType voltha.Port_PortType, state string) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 216 | var operStatus common.OperStatus_OperStatus |
| 217 | if state == "up" { |
| 218 | operStatus = voltha.OperStatus_ACTIVE |
| 219 | } else { |
| 220 | operStatus = voltha.OperStatus_DISCOVERED |
| 221 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 222 | portNum := IntfIDToPortNo(intfID, portType) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 223 | label := GetportLabel(portNum, portType) |
| 224 | if len(label) == 0 { |
| 225 | log.Errorw("Invalid-port-label", log.Fields{"portNum": portNum, "portType": portType}) |
| 226 | return |
| 227 | } |
| 228 | // Now create Port |
| 229 | port := &voltha.Port{ |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 230 | PortNo: portNum, |
| 231 | Label: label, |
| 232 | Type: portType, |
| 233 | OperStatus: operStatus, |
| 234 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 235 | log.Debugw("Sending port update to core", log.Fields{"port": port}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 236 | // 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] | 237 | if err := dh.coreProxy.PortCreated(context.TODO(), dh.device.Id, port); err != nil { |
| 238 | log.Errorw("error-creating-nni-port", log.Fields{"deviceID": dh.device.Id, "portType": portType, "error": err}) |
Girish Gowdru | 1110ef2 | 2019-06-24 11:17:59 -0400 | [diff] [blame] | 239 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 240 | |
Girish Gowdru | 1110ef2 | 2019-06-24 11:17:59 -0400 | [diff] [blame] | 241 | // Once we have successfully added the NNI port to the core, if the |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 242 | // locally cached nniIntfID is set to invalid (-1), set it to the right value. |
| 243 | if portType == voltha.Port_ETHERNET_NNI && dh.nniIntfID == -1 { |
| 244 | dh.nniIntfID = int(intfID) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 245 | } |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | // readIndications to read the indications from the OLT device |
| 249 | func (dh *DeviceHandler) readIndications() { |
William Kurkian | ff52466 | 2019-08-20 10:34:30 -0400 | [diff] [blame] | 250 | defer log.Errorw("Indications ended", log.Fields{}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 251 | indications, err := dh.Client.EnableIndication(context.Background(), new(oop.Empty)) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 252 | if err != nil { |
| 253 | log.Errorw("Failed to read indications", log.Fields{"err": err}) |
| 254 | return |
| 255 | } |
| 256 | if indications == nil { |
| 257 | log.Errorw("Indications is nil", log.Fields{}) |
| 258 | return |
| 259 | } |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 260 | /* get device state */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 261 | device, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, dh.device.Id) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 262 | if err != nil || device == nil { |
| 263 | /*TODO: needs to handle error scenarios */ |
| 264 | log.Errorw("Failed to fetch device info", log.Fields{"err": err}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 265 | return |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 266 | } |
| 267 | // When the device is in DISABLED and Adapter container restarts, we need to |
| 268 | // rebuild the locally maintained admin state. |
| 269 | if device.AdminState == voltha.AdminState_DISABLED { |
| 270 | dh.lockDevice.Lock() |
| 271 | dh.adminState = "down" |
| 272 | dh.lockDevice.Unlock() |
| 273 | } |
| 274 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 275 | for { |
| 276 | indication, err := indications.Recv() |
| 277 | if err == io.EOF { |
| 278 | break |
| 279 | } |
| 280 | if err != nil { |
| 281 | log.Infow("Failed to read from indications", log.Fields{"err": err}) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 282 | if dh.adminState == "deleted" { |
| 283 | log.Debug("Device deleted stoping the read indication thread") |
| 284 | break |
| 285 | } |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 286 | dh.transitionMap.Handle(DeviceDownInd) |
| 287 | dh.transitionMap.Handle(DeviceInit) |
| 288 | break |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 289 | } |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 290 | dh.lockDevice.RLock() |
| 291 | adminState := dh.adminState |
| 292 | dh.lockDevice.RUnlock() |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 293 | // When OLT is admin down, allow only NNI operation status change indications. |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 294 | if adminState == "down" { |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 295 | _, isIntfOperInd := indication.Data.(*oop.Indication_IntfOperInd) |
| 296 | if isIntfOperInd { |
| 297 | intfOperInd := indication.GetIntfOperInd() |
| 298 | if intfOperInd.GetType() == "nni" { |
| 299 | log.Infow("olt is admin down, allow nni ind", log.Fields{}) |
| 300 | } |
| 301 | } else { |
| 302 | log.Infow("olt is admin down, ignore indication", log.Fields{}) |
| 303 | continue |
| 304 | } |
| 305 | } |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 306 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 307 | dh.handleIndication(indication) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 308 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
| 312 | func (dh *DeviceHandler) handleOltIndication(oltIndication *oop.OltIndication) { |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 313 | raisedTs := time.Now().UnixNano() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 314 | if oltIndication.OperState == "up" { |
| 315 | dh.transitionMap.Handle(DeviceUpInd) |
| 316 | } else if oltIndication.OperState == "down" { |
| 317 | dh.transitionMap.Handle(DeviceDownInd) |
| 318 | } |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 319 | // Send or clear Alarm |
| 320 | dh.eventMgr.oltUpDownIndication(oltIndication, dh.deviceID, raisedTs) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | func (dh *DeviceHandler) handleIndication(indication *oop.Indication) { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 324 | raisedTs := time.Now().UnixNano() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 325 | switch indication.Data.(type) { |
| 326 | case *oop.Indication_OltInd: |
| 327 | dh.handleOltIndication(indication.GetOltInd()) |
| 328 | case *oop.Indication_IntfInd: |
| 329 | intfInd := indication.GetIntfInd() |
| 330 | go dh.addPort(intfInd.GetIntfId(), voltha.Port_PON_OLT, intfInd.GetOperState()) |
| 331 | log.Infow("Received interface indication ", log.Fields{"InterfaceInd": intfInd}) |
| 332 | case *oop.Indication_IntfOperInd: |
| 333 | intfOperInd := indication.GetIntfOperInd() |
| 334 | if intfOperInd.GetType() == "nni" { |
| 335 | go dh.addPort(intfOperInd.GetIntfId(), voltha.Port_ETHERNET_NNI, intfOperInd.GetOperState()) |
| 336 | } else if intfOperInd.GetType() == "pon" { |
| 337 | // TODO: Check what needs to be handled here for When PON PORT down, ONU will be down |
| 338 | // Handle pon port update |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 339 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 340 | log.Infow("Received interface oper indication ", log.Fields{"InterfaceOperInd": intfOperInd}) |
| 341 | case *oop.Indication_OnuDiscInd: |
| 342 | onuDiscInd := indication.GetOnuDiscInd() |
| 343 | log.Infow("Received Onu discovery indication ", log.Fields{"OnuDiscInd": onuDiscInd}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 344 | sn := dh.stringifySerialNumber(onuDiscInd.SerialNumber) |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 345 | go dh.onuDiscIndication(onuDiscInd, sn) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 346 | case *oop.Indication_OnuInd: |
| 347 | onuInd := indication.GetOnuInd() |
| 348 | log.Infow("Received Onu indication ", log.Fields{"OnuInd": onuInd}) |
| 349 | go dh.onuIndication(onuInd) |
| 350 | case *oop.Indication_OmciInd: |
| 351 | omciInd := indication.GetOmciInd() |
| 352 | log.Infow("Received Omci indication ", log.Fields{"OmciInd": omciInd}) |
William Kurkian | ff52466 | 2019-08-20 10:34:30 -0400 | [diff] [blame] | 353 | go dh.omciIndication(omciInd) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 354 | case *oop.Indication_PktInd: |
| 355 | pktInd := indication.GetPktInd() |
| 356 | log.Infow("Received pakcet indication ", log.Fields{"PktInd": pktInd}) |
| 357 | go dh.handlePacketIndication(pktInd) |
| 358 | case *oop.Indication_PortStats: |
| 359 | portStats := indication.GetPortStats() |
| 360 | log.Infow("Received port stats indication", log.Fields{"PortStats": portStats}) |
| 361 | case *oop.Indication_FlowStats: |
| 362 | flowStats := indication.GetFlowStats() |
| 363 | log.Infow("Received flow stats", log.Fields{"FlowStats": flowStats}) |
| 364 | case *oop.Indication_AlarmInd: |
| 365 | alarmInd := indication.GetAlarmInd() |
| 366 | log.Infow("Received alarm indication ", log.Fields{"AlarmInd": alarmInd}) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 367 | dh.eventMgr.ProcessEvents(alarmInd, dh.deviceID, raisedTs) |
| 368 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 369 | } |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | // doStateUp handle the olt up indication and update to voltha core |
| 373 | func (dh *DeviceHandler) doStateUp() error { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 374 | // Synchronous call to update device state - this method is run in its own go routine |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 375 | if err := dh.coreProxy.DeviceStateUpdate(context.Background(), dh.device.Id, voltha.ConnectStatus_REACHABLE, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 376 | voltha.OperStatus_ACTIVE); err != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 377 | log.Errorw("Failed to update device with OLT UP indication", log.Fields{"deviceID": dh.device.Id, "error": err}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 378 | return err |
| 379 | } |
| 380 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | // doStateDown handle the olt down indication |
| 384 | func (dh *DeviceHandler) doStateDown() error { |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 385 | dh.lockDevice.Lock() |
| 386 | defer dh.lockDevice.Unlock() |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 387 | log.Debug("do-state-down-start") |
| 388 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 389 | 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] | 390 | if err != nil || device == nil { |
| 391 | /*TODO: needs to handle error scenarios */ |
| 392 | log.Errorw("Failed to fetch device device", log.Fields{"err": err}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 393 | return errors.New("failed to fetch device device") |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | cloned := proto.Clone(device).(*voltha.Device) |
| 397 | // Update the all ports state on that device to disable |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 398 | if er := dh.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_UNKNOWN); er != nil { |
| 399 | log.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": er}) |
| 400 | return er |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | //Update the device oper state and connection status |
| 404 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 405 | cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE |
| 406 | dh.device = cloned |
| 407 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 408 | if er := dh.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil { |
| 409 | log.Errorw("error-updating-device-state", log.Fields{"deviceID": device.Id, "error": er}) |
| 410 | return er |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 411 | } |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 412 | |
| 413 | //get the child device for the parent device |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 414 | onuDevices, err := dh.coreProxy.GetChildDevices(context.TODO(), dh.device.Id) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 415 | if err != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 416 | log.Errorw("failed to get child devices information", log.Fields{"deviceID": dh.device.Id, "error": err}) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 417 | return err |
| 418 | } |
| 419 | for _, onuDevice := range onuDevices.Items { |
| 420 | |
| 421 | // Update onu state as down in onu adapter |
| 422 | onuInd := oop.OnuIndication{} |
| 423 | onuInd.OperState = "down" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 424 | er := dh.AdapterProxy.SendInterAdapterMessage(context.TODO(), &onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, |
| 425 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 426 | if er != nil { |
| 427 | log.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
| 428 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id}) |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 429 | //Do not return here and continue to process other ONUs |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 430 | } |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 431 | } |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 432 | /* Discovered ONUs entries need to be cleared , since after OLT |
| 433 | is up, it starts sending discovery indications again*/ |
| 434 | dh.discOnus = make(map[string]bool) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 435 | log.Debugw("do-state-down-end", log.Fields{"deviceID": device.Id}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 436 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | // doStateInit dial the grpc before going to init state |
| 440 | func (dh *DeviceHandler) doStateInit() error { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 441 | var err error |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 442 | dh.clientCon, err = grpc.Dial(dh.device.GetHostAndPort(), grpc.WithInsecure(), grpc.WithBlock()) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 443 | if err != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 444 | log.Errorw("Failed to dial device", log.Fields{"DeviceId": dh.deviceID, "HostAndPort": dh.device.GetHostAndPort(), "err": err}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 445 | return err |
| 446 | } |
| 447 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | // postInit create olt client instance to invoke RPC on the olt device |
| 451 | func (dh *DeviceHandler) postInit() error { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 452 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
| 453 | dh.transitionMap.Handle(GrpcConnected) |
| 454 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | // doStateConnected get the device info and update to voltha core |
| 458 | func (dh *DeviceHandler) doStateConnected() error { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 459 | log.Debug("OLT device has been connected") |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 460 | |
| 461 | // Case where OLT is disabled and then rebooted. |
| 462 | if dh.adminState == "down" { |
| 463 | log.Debugln("do-state-connected--device-admin-state-down") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 464 | device, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, dh.device.Id) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 465 | if err != nil || device == nil { |
| 466 | /*TODO: needs to handle error scenarios */ |
| 467 | log.Errorw("Failed to fetch device device", log.Fields{"err": err}) |
| 468 | } |
| 469 | |
| 470 | cloned := proto.Clone(device).(*voltha.Device) |
| 471 | cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE |
| 472 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 473 | dh.device = cloned |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 474 | if er := dh.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil { |
| 475 | log.Errorw("error-updating-device-state", log.Fields{"deviceID": dh.device.Id, "error": er}) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 476 | } |
| 477 | |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 478 | // Since the device was disabled before the OLT was rebooted, enforce the OLT to be Disabled after re-connection. |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 479 | _, err = dh.Client.DisableOlt(context.Background(), new(oop.Empty)) |
| 480 | if err != nil { |
| 481 | log.Errorw("Failed to disable olt ", log.Fields{"err": err}) |
| 482 | } |
| 483 | |
| 484 | // Start reading indications |
| 485 | go dh.readIndications() |
| 486 | return nil |
| 487 | } |
| 488 | |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 489 | deviceInfo, err := dh.populateDeviceInfo() |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 490 | if err != nil { |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 491 | log.Errorw("Unable to populate Device Info", log.Fields{"err": err}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 492 | return err |
| 493 | } |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 494 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 495 | 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] | 496 | if err != nil || device == nil { |
| 497 | /*TODO: needs to handle error scenarios */ |
| 498 | log.Errorw("Failed to fetch device device", log.Fields{"err": err}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 499 | return err |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 500 | } |
| 501 | cloned := proto.Clone(device).(*voltha.Device) |
| 502 | // Update the all ports (if available) on that device to ACTIVE. |
| 503 | // The ports do not normally exist, unless the device is coming back from a reboot |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 504 | if err := dh.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_ACTIVE); err != nil { |
| 505 | log.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": err}) |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 506 | return err |
| 507 | } |
| 508 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 509 | KVStoreHostPort := fmt.Sprintf("%s:%d", dh.openOLT.KVStoreHost, dh.openOLT.KVStorePort) |
| 510 | // Instantiate resource manager |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 511 | if dh.resourceMgr = rsrcMgr.NewResourceMgr(dh.deviceID, KVStoreHostPort, dh.openOLT.KVStoreType, dh.deviceType, deviceInfo); dh.resourceMgr == nil { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 512 | log.Error("Error while instantiating resource manager") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 513 | return errors.New("instantiating resource manager failed") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 514 | } |
| 515 | // Instantiate flow manager |
| 516 | if dh.flowMgr = NewFlowManager(dh, dh.resourceMgr); dh.flowMgr == nil { |
| 517 | log.Error("Error while instantiating flow manager") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 518 | return errors.New("instantiating flow manager failed") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 519 | } |
| 520 | /* TODO: Instantiate Alarm , stats , BW managers */ |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 521 | /* Instantiating Event Manager to handle Alarms and KPIs */ |
Devmalya Paul | 90ca301 | 2019-09-02 21:55:45 -0400 | [diff] [blame] | 522 | dh.eventMgr = NewEventMgr(dh.EventProxy, dh) |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 523 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 524 | // Start reading indications |
| 525 | go dh.readIndications() |
| 526 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 527 | } |
| 528 | |
Matt Jeanneret | f4fdcd7 | 2019-07-19 20:03:23 -0400 | [diff] [blame] | 529 | func (dh *DeviceHandler) populateDeviceInfo() (*oop.DeviceInfo, error) { |
| 530 | var err error |
| 531 | var deviceInfo *oop.DeviceInfo |
| 532 | |
| 533 | deviceInfo, err = dh.Client.GetDeviceInfo(context.Background(), new(oop.Empty)) |
| 534 | |
| 535 | if err != nil { |
| 536 | log.Errorw("Failed to fetch device info", log.Fields{"err": err}) |
| 537 | return nil, err |
| 538 | } |
| 539 | if deviceInfo == nil { |
| 540 | log.Errorw("Device info is nil", log.Fields{}) |
| 541 | return nil, errors.New("failed to get device info from OLT") |
| 542 | } |
| 543 | |
| 544 | log.Debugw("Fetched device info", log.Fields{"deviceInfo": deviceInfo}) |
| 545 | dh.device.Root = true |
| 546 | dh.device.Vendor = deviceInfo.Vendor |
| 547 | dh.device.Model = deviceInfo.Model |
| 548 | dh.device.SerialNumber = deviceInfo.DeviceSerialNumber |
| 549 | dh.device.HardwareVersion = deviceInfo.HardwareVersion |
| 550 | dh.device.FirmwareVersion = deviceInfo.FirmwareVersion |
| 551 | |
| 552 | if deviceInfo.DeviceId == "" { |
| 553 | log.Warnw("no-device-id-provided-using-host", log.Fields{"hostport": dh.device.GetHostAndPort()}) |
| 554 | host := strings.Split(dh.device.GetHostAndPort(), ":")[0] |
| 555 | genmac, err := generateMacFromHost(host) |
| 556 | if err != nil { |
| 557 | return nil, err |
| 558 | } |
| 559 | log.Debugw("using-host-for-mac-address", log.Fields{"host": host, "mac": genmac}) |
| 560 | dh.device.MacAddress = genmac |
| 561 | } else { |
| 562 | dh.device.MacAddress = deviceInfo.DeviceId |
| 563 | } |
| 564 | |
| 565 | // Synchronous call to update device - this method is run in its own go routine |
| 566 | if err := dh.coreProxy.DeviceUpdate(context.TODO(), dh.device); err != nil { |
| 567 | log.Errorw("error-updating-device", log.Fields{"deviceID": dh.device.Id, "error": err}) |
| 568 | return nil, err |
| 569 | } |
| 570 | |
| 571 | return deviceInfo, nil |
| 572 | } |
| 573 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 574 | //AdoptDevice adopts the OLT device |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 575 | func (dh *DeviceHandler) AdoptDevice(device *voltha.Device) { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 576 | dh.transitionMap = NewTransitionMap(dh) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 577 | log.Infow("Adopt_device", log.Fields{"deviceID": device.Id, "Address": device.GetHostAndPort()}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 578 | dh.transitionMap.Handle(DeviceInit) |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 579 | } |
| 580 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 581 | //GetOfpDeviceInfo Gets the Ofp information of the given device |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 582 | func (dh *DeviceHandler) GetOfpDeviceInfo(device *voltha.Device) (*ic.SwitchCapability, error) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 583 | return &ic.SwitchCapability{ |
| 584 | Desc: &of.OfpDesc{ |
Devmalya Paul | 70dd497 | 2019-06-10 15:19:17 +0530 | [diff] [blame] | 585 | MfrDesc: "VOLTHA Project", |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 586 | HwDesc: "open_pon", |
| 587 | SwDesc: "open_pon", |
| 588 | SerialNum: dh.device.SerialNumber, |
| 589 | }, |
| 590 | SwitchFeatures: &of.OfpSwitchFeatures{ |
| 591 | NBuffers: 256, |
| 592 | NTables: 2, |
| 593 | Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS | |
| 594 | of.OfpCapabilities_OFPC_TABLE_STATS | |
| 595 | of.OfpCapabilities_OFPC_PORT_STATS | |
| 596 | of.OfpCapabilities_OFPC_GROUP_STATS), |
| 597 | }, |
| 598 | }, nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 599 | } |
| 600 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 601 | //GetOfpPortInfo Get Ofp port information |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 602 | func (dh *DeviceHandler) GetOfpPortInfo(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 603 | capacity := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 604 | return &ic.PortCapability{ |
| 605 | Port: &voltha.LogicalPort{ |
| 606 | OfpPort: &of.OfpPort{ |
| 607 | HwAddr: macAddressToUint32Array(dh.device.MacAddress), |
| 608 | Config: 0, |
| 609 | State: uint32(of.OfpPortState_OFPPS_LIVE), |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 610 | Curr: capacity, |
| 611 | Advertised: capacity, |
| 612 | Peer: capacity, |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 613 | CurrSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD), |
| 614 | MaxSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD), |
| 615 | }, |
| 616 | DeviceId: dh.device.Id, |
| 617 | DevicePortNo: uint32(portNo), |
| 618 | }, |
| 619 | }, nil |
| 620 | } |
| 621 | |
William Kurkian | ff52466 | 2019-08-20 10:34:30 -0400 | [diff] [blame] | 622 | func (dh *DeviceHandler) omciIndication(omciInd *oop.OmciIndication) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 623 | log.Debugw("omci indication", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId}) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 624 | var deviceType string |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 625 | var deviceID string |
| 626 | var proxyDeviceID string |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 627 | |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 628 | onuKey := dh.formOnuKey(omciInd.IntfId, omciInd.OnuId) |
| 629 | if onuInCache, ok := dh.onus[onuKey]; !ok { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 630 | log.Debugw("omci indication for a device not in cache.", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId}) |
| 631 | ponPort := IntfIDToPortNo(omciInd.GetIntfId(), voltha.Port_PON_OLT) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 632 | kwargs := make(map[string]interface{}) |
| 633 | kwargs["onu_id"] = omciInd.OnuId |
| 634 | kwargs["parent_port_no"] = ponPort |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 635 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 636 | onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs) |
| 637 | if err != nil { |
William Kurkian | ff52466 | 2019-08-20 10:34:30 -0400 | [diff] [blame] | 638 | log.Errorw("onu not found", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId, "error": err}) |
| 639 | return |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 640 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 641 | deviceType = onuDevice.Type |
| 642 | deviceID = onuDevice.Id |
| 643 | proxyDeviceID = onuDevice.ProxyAddress.DeviceId |
| 644 | //if not exist in cache, then add to cache. |
| 645 | dh.onus[onuKey] = NewOnuDevice(deviceID, deviceType, onuDevice.SerialNumber, omciInd.OnuId, omciInd.IntfId, proxyDeviceID) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 646 | } else { |
| 647 | //found in cache |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 648 | log.Debugw("omci indication for a device in cache.", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId}) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 649 | deviceType = onuInCache.deviceType |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 650 | deviceID = onuInCache.deviceID |
| 651 | proxyDeviceID = onuInCache.proxyDeviceID |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 652 | } |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 653 | |
| 654 | omciMsg := &ic.InterAdapterOmciMessage{Message: omciInd.Pkt} |
| 655 | if sendErr := dh.AdapterProxy.SendInterAdapterMessage(context.Background(), omciMsg, |
| 656 | ic.InterAdapterMessageType_OMCI_REQUEST, dh.deviceType, deviceType, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 657 | deviceID, proxyDeviceID, ""); sendErr != nil { |
William Kurkian | ff52466 | 2019-08-20 10:34:30 -0400 | [diff] [blame] | 658 | log.Errorw("send omci request error", log.Fields{"fromAdapter": dh.deviceType, "toAdapter": deviceType, "onuID": deviceID, "proxyDeviceID": proxyDeviceID, "error": sendErr}) |
| 659 | return |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 660 | } |
William Kurkian | ff52466 | 2019-08-20 10:34:30 -0400 | [diff] [blame] | 661 | return |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 662 | } |
| 663 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 664 | //ProcessInterAdapterMessage sends the proxied messages to the target device |
| 665 | // If the proxy address is not found in the unmarshalled message, it first fetches the onu device for which the message |
| 666 | // is meant, and then send the unmarshalled omci message to this onu |
| 667 | func (dh *DeviceHandler) ProcessInterAdapterMessage(msg *ic.InterAdapterMessage) error { |
| 668 | log.Debugw("Process_inter_adapter_message", log.Fields{"msgID": msg.Header.Id}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 669 | if msg.Header.Type == ic.InterAdapterMessageType_OMCI_REQUEST { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 670 | msgID := msg.Header.Id |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 671 | fromTopic := msg.Header.FromTopic |
| 672 | toTopic := msg.Header.ToTopic |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 673 | toDeviceID := msg.Header.ToDeviceId |
| 674 | proxyDeviceID := msg.Header.ProxyDeviceId |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 675 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 676 | 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] | 677 | |
| 678 | msgBody := msg.GetBody() |
| 679 | |
| 680 | omciMsg := &ic.InterAdapterOmciMessage{} |
| 681 | if err := ptypes.UnmarshalAny(msgBody, omciMsg); err != nil { |
| 682 | log.Warnw("cannot-unmarshal-omci-msg-body", log.Fields{"error": err}) |
| 683 | return err |
| 684 | } |
| 685 | |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 686 | if omciMsg.GetProxyAddress() == nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 687 | onuDevice, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, toDeviceID) |
| 688 | if err != nil { |
| 689 | log.Errorw("onu not found", log.Fields{"onuDeviceId": toDeviceID, "error": err}) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 690 | return err |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 691 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 692 | log.Debugw("device retrieved from core", log.Fields{"msgID": msgID, "fromTopic": fromTopic, "toTopic": toTopic, "toDeviceID": toDeviceID, "proxyDeviceID": proxyDeviceID}) |
| 693 | dh.sendProxiedMessage(onuDevice, omciMsg) |
| 694 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 695 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 696 | log.Debugw("Proxy Address found in omci message", log.Fields{"msgID": msgID, "fromTopic": fromTopic, "toTopic": toTopic, "toDeviceID": toDeviceID, "proxyDeviceID": proxyDeviceID}) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 697 | dh.sendProxiedMessage(nil, omciMsg) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | } else { |
| 701 | log.Errorw("inter-adapter-unhandled-type", log.Fields{"msgType": msg.Header.Type}) |
| 702 | } |
| 703 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 704 | } |
| 705 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 706 | func (dh *DeviceHandler) sendProxiedMessage(onuDevice *voltha.Device, omciMsg *ic.InterAdapterOmciMessage) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 707 | var intfID uint32 |
| 708 | var onuID uint32 |
| 709 | var connectStatus common.ConnectStatus_ConnectStatus |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 710 | if onuDevice != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 711 | intfID = onuDevice.ProxyAddress.GetChannelId() |
| 712 | onuID = onuDevice.ProxyAddress.GetOnuId() |
| 713 | connectStatus = onuDevice.ConnectStatus |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 714 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 715 | intfID = omciMsg.GetProxyAddress().GetChannelId() |
| 716 | onuID = omciMsg.GetProxyAddress().GetOnuId() |
| 717 | connectStatus = omciMsg.GetConnectStatus() |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 718 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 719 | if connectStatus != voltha.ConnectStatus_REACHABLE { |
| 720 | log.Debugw("ONU is not reachable, cannot send OMCI", log.Fields{"intfID": intfID, "onuID": onuID}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 721 | return |
| 722 | } |
| 723 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 724 | omciMessage := &oop.OmciMsg{IntfId: intfID, OnuId: onuID, Pkt: omciMsg.Message} |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 725 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 726 | _, err := dh.Client.OmciMsgOut(context.Background(), omciMessage) |
| 727 | if err != nil { |
| 728 | log.Errorw("unable to send omci-msg-out", log.Fields{"IntfID": intfID, "OnuID": onuID, "Msg": omciMessage}) |
| 729 | return |
| 730 | } |
| 731 | log.Debugw("omci-message-sent", log.Fields{"intfID": intfID, "onuID": onuID, "omciMsg": string(omciMsg.GetMessage())}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 734 | func (dh *DeviceHandler) activateONU(intfID uint32, onuID int64, serialNum *oop.SerialNumber, serialNumber string) { |
| 735 | log.Debugw("activate-onu", log.Fields{"intfID": intfID, "onuID": onuID, "serialNum": serialNum, "serialNumber": serialNumber}) |
| 736 | dh.flowMgr.UpdateOnuInfo(intfID, uint32(onuID), serialNumber) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 737 | // TODO: need resource manager |
| 738 | var pir uint32 = 1000000 |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 739 | Onu := oop.Onu{IntfId: intfID, OnuId: uint32(onuID), SerialNumber: serialNum, Pir: pir} |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 740 | if _, err := dh.Client.ActivateOnu(context.Background(), &Onu); err != nil { |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 741 | st, _ := status.FromError(err) |
| 742 | if st.Code() == codes.AlreadyExists { |
| 743 | log.Debug("ONU activation is in progress", log.Fields{"SerialNumber": serialNumber}) |
| 744 | } else { |
| 745 | log.Errorw("activate-onu-failed", log.Fields{"Onu": Onu, "err ": err}) |
| 746 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 747 | } else { |
| 748 | log.Infow("activated-onu", log.Fields{"SerialNumber": serialNumber}) |
| 749 | } |
| 750 | } |
| 751 | |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 752 | func (dh *DeviceHandler) onuDiscIndication(onuDiscInd *oop.OnuDiscIndication, sn string) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 753 | channelID := onuDiscInd.GetIntfId() |
| 754 | parentPortNo := IntfIDToPortNo(onuDiscInd.GetIntfId(), voltha.Port_PON_OLT) |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 755 | |
| 756 | log.Debugw("new-discovery-indication", log.Fields{"sn": sn}) |
| 757 | dh.lockDevice.Lock() |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 758 | if _, ok := dh.discOnus[sn]; ok { |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 759 | dh.lockDevice.Unlock() |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 760 | log.Debugw("onu-sn-is-already-being-processed", log.Fields{"sn": sn}) |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 761 | return |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 764 | dh.discOnus[sn] = true |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 765 | log.Debugw("new-discovery-indications-list", log.Fields{"discOnus": dh.discOnus}) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 766 | dh.lockDevice.Unlock() |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 767 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 768 | kwargs := make(map[string]interface{}) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 769 | if sn != "" { |
| 770 | kwargs["serial_number"] = sn |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 771 | } else { |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 772 | log.Errorw("invalid onu serial number", log.Fields{"sn": sn}) |
| 773 | return |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs) |
| 777 | var onuID uint32 |
| 778 | if onuDevice == nil || err != nil { |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 779 | //This is the first time ONU discovered. Create an OnuID for it. |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 780 | ponintfid := onuDiscInd.GetIntfId() |
| 781 | dh.lockDevice.Lock() |
| 782 | onuID, err = dh.resourceMgr.GetONUID(ponintfid) |
| 783 | dh.lockDevice.Unlock() |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 784 | if err != nil { |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 785 | log.Errorw("failed to fetch onuID from resource manager", log.Fields{"pon-intf-id": ponintfid, "err": err}) |
| 786 | return |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 787 | } |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 788 | if onuDevice, err = dh.coreProxy.ChildDeviceDetected(context.TODO(), dh.device.Id, int(parentPortNo), |
Chaitrashree G S | ee824a2 | 2019-07-28 18:28:27 -0400 | [diff] [blame] | 789 | "", int(channelID), |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 790 | string(onuDiscInd.SerialNumber.GetVendorId()), sn, int64(onuID)); onuDevice == nil { |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 791 | log.Errorw("Create onu error", |
| 792 | log.Fields{"parent_id": dh.device.Id, "ponPort": onuDiscInd.GetIntfId(), |
| 793 | "onuID": onuID, "sn": sn, "error": err}) |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 794 | return |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 795 | } |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 796 | log.Debugw("onu-child-device-added", log.Fields{"onuDevice": onuDevice}) |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 797 | |
| 798 | } else { |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 799 | //ONU already discovered before. Use the same OnuID. |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 800 | onuID = onuDevice.ProxyAddress.OnuId |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 801 | } |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 802 | //Insert the ONU into cache to use in OnuIndication. |
| 803 | //TODO: Do we need to remove this from the cache on ONU change, or wait for overwritten on next discovery. |
Scott Baker | 7eb0a93 | 2019-07-26 10:33:22 -0700 | [diff] [blame] | 804 | log.Debugw("ONU discovery indication key create", log.Fields{"onuID": onuID, |
| 805 | "intfId": onuDiscInd.GetIntfId()}) |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 806 | onuKey := dh.formOnuKey(onuDiscInd.GetIntfId(), onuID) |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 807 | |
| 808 | dh.lockDevice.Lock() |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 809 | dh.onus[onuKey] = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuID, onuDiscInd.GetIntfId(), onuDevice.ProxyAddress.DeviceId) |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 810 | log.Debugw("new-onu-device-discovered", log.Fields{"onu": dh.onus[onuKey]}) |
| 811 | dh.lockDevice.Unlock() |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 812 | |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 813 | err = dh.coreProxy.DeviceStateUpdate(context.TODO(), onuDevice.Id, common.ConnectStatus_REACHABLE, common.OperStatus_DISCOVERED) |
| 814 | if err != nil { |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 815 | log.Errorw("failed to update device state", log.Fields{"DeviceID": onuDevice.Id, "err": err}) |
| 816 | return |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 817 | } |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 818 | log.Debugw("onu-discovered-reachable", log.Fields{"deviceId": onuDevice.Id}) |
| 819 | //TODO: We put this sleep here to prevent the race between state update and onuIndication |
| 820 | //In onuIndication the operStatus of device is checked. If it is still not updated in KV store |
| 821 | //then the initialisation fails. |
| 822 | time.Sleep(1 * time.Second) |
| 823 | dh.activateONU(onuDiscInd.IntfId, int64(onuID), onuDiscInd.SerialNumber, sn) |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 824 | return |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | func (dh *DeviceHandler) onuIndication(onuInd *oop.OnuIndication) { |
| 828 | serialNumber := dh.stringifySerialNumber(onuInd.SerialNumber) |
| 829 | |
| 830 | kwargs := make(map[string]interface{}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 831 | ponPort := IntfIDToPortNo(onuInd.GetIntfId(), voltha.Port_PON_OLT) |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 832 | var onuDevice *voltha.Device |
| 833 | foundInCache := false |
Scott Baker | 7eb0a93 | 2019-07-26 10:33:22 -0700 | [diff] [blame] | 834 | log.Debugw("ONU indication key create", log.Fields{"onuId": onuInd.OnuId, |
| 835 | "intfId": onuInd.GetIntfId()}) |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 836 | onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.OnuId) |
| 837 | if onuInCache, ok := dh.onus[onuKey]; ok { |
| 838 | //If ONU id is discovered before then use GetDevice to get onuDevice because it is cheaper. |
| 839 | foundInCache = true |
| 840 | onuDevice, _ = dh.coreProxy.GetDevice(nil, dh.device.Id, onuInCache.deviceID) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 841 | } else { |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 842 | //If ONU not found in adapter cache then we have to use GetChildDevice to get onuDevice |
| 843 | if serialNumber != "" { |
| 844 | kwargs["serial_number"] = serialNumber |
| 845 | } else { |
| 846 | kwargs["onu_id"] = onuInd.OnuId |
| 847 | kwargs["parent_port_no"] = ponPort |
| 848 | } |
| 849 | onuDevice, _ = dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 850 | } |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 851 | |
| 852 | if onuDevice != nil { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 853 | if onuDevice.ParentPortNo != ponPort { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 854 | //log.Warnw("ONU-is-on-a-different-intf-id-now", log.Fields{"previousIntfId": intfIDFromPortNo(onuDevice.ParentPortNo), "currentIntfId": onuInd.GetIntfId()}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 855 | log.Warnw("ONU-is-on-a-different-intf-id-now", log.Fields{"previousIntfId": onuDevice.ParentPortNo, "currentIntfId": ponPort}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | if onuDevice.ProxyAddress.OnuId != onuInd.OnuId { |
| 859 | log.Warnw("ONU-id-mismatch, can happen if both voltha and the olt rebooted", log.Fields{"expected_onu_id": onuDevice.ProxyAddress.OnuId, "received_onu_id": onuInd.OnuId}) |
| 860 | } |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 861 | if !foundInCache { |
| 862 | onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.GetOnuId()) |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 863 | dh.lockDevice.Lock() |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 864 | dh.onus[onuKey] = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuInd.GetOnuId(), onuInd.GetIntfId(), onuDevice.ProxyAddress.DeviceId) |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 865 | dh.lockDevice.Unlock() |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 866 | } |
Scott Baker | 7eb0a93 | 2019-07-26 10:33:22 -0700 | [diff] [blame] | 867 | dh.updateOnuStates(onuDevice, onuInd, foundInCache) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 868 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 869 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 870 | log.Errorw("onu not found", log.Fields{"intfID": onuInd.IntfId, "onuID": onuInd.OnuId}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 871 | return |
| 872 | } |
| 873 | |
| 874 | } |
| 875 | |
Scott Baker | 7eb0a93 | 2019-07-26 10:33:22 -0700 | [diff] [blame] | 876 | func (dh *DeviceHandler) updateOnuStates(onuDevice *voltha.Device, onuInd *oop.OnuIndication, foundInCache bool) { |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 877 | log.Debugw("onu-indication-for-state", 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] | 878 | dh.updateOnuAdminState(onuInd) |
| 879 | // operState |
| 880 | if onuInd.OperState == "down" { |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 881 | 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] | 882 | // TODO NEW CORE do not hardcode adapter name. Handler needs Adapter reference |
| 883 | err := dh.AdapterProxy.SendInterAdapterMessage(context.TODO(), onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, |
| 884 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 885 | if err != nil { |
| 886 | log.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
| 887 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id}) |
| 888 | } |
| 889 | } else if onuInd.OperState == "up" { |
Scott Baker | 7eb0a93 | 2019-07-26 10:33:22 -0700 | [diff] [blame] | 890 | // Ignore operstatus if device was found in cache |
| 891 | if !foundInCache && onuDevice.OperStatus != common.OperStatus_DISCOVERED { |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 892 | log.Warnw("ignore-onu-indication", log.Fields{"intfID": onuInd.IntfId, "onuID": onuInd.OnuId, "operStatus": onuDevice.OperStatus, "msgOperStatus": onuInd.OperState}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 893 | return |
| 894 | } |
Matt Jeanneret | 5353951 | 2019-07-20 14:47:02 -0400 | [diff] [blame] | 895 | log.Debugw("sending-interadapter-onu-indication", log.Fields{"onuIndication": onuInd, "DeviceId": onuDevice.Id, "operStatus": onuDevice.OperStatus, "adminStatus": onuDevice.AdminState}) |
| 896 | // TODO NEW CORE do not hardcode adapter name. Handler needs Adapter reference |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 897 | err := dh.AdapterProxy.SendInterAdapterMessage(context.TODO(), onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, |
| 898 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 899 | if err != nil { |
| 900 | log.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
| 901 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id}) |
| 902 | return |
| 903 | } |
| 904 | } else { |
| 905 | log.Warnw("Not-implemented-or-invalid-value-of-oper-state", log.Fields{"operState": onuInd.OperState}) |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | func (dh *DeviceHandler) updateOnuAdminState(onuInd *oop.OnuIndication) { |
| 910 | if onuInd.AdminState == "down" { |
| 911 | if onuInd.OperState != "down" { |
| 912 | log.Errorw("ONU-admin-state-down-and-oper-status-not-down", log.Fields{"operState": onuInd.OperState}) |
| 913 | // Forcing the oper state change code to execute |
| 914 | onuInd.OperState = "down" |
| 915 | } |
| 916 | // Port and logical port update is taken care of by oper state block |
| 917 | } else if onuInd.AdminState == "up" { |
| 918 | log.Debugln("received-onu-admin-state up") |
| 919 | } else { |
| 920 | log.Errorw("Invalid-or-not-implemented-admin-state", log.Fields{"received-admin-state": onuInd.AdminState}) |
| 921 | } |
| 922 | log.Debugln("admin-state-dealt-with") |
| 923 | } |
| 924 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 925 | func (dh *DeviceHandler) stringifySerialNumber(serialNum *oop.SerialNumber) string { |
| 926 | if serialNum != nil { |
| 927 | return string(serialNum.VendorId) + dh.stringifyVendorSpecific(serialNum.VendorSpecific) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 928 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 929 | return "" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | func (dh *DeviceHandler) stringifyVendorSpecific(vendorSpecific []byte) string { |
| 933 | tmp := fmt.Sprintf("%x", (uint32(vendorSpecific[0])>>4)&0x0f) + |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 934 | fmt.Sprintf("%x", uint32(vendorSpecific[0]&0x0f)) + |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 935 | fmt.Sprintf("%x", (uint32(vendorSpecific[1])>>4)&0x0f) + |
| 936 | fmt.Sprintf("%x", (uint32(vendorSpecific[1]))&0x0f) + |
| 937 | fmt.Sprintf("%x", (uint32(vendorSpecific[2])>>4)&0x0f) + |
| 938 | fmt.Sprintf("%x", (uint32(vendorSpecific[2]))&0x0f) + |
| 939 | fmt.Sprintf("%x", (uint32(vendorSpecific[3])>>4)&0x0f) + |
| 940 | fmt.Sprintf("%x", (uint32(vendorSpecific[3]))&0x0f) |
| 941 | return tmp |
| 942 | } |
| 943 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 944 | //UpdateFlowsBulk upates the bulk flow |
| 945 | func (dh *DeviceHandler) UpdateFlowsBulk() error { |
| 946 | return errors.New("unimplemented") |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 947 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 948 | |
| 949 | //GetChildDevice returns the child device for given parent port and onu id |
| 950 | func (dh *DeviceHandler) GetChildDevice(parentPort, onuID uint32) *voltha.Device { |
| 951 | log.Debugw("GetChildDevice", log.Fields{"pon port": parentPort, "onuID": onuID}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 952 | kwargs := make(map[string]interface{}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 953 | kwargs["onu_id"] = onuID |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 954 | kwargs["parent_port_no"] = parentPort |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 955 | onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 956 | if err != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 957 | log.Errorw("onu not found", log.Fields{"intfID": parentPort, "onuID": onuID}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 958 | return nil |
| 959 | } |
| 960 | log.Debugw("Successfully received child device from core", log.Fields{"child_device": *onuDevice}) |
| 961 | return onuDevice |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 962 | } |
| 963 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 964 | // SendPacketInToCore sends packet-in to core |
| 965 | // For this, it calls SendPacketIn of the core-proxy which uses a device specific topic to send the request. |
| 966 | // The adapter handling the device creates a device specific topic |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 967 | func (dh *DeviceHandler) SendPacketInToCore(logicalPort uint32, packetPayload []byte) { |
| 968 | log.Debugw("SendPacketInToCore", log.Fields{"port": logicalPort, "packetPayload": packetPayload}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 969 | if err := dh.coreProxy.SendPacketIn(context.TODO(), dh.device.Id, logicalPort, packetPayload); err != nil { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 970 | log.Errorw("Error sending packetin to core", log.Fields{"error": err}) |
| 971 | return |
| 972 | } |
| 973 | log.Debug("Sent packet-in to core successfully") |
| 974 | } |
| 975 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 976 | //UpdateFlowsIncrementally updates the device flow |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 977 | func (dh *DeviceHandler) UpdateFlowsIncrementally(device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { |
| 978 | log.Debugw("Received-incremental-flowupdate-in-device-handler", log.Fields{"deviceID": device.Id, "flows": flows, "groups": groups, "flowMetadata": flowMetadata}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 979 | if flows != nil { |
| 980 | for _, flow := range flows.ToAdd.Items { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 981 | log.Debug("Adding flow", log.Fields{"deviceId": device.Id, "flowToAdd": flow}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 982 | dh.flowMgr.AddFlow(flow, flowMetadata) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 983 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 984 | for _, flow := range flows.ToRemove.Items { |
| 985 | log.Debug("Removing flow", log.Fields{"deviceId": device.Id, "flowToRemove": flow}) |
| 986 | dh.flowMgr.RemoveFlow(flow) |
| 987 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 988 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 989 | if groups != nil && flows != nil { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 990 | for _, flow := range flows.ToRemove.Items { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 991 | log.Debug("Removing flow", log.Fields{"deviceID": device.Id, "flowToRemove": flow}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 992 | // dh.flowMgr.RemoveFlow(flow) |
| 993 | } |
| 994 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 995 | log.Debug("UpdateFlowsIncrementally done successfully") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 996 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 997 | } |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 998 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 999 | //DisableDevice disables the given device |
| 1000 | //It marks the following for the given device: |
| 1001 | //Device-Handler Admin-State : down |
| 1002 | //Device Port-State: UNKNOWN |
| 1003 | //Device Oper-State: UNKNOWN |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1004 | func (dh *DeviceHandler) DisableDevice(device *voltha.Device) error { |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 1005 | /* On device disable ,admin state update has to be done prior sending request to agent since |
| 1006 | the indication thread may processes invalid indications of ONU and OLT*/ |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1007 | dh.lockDevice.Lock() |
| 1008 | dh.adminState = "down" |
| 1009 | dh.lockDevice.Unlock() |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 1010 | if _, err := dh.Client.DisableOlt(context.Background(), new(oop.Empty)); err != nil { |
| 1011 | log.Errorw("Failed to disable olt ", log.Fields{"err": err}) |
| 1012 | dh.lockDevice.Lock() |
| 1013 | dh.adminState = "up" |
| 1014 | dh.lockDevice.Unlock() |
| 1015 | return err |
| 1016 | } |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1017 | log.Debug("olt-disabled") |
Chaitrashree G S | 4412419 | 2019-08-07 20:21:36 -0400 | [diff] [blame] | 1018 | dh.lockDevice.Lock() |
| 1019 | /* Discovered ONUs entries need to be cleared , since on device disable the child devices goes to |
| 1020 | UNREACHABLE state which needs to be configured again*/ |
| 1021 | dh.discOnus = make(map[string]bool) |
| 1022 | dh.lockDevice.Unlock() |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1023 | |
| 1024 | cloned := proto.Clone(device).(*voltha.Device) |
| 1025 | // Update the all ports state on that device to disable |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1026 | if err := dh.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_UNKNOWN); err != nil { |
| 1027 | log.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": err}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1028 | return err |
| 1029 | } |
| 1030 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1031 | log.Debugw("Disable_device-end", log.Fields{"deviceID": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1032 | return nil |
| 1033 | } |
| 1034 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1035 | //ReenableDevice re-enables the olt device after disable |
| 1036 | //It marks the following for the given device: |
| 1037 | //Device-Handler Admin-State : up |
| 1038 | //Device Port-State: ACTIVE |
| 1039 | //Device Oper-State: ACTIVE |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1040 | func (dh *DeviceHandler) ReenableDevice(device *voltha.Device) error { |
| 1041 | if _, err := dh.Client.ReenableOlt(context.Background(), new(oop.Empty)); err != nil { |
| 1042 | log.Errorw("Failed to reenable olt ", log.Fields{"err": err}) |
| 1043 | return err |
| 1044 | } |
| 1045 | |
| 1046 | dh.lockDevice.Lock() |
| 1047 | dh.adminState = "up" |
| 1048 | dh.lockDevice.Unlock() |
| 1049 | log.Debug("olt-reenabled") |
| 1050 | |
| 1051 | cloned := proto.Clone(device).(*voltha.Device) |
| 1052 | // Update the all ports state on that device to enable |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1053 | if err := dh.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_ACTIVE); err != nil { |
| 1054 | log.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": err}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1055 | return err |
| 1056 | } |
| 1057 | |
| 1058 | //Update the device oper status as ACTIVE |
| 1059 | cloned.OperStatus = voltha.OperStatus_ACTIVE |
| 1060 | dh.device = cloned |
| 1061 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1062 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil { |
| 1063 | log.Errorw("error-updating-device-state", log.Fields{"deviceID": device.Id, "error": err}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1064 | return err |
| 1065 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1066 | log.Debugw("ReEnableDevice-end", log.Fields{"deviceID": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 1067 | |
| 1068 | return nil |
| 1069 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1070 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1071 | func (dh *DeviceHandler) clearUNIData(onu *OnuDevice, uniPorts []*voltha.Port) error { |
| 1072 | var uniID uint32 |
| 1073 | var err error |
| 1074 | for _, port := range uniPorts { |
| 1075 | if port.Type == voltha.Port_ETHERNET_UNI { |
| 1076 | uniID = UniIDFromPortNum(port.PortNo) |
| 1077 | /* Delete tech-profile instance from the KV store */ |
| 1078 | if err = dh.flowMgr.DeleteTechProfileInstance(onu.intfID, onu.onuID, uniID, onu.serialNumber); err != nil { |
| 1079 | log.Debugw("Failed-to-remove-tech-profile-instance-for-onu", log.Fields{"onu-id": onu.onuID}) |
| 1080 | } |
| 1081 | log.Debugw("Deleted-tech-profile-instance-for-onu", log.Fields{"onu-id": onu.onuID}) |
| 1082 | flowIDs := dh.resourceMgr.GetCurrentFlowIDsForOnu(onu.intfID, onu.onuID, uniID) |
| 1083 | for _, flowID := range flowIDs { |
| 1084 | dh.resourceMgr.FreeFlowID(onu.intfID, int32(onu.onuID), int32(uniID), flowID) |
| 1085 | } |
| 1086 | dh.resourceMgr.FreePONResourcesForONU(onu.intfID, onu.onuID, uniID) |
| 1087 | if err = dh.resourceMgr.RemoveTechProfileIDForOnu(onu.intfID, onu.onuID, uniID); err != nil { |
| 1088 | log.Debugw("Failed-to-remove-tech-profile-id-for-onu", log.Fields{"onu-id": onu.onuID}) |
| 1089 | } |
| 1090 | log.Debugw("Removed-tech-profile-id-for-onu", log.Fields{"onu-id": onu.onuID}) |
| 1091 | if err = dh.resourceMgr.RemoveMeterIDForOnu("upstream", onu.intfID, onu.onuID, uniID); err != nil { |
| 1092 | log.Debugw("Failed-to-remove-meter-id-for-onu-upstream", log.Fields{"onu-id": onu.onuID}) |
| 1093 | } |
| 1094 | log.Debugw("Removed-meter-id-for-onu-upstream", log.Fields{"onu-id": onu.onuID}) |
| 1095 | if err = dh.resourceMgr.RemoveMeterIDForOnu("downstream", onu.intfID, onu.onuID, uniID); err != nil { |
| 1096 | log.Debugw("Failed-to-remove-meter-id-for-onu-downstream", log.Fields{"onu-id": onu.onuID}) |
| 1097 | } |
| 1098 | log.Debugw("Removed-meter-id-for-onu-downstream", log.Fields{"onu-id": onu.onuID}) |
| 1099 | } |
| 1100 | } |
| 1101 | return nil |
| 1102 | } |
| 1103 | |
| 1104 | func (dh *DeviceHandler) clearNNIData() error { |
| 1105 | nniUniID := -1 |
| 1106 | nniOnuID := -1 |
| 1107 | flowIDs := dh.resourceMgr.GetCurrentFlowIDsForOnu(uint32(dh.nniIntfID), uint32(nniOnuID), uint32(nniUniID)) |
| 1108 | log.Debugw("Current flow ids for nni", log.Fields{"flow-ids": flowIDs}) |
| 1109 | for _, flowID := range flowIDs { |
| 1110 | dh.resourceMgr.FreeFlowID(uint32(dh.nniIntfID), -1, -1, uint32(flowID)) |
| 1111 | } |
| 1112 | //Free the flow-ids for the NNI port |
| 1113 | dh.resourceMgr.FreePONResourcesForONU(uint32(dh.nniIntfID), uint32(nniOnuID), uint32(nniUniID)) |
| 1114 | /* Free ONU IDs for each pon port |
| 1115 | intfIDToONUIds is a map of intf-id: [onu-ids]*/ |
| 1116 | intfIDToONUIds := make(map[uint32][]uint32) |
| 1117 | for _, onu := range dh.onus { |
| 1118 | intfIDToONUIds[onu.intfID] = append(intfIDToONUIds[onu.intfID], onu.onuID) |
| 1119 | } |
| 1120 | for intfID, onuIds := range intfIDToONUIds { |
| 1121 | dh.resourceMgr.FreeonuID(intfID, onuIds) |
| 1122 | } |
| 1123 | return nil |
| 1124 | } |
| 1125 | |
| 1126 | // DeleteDevice deletes the device instance from openolt handler array. Also clears allocated resource manager resources. Also reboots the OLT hardware! |
| 1127 | func (dh *DeviceHandler) DeleteDevice(device *voltha.Device) error { |
| 1128 | log.Debug("Function entry delete device") |
| 1129 | dh.lockDevice.Lock() |
| 1130 | dh.adminState = "deleted" |
| 1131 | dh.lockDevice.Unlock() |
| 1132 | /* Clear the KV store data associated with the all the UNI ports |
| 1133 | This clears up flow data and also resource map data for various |
| 1134 | other pon resources like alloc_id and gemport_id |
| 1135 | */ |
| 1136 | for _, onu := range dh.onus { |
| 1137 | childDevice, err := dh.coreProxy.GetDevice(nil, dh.deviceID, onu.deviceID) |
| 1138 | if err != nil { |
| 1139 | log.Debug("Failed to get onu device") |
| 1140 | continue |
| 1141 | } |
| 1142 | uniPorts := childDevice.Ports |
| 1143 | log.Debugw("onu-uni-ports", log.Fields{"onu-ports": uniPorts}) |
| 1144 | if err := dh.clearUNIData(onu, uniPorts); err != nil { |
| 1145 | log.Debugw("Failed to clear data for onu", log.Fields{"onu-device": onu}) |
| 1146 | } |
| 1147 | } |
| 1148 | /* Clear the flows from KV store associated with NNI port. |
| 1149 | There are mostly trap rules from NNI port (like LLDP) |
| 1150 | */ |
| 1151 | if err := dh.clearNNIData(); err != nil { |
| 1152 | log.Debugw("Failed to clear data for NNI port", log.Fields{"device-id": dh.deviceID}) |
| 1153 | } |
| 1154 | /* Clear the resource pool for each PON port*/ |
| 1155 | if err := dh.resourceMgr.Delete(); err != nil { |
| 1156 | log.Debug("Failed-to-remove-device-from-Resource-mananger-KV-store") |
| 1157 | } |
| 1158 | /*Delete ONU map for the device*/ |
| 1159 | for onu := range dh.onus { |
| 1160 | delete(dh.onus, onu) |
| 1161 | } |
| 1162 | log.Debug("Removed-device-from-Resource-manager-KV-store") |
| 1163 | //Reset the state |
| 1164 | if _, err := dh.Client.Reboot(context.Background(), new(oop.Empty)); err != nil { |
| 1165 | log.Errorw("Failed-to-reboot-olt ", log.Fields{"err": err}) |
| 1166 | return err |
| 1167 | } |
| 1168 | cloned := proto.Clone(device).(*voltha.Device) |
| 1169 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 1170 | cloned.ConnectStatus = voltha.ConnectStatus_UNREACHABLE |
| 1171 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil { |
| 1172 | log.Errorw("error-updating-device-state", log.Fields{"deviceID": device.Id, "error": err}) |
| 1173 | return err |
| 1174 | } |
| 1175 | return nil |
| 1176 | } |
| 1177 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1178 | //RebootDevice reboots the given device |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1179 | func (dh *DeviceHandler) RebootDevice(device *voltha.Device) error { |
| 1180 | if _, err := dh.Client.Reboot(context.Background(), new(oop.Empty)); err != nil { |
| 1181 | log.Errorw("Failed to reboot olt ", log.Fields{"err": err}) |
| 1182 | return err |
| 1183 | } |
| 1184 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1185 | log.Debugw("rebooted-device-successfully", log.Fields{"deviceID": device.Id}) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 1186 | |
| 1187 | return nil |
| 1188 | } |
| 1189 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1190 | func (dh *DeviceHandler) handlePacketIndication(packetIn *oop.PacketIndication) { |
| 1191 | log.Debugw("Received packet-in", log.Fields{"packet-indication": *packetIn}) |
| 1192 | logicalPortNum, err := dh.flowMgr.GetLogicalPortFromPacketIn(packetIn) |
| 1193 | if err != nil { |
| 1194 | log.Errorw("Error getting logical port from packet-in", log.Fields{"error": err}) |
| 1195 | return |
| 1196 | } |
| 1197 | log.Debugw("sending packet-in to core", log.Fields{"logicalPortNum": logicalPortNum, "packet": *packetIn}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1198 | if err := dh.coreProxy.SendPacketIn(context.TODO(), dh.device.Id, logicalPortNum, packetIn.Pkt); err != nil { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1199 | log.Errorw("Error sending packet-in to core", log.Fields{"error": err}) |
| 1200 | return |
| 1201 | } |
| 1202 | log.Debug("Success sending packet-in to core!") |
| 1203 | } |
| 1204 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1205 | // PacketOut sends packet-out from VOLTHA to OLT on the egress port provided |
| 1206 | func (dh *DeviceHandler) PacketOut(egressPortNo int, packet *of.OfpPacketOut) error { |
Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 1207 | log.Debugw("incoming-packet-out", log.Fields{"deviceID": dh.deviceID, "egress_port_no": egressPortNo, |
| 1208 | "pkt-length": len(packet.Data), "packetData": hex.EncodeToString(packet.Data)}) |
| 1209 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1210 | egressPortType := IntfIDToPortTypeName(uint32(egressPortNo)) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1211 | if egressPortType == voltha.Port_ETHERNET_UNI { |
Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 1212 | outerEthType := (uint16(packet.Data[12]) << 8) | uint16(packet.Data[13]) |
| 1213 | innerEthType := (uint16(packet.Data[16]) << 8) | uint16(packet.Data[17]) |
| 1214 | if outerEthType == 0x88a8 || outerEthType == 0x8100 { |
| 1215 | if innerEthType == 0x8100 { |
| 1216 | // q-in-q 802.1ad or 802.1q double tagged packet. |
| 1217 | // slice out the outer tag. |
| 1218 | packet.Data = append(packet.Data[:12], packet.Data[16:]...) |
| 1219 | 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] | 1220 | } |
| 1221 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1222 | intfID := IntfIDFromUniPortNum(uint32(egressPortNo)) |
| 1223 | onuID := OnuIDFromPortNum(uint32(egressPortNo)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1224 | uniID := UniIDFromPortNum(uint32(egressPortNo)) |
| 1225 | |
| 1226 | gemPortID, err := dh.flowMgr.GetPacketOutGemPortID(intfID, onuID, uint32(egressPortNo)) |
| 1227 | if err != nil { |
| 1228 | // In this case the openolt agent will receive the gemPortID as 0. |
| 1229 | // The agent tries to retrieve the gemPortID in this case. |
| 1230 | // This may not always succeed at the agent and packetOut may fail. |
| 1231 | log.Error("failed-to-retrieve-gemport-id-for-packet-out") |
| 1232 | } |
| 1233 | |
| 1234 | 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] | 1235 | |
| 1236 | log.Debugw("sending-packet-to-onu", log.Fields{"egress_port_no": egressPortNo, "IntfId": intfID, "onuID": onuID, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1237 | "uniID": uniID, "gemPortID": gemPortID, "packet": hex.EncodeToString(packet.Data)}) |
Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 1238 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1239 | if _, err := dh.Client.OnuPacketOut(context.Background(), &onuPkt); err != nil { |
| 1240 | log.Errorw("Error while sending packet-out to ONU", log.Fields{"error": err}) |
| 1241 | return err |
| 1242 | } |
| 1243 | } else if egressPortType == voltha.Port_ETHERNET_NNI { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1244 | uplinkPkt := oop.UplinkPacket{IntfId: IntfIDFromNniPortNum(uint32(egressPortNo)), Pkt: packet.Data} |
Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 1245 | |
| 1246 | log.Debugw("sending-packet-to-nni", log.Fields{"uplink_pkt": uplinkPkt, "packet": hex.EncodeToString(packet.Data)}) |
| 1247 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1248 | if _, err := dh.Client.UplinkPacketOut(context.Background(), &uplinkPkt); err != nil { |
Matt Jeanneret | 1359c73 | 2019-08-01 21:40:02 -0400 | [diff] [blame] | 1249 | log.Errorw("Error while sending packet-out to NNI", log.Fields{"error": err}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1250 | return err |
| 1251 | } |
| 1252 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1253 | log.Warnw("Packet-out-to-this-interface-type-not-implemented", log.Fields{"egress_port_no": egressPortNo, "egressPortType": egressPortType}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1254 | } |
| 1255 | return nil |
| 1256 | } |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1257 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1258 | func (dh *DeviceHandler) formOnuKey(intfID, onuID uint32) string { |
| 1259 | return "" + strconv.Itoa(int(intfID)) + "." + strconv.Itoa(int(onuID)) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1260 | } |