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" |
| 22 | "errors" |
| 23 | "fmt" |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 24 | "google.golang.org/grpc/codes" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 25 | "io" |
| 26 | "strconv" |
| 27 | "strings" |
| 28 | "sync" |
| 29 | "time" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 30 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 31 | "github.com/gogo/protobuf/proto" |
| 32 | "github.com/golang/protobuf/ptypes" |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 33 | "github.com/mdlayher/ethernet" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 34 | com "github.com/opencord/voltha-go/adapters/common" |
| 35 | "github.com/opencord/voltha-go/common/log" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 36 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 37 | "github.com/opencord/voltha-protos/go/common" |
| 38 | ic "github.com/opencord/voltha-protos/go/inter_container" |
| 39 | of "github.com/opencord/voltha-protos/go/openflow_13" |
| 40 | oop "github.com/opencord/voltha-protos/go/openolt" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 41 | "github.com/opencord/voltha-protos/go/voltha" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 42 | "google.golang.org/grpc" |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 43 | "google.golang.org/grpc/status" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 44 | ) |
| 45 | |
| 46 | //DeviceHandler will interact with the OLT device. |
| 47 | type DeviceHandler struct { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 48 | deviceID string |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 49 | deviceType string |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 50 | adminState string |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 51 | device *voltha.Device |
| 52 | coreProxy *com.CoreProxy |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 53 | AdapterProxy *com.AdapterProxy |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 54 | openOLT *OpenOLT |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 55 | exitChannel chan int |
| 56 | lockDevice sync.RWMutex |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 57 | Client oop.OpenoltClient |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 58 | transitionMap *TransitionMap |
| 59 | clientCon *grpc.ClientConn |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 60 | flowMgr *OpenOltFlowMgr |
| 61 | resourceMgr *rsrcMgr.OpenOltResourceMgr |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 62 | discOnus map[string]bool |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 63 | onus map[string]*OnuDevice |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 64 | nniIntfID int |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 67 | //OnuDevice represents ONU related info |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 68 | type OnuDevice struct { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 69 | deviceID string |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 70 | deviceType string |
| 71 | serialNumber string |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 72 | onuID uint32 |
| 73 | intfID uint32 |
| 74 | proxyDeviceID string |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | //NewOnuDevice creates a new Onu Device |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 78 | func NewOnuDevice(devID, deviceTp, serialNum string, onuID, intfID uint32, proxyDevID string) *OnuDevice { |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 79 | var device OnuDevice |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 80 | device.deviceID = devID |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 81 | device.deviceType = deviceTp |
| 82 | device.serialNumber = serialNum |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 83 | device.onuID = onuID |
| 84 | device.intfID = intfID |
| 85 | device.proxyDeviceID = proxyDevID |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 86 | return &device |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | //NewDeviceHandler creates a new device handler |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 90 | func NewDeviceHandler(cp *com.CoreProxy, ap *com.AdapterProxy, device *voltha.Device, adapter *OpenOLT) *DeviceHandler { |
| 91 | var dh DeviceHandler |
| 92 | dh.coreProxy = cp |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 93 | dh.AdapterProxy = ap |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 94 | cloned := (proto.Clone(device)).(*voltha.Device) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 95 | dh.deviceID = cloned.Id |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 96 | dh.deviceType = cloned.Type |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 97 | dh.adminState = "up" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 98 | dh.device = cloned |
| 99 | dh.openOLT = adapter |
| 100 | dh.exitChannel = make(chan int, 1) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 101 | dh.discOnus = make(map[string]bool) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 102 | dh.lockDevice = sync.RWMutex{} |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 103 | dh.onus = make(map[string]*OnuDevice) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 104 | // The nniIntfID is initialized to -1 (invalid) and set to right value |
Girish Gowdru | 1110ef2 | 2019-06-24 11:17:59 -0400 | [diff] [blame] | 105 | // when the first IntfOperInd with status as "up" is received for |
| 106 | // any one of the available NNI port on the OLT device. |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 107 | dh.nniIntfID = -1 |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 108 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 109 | //TODO initialize the support classes. |
| 110 | return &dh |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | // start save the device to the data model |
| 114 | func (dh *DeviceHandler) start(ctx context.Context) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 115 | dh.lockDevice.Lock() |
| 116 | defer dh.lockDevice.Unlock() |
| 117 | log.Debugw("starting-device-agent", log.Fields{"device": dh.device}) |
| 118 | // Add the initial device to the local model |
| 119 | log.Debug("device-agent-started") |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | // stop stops the device dh. Not much to do for now |
| 123 | func (dh *DeviceHandler) stop(ctx context.Context) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 124 | dh.lockDevice.Lock() |
| 125 | defer dh.lockDevice.Unlock() |
| 126 | log.Debug("stopping-device-agent") |
| 127 | dh.exitChannel <- 1 |
| 128 | log.Debug("device-agent-stopped") |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | func macAddressToUint32Array(mac string) []uint32 { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 132 | slist := strings.Split(mac, ":") |
| 133 | result := make([]uint32, len(slist)) |
| 134 | var err error |
| 135 | var tmp int64 |
| 136 | for index, val := range slist { |
| 137 | if tmp, err = strconv.ParseInt(val, 16, 32); err != nil { |
| 138 | return []uint32{1, 2, 3, 4, 5, 6} |
| 139 | } |
| 140 | result[index] = uint32(tmp) |
| 141 | } |
| 142 | return result |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 143 | } |
| 144 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 145 | //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] | 146 | func GetportLabel(portNum uint32, portType voltha.Port_PortType) string { |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 147 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 148 | if portType == voltha.Port_ETHERNET_NNI { |
| 149 | return fmt.Sprintf("nni-%d", portNum) |
| 150 | } else if portType == voltha.Port_PON_OLT { |
| 151 | return fmt.Sprintf("pon-%d", portNum) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 152 | } else if portType == voltha.Port_ETHERNET_UNI { |
| 153 | log.Errorw("local UNI management not supported", log.Fields{}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 154 | return "" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 155 | } |
| 156 | return "" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 157 | } |
| 158 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 159 | func (dh *DeviceHandler) addPort(intfID uint32, portType voltha.Port_PortType, state string) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 160 | var operStatus common.OperStatus_OperStatus |
| 161 | if state == "up" { |
| 162 | operStatus = voltha.OperStatus_ACTIVE |
| 163 | } else { |
| 164 | operStatus = voltha.OperStatus_DISCOVERED |
| 165 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 166 | portNum := IntfIDToPortNo(intfID, portType) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 167 | label := GetportLabel(portNum, portType) |
| 168 | if len(label) == 0 { |
| 169 | log.Errorw("Invalid-port-label", log.Fields{"portNum": portNum, "portType": portType}) |
| 170 | return |
| 171 | } |
| 172 | // Now create Port |
| 173 | port := &voltha.Port{ |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 174 | PortNo: portNum, |
| 175 | Label: label, |
| 176 | Type: portType, |
| 177 | OperStatus: operStatus, |
| 178 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 179 | log.Debugw("Sending port update to core", log.Fields{"port": port}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 180 | // 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] | 181 | if err := dh.coreProxy.PortCreated(context.TODO(), dh.device.Id, port); err != nil { |
| 182 | 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] | 183 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 184 | |
Girish Gowdru | 1110ef2 | 2019-06-24 11:17:59 -0400 | [diff] [blame] | 185 | // 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] | 186 | // locally cached nniIntfID is set to invalid (-1), set it to the right value. |
| 187 | if portType == voltha.Port_ETHERNET_NNI && dh.nniIntfID == -1 { |
| 188 | dh.nniIntfID = int(intfID) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 189 | } |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | // readIndications to read the indications from the OLT device |
| 193 | func (dh *DeviceHandler) readIndications() { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 194 | indications, err := dh.Client.EnableIndication(context.Background(), new(oop.Empty)) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 195 | if err != nil { |
| 196 | log.Errorw("Failed to read indications", log.Fields{"err": err}) |
| 197 | return |
| 198 | } |
| 199 | if indications == nil { |
| 200 | log.Errorw("Indications is nil", log.Fields{}) |
| 201 | return |
| 202 | } |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 203 | /* get device state */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 204 | 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] | 205 | if err != nil || device == nil { |
| 206 | /*TODO: needs to handle error scenarios */ |
| 207 | log.Errorw("Failed to fetch device info", log.Fields{"err": err}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 208 | return |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 209 | } |
| 210 | // When the device is in DISABLED and Adapter container restarts, we need to |
| 211 | // rebuild the locally maintained admin state. |
| 212 | if device.AdminState == voltha.AdminState_DISABLED { |
| 213 | dh.lockDevice.Lock() |
| 214 | dh.adminState = "down" |
| 215 | dh.lockDevice.Unlock() |
| 216 | } |
| 217 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 218 | for { |
| 219 | indication, err := indications.Recv() |
| 220 | if err == io.EOF { |
| 221 | break |
| 222 | } |
| 223 | if err != nil { |
| 224 | log.Infow("Failed to read from indications", log.Fields{"err": err}) |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 225 | dh.transitionMap.Handle(DeviceDownInd) |
| 226 | dh.transitionMap.Handle(DeviceInit) |
| 227 | break |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 228 | } |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 229 | // When OLT is admin down, allow only NNI operation status change indications. |
| 230 | if dh.adminState == "down" { |
| 231 | _, isIntfOperInd := indication.Data.(*oop.Indication_IntfOperInd) |
| 232 | if isIntfOperInd { |
| 233 | intfOperInd := indication.GetIntfOperInd() |
| 234 | if intfOperInd.GetType() == "nni" { |
| 235 | log.Infow("olt is admin down, allow nni ind", log.Fields{}) |
| 236 | } |
| 237 | } else { |
| 238 | log.Infow("olt is admin down, ignore indication", log.Fields{}) |
| 239 | continue |
| 240 | } |
| 241 | } |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 242 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 243 | dh.handleIndication(indication) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 244 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
| 248 | func (dh *DeviceHandler) handleOltIndication(oltIndication *oop.OltIndication) { |
| 249 | if oltIndication.OperState == "up" { |
| 250 | dh.transitionMap.Handle(DeviceUpInd) |
| 251 | } else if oltIndication.OperState == "down" { |
| 252 | dh.transitionMap.Handle(DeviceDownInd) |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | func (dh *DeviceHandler) handleIndication(indication *oop.Indication) { |
| 257 | switch indication.Data.(type) { |
| 258 | case *oop.Indication_OltInd: |
| 259 | dh.handleOltIndication(indication.GetOltInd()) |
| 260 | case *oop.Indication_IntfInd: |
| 261 | intfInd := indication.GetIntfInd() |
| 262 | go dh.addPort(intfInd.GetIntfId(), voltha.Port_PON_OLT, intfInd.GetOperState()) |
| 263 | log.Infow("Received interface indication ", log.Fields{"InterfaceInd": intfInd}) |
| 264 | case *oop.Indication_IntfOperInd: |
| 265 | intfOperInd := indication.GetIntfOperInd() |
| 266 | if intfOperInd.GetType() == "nni" { |
| 267 | go dh.addPort(intfOperInd.GetIntfId(), voltha.Port_ETHERNET_NNI, intfOperInd.GetOperState()) |
| 268 | } else if intfOperInd.GetType() == "pon" { |
| 269 | // TODO: Check what needs to be handled here for When PON PORT down, ONU will be down |
| 270 | // Handle pon port update |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 271 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 272 | log.Infow("Received interface oper indication ", log.Fields{"InterfaceOperInd": intfOperInd}) |
| 273 | case *oop.Indication_OnuDiscInd: |
| 274 | onuDiscInd := indication.GetOnuDiscInd() |
| 275 | log.Infow("Received Onu discovery indication ", log.Fields{"OnuDiscInd": onuDiscInd}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 276 | sn := dh.stringifySerialNumber(onuDiscInd.SerialNumber) |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 277 | dh.onuDiscIndication(onuDiscInd, sn) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 278 | case *oop.Indication_OnuInd: |
| 279 | onuInd := indication.GetOnuInd() |
| 280 | log.Infow("Received Onu indication ", log.Fields{"OnuInd": onuInd}) |
| 281 | go dh.onuIndication(onuInd) |
| 282 | case *oop.Indication_OmciInd: |
| 283 | omciInd := indication.GetOmciInd() |
| 284 | log.Infow("Received Omci indication ", log.Fields{"OmciInd": omciInd}) |
| 285 | if err := dh.omciIndication(omciInd); err != nil { |
| 286 | log.Errorw("send-omci-indication-errr", log.Fields{"error": err, "omciInd": omciInd}) |
| 287 | } |
| 288 | case *oop.Indication_PktInd: |
| 289 | pktInd := indication.GetPktInd() |
| 290 | log.Infow("Received pakcet indication ", log.Fields{"PktInd": pktInd}) |
| 291 | go dh.handlePacketIndication(pktInd) |
| 292 | case *oop.Indication_PortStats: |
| 293 | portStats := indication.GetPortStats() |
| 294 | log.Infow("Received port stats indication", log.Fields{"PortStats": portStats}) |
| 295 | case *oop.Indication_FlowStats: |
| 296 | flowStats := indication.GetFlowStats() |
| 297 | log.Infow("Received flow stats", log.Fields{"FlowStats": flowStats}) |
| 298 | case *oop.Indication_AlarmInd: |
| 299 | alarmInd := indication.GetAlarmInd() |
| 300 | log.Infow("Received alarm indication ", log.Fields{"AlarmInd": alarmInd}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 301 | } |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | // doStateUp handle the olt up indication and update to voltha core |
| 305 | func (dh *DeviceHandler) doStateUp() error { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 306 | // 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] | 307 | 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] | 308 | voltha.OperStatus_ACTIVE); err != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 309 | 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] | 310 | return err |
| 311 | } |
| 312 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | // doStateDown handle the olt down indication |
| 316 | func (dh *DeviceHandler) doStateDown() error { |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 317 | log.Debug("do-state-down-start") |
| 318 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 319 | 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] | 320 | if err != nil || device == nil { |
| 321 | /*TODO: needs to handle error scenarios */ |
| 322 | log.Errorw("Failed to fetch device device", log.Fields{"err": err}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 323 | return errors.New("failed to fetch device device") |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | cloned := proto.Clone(device).(*voltha.Device) |
| 327 | // Update the all ports state on that device to disable |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 328 | if er := dh.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_UNKNOWN); er != nil { |
| 329 | log.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": er}) |
| 330 | return er |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | //Update the device oper state and connection status |
| 334 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 335 | cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE |
| 336 | dh.device = cloned |
| 337 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 338 | if er := dh.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil { |
| 339 | log.Errorw("error-updating-device-state", log.Fields{"deviceID": device.Id, "error": er}) |
| 340 | return er |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 341 | } |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 342 | |
| 343 | //get the child device for the parent device |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 344 | onuDevices, err := dh.coreProxy.GetChildDevices(context.TODO(), dh.device.Id) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 345 | if err != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 346 | 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] | 347 | return err |
| 348 | } |
| 349 | for _, onuDevice := range onuDevices.Items { |
| 350 | |
| 351 | // Update onu state as down in onu adapter |
| 352 | onuInd := oop.OnuIndication{} |
| 353 | onuInd.OperState = "down" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 354 | er := dh.AdapterProxy.SendInterAdapterMessage(context.TODO(), &onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, |
| 355 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 356 | if er != nil { |
| 357 | log.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
| 358 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id}) |
| 359 | return er |
| 360 | } |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 361 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 362 | log.Debugw("do-state-down-end", log.Fields{"deviceID": device.Id}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 363 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | // doStateInit dial the grpc before going to init state |
| 367 | func (dh *DeviceHandler) doStateInit() error { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 368 | var err error |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 369 | dh.clientCon, err = grpc.Dial(dh.device.GetHostAndPort(), grpc.WithInsecure(), grpc.WithBlock()) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 370 | if err != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 371 | 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] | 372 | return err |
| 373 | } |
| 374 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | // postInit create olt client instance to invoke RPC on the olt device |
| 378 | func (dh *DeviceHandler) postInit() error { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 379 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
| 380 | dh.transitionMap.Handle(GrpcConnected) |
| 381 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | // doStateConnected get the device info and update to voltha core |
| 385 | func (dh *DeviceHandler) doStateConnected() error { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 386 | log.Debug("OLT device has been connected") |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 387 | |
| 388 | // Case where OLT is disabled and then rebooted. |
| 389 | if dh.adminState == "down" { |
| 390 | log.Debugln("do-state-connected--device-admin-state-down") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 391 | 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] | 392 | if err != nil || device == nil { |
| 393 | /*TODO: needs to handle error scenarios */ |
| 394 | log.Errorw("Failed to fetch device device", log.Fields{"err": err}) |
| 395 | } |
| 396 | |
| 397 | cloned := proto.Clone(device).(*voltha.Device) |
| 398 | cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE |
| 399 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 400 | dh.device = cloned |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 401 | if er := dh.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil { |
| 402 | 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] | 403 | } |
| 404 | |
| 405 | // Since the device was disabled before the OLT was rebooted, enfore the OLT to be Disabled after re-connection. |
| 406 | _, err = dh.Client.DisableOlt(context.Background(), new(oop.Empty)) |
| 407 | if err != nil { |
| 408 | log.Errorw("Failed to disable olt ", log.Fields{"err": err}) |
| 409 | } |
| 410 | |
| 411 | // Start reading indications |
| 412 | go dh.readIndications() |
| 413 | return nil |
| 414 | } |
| 415 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 416 | deviceInfo, err := dh.Client.GetDeviceInfo(context.Background(), new(oop.Empty)) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 417 | if err != nil { |
| 418 | log.Errorw("Failed to fetch device info", log.Fields{"err": err}) |
| 419 | return err |
| 420 | } |
| 421 | if deviceInfo == nil { |
| 422 | log.Errorw("Device info is nil", log.Fields{}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 423 | return errors.New("failed to get device info from OLT") |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 424 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 425 | log.Debugw("Fetched device info", log.Fields{"deviceInfo": deviceInfo}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 426 | dh.device.Root = true |
| 427 | dh.device.Vendor = deviceInfo.Vendor |
| 428 | dh.device.Model = deviceInfo.Model |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 429 | dh.device.SerialNumber = deviceInfo.DeviceSerialNumber |
| 430 | dh.device.HardwareVersion = deviceInfo.HardwareVersion |
| 431 | dh.device.FirmwareVersion = deviceInfo.FirmwareVersion |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 432 | // FIXME: Remove Hardcodings |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 433 | dh.device.MacAddress = "0a:0b:0c:0d:0e:0f" |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 434 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 435 | // 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] | 436 | if er := dh.coreProxy.DeviceUpdate(context.TODO(), dh.device); er != nil { |
| 437 | log.Errorw("error-updating-device", log.Fields{"deviceID": dh.device.Id, "error": er}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 438 | } |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 439 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 440 | 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] | 441 | if err != nil || device == nil { |
| 442 | /*TODO: needs to handle error scenarios */ |
| 443 | log.Errorw("Failed to fetch device device", log.Fields{"err": err}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 444 | return err |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 445 | } |
| 446 | cloned := proto.Clone(device).(*voltha.Device) |
| 447 | // Update the all ports (if available) on that device to ACTIVE. |
| 448 | // 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] | 449 | if err := dh.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_ACTIVE); err != nil { |
| 450 | log.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": err}) |
Girish Gowdru | d424515 | 2019-05-10 00:47:31 -0400 | [diff] [blame] | 451 | return err |
| 452 | } |
| 453 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 454 | KVStoreHostPort := fmt.Sprintf("%s:%d", dh.openOLT.KVStoreHost, dh.openOLT.KVStorePort) |
| 455 | // Instantiate resource manager |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 456 | 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] | 457 | log.Error("Error while instantiating resource manager") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 458 | return errors.New("instantiating resource manager failed") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 459 | } |
| 460 | // Instantiate flow manager |
| 461 | if dh.flowMgr = NewFlowManager(dh, dh.resourceMgr); dh.flowMgr == nil { |
| 462 | log.Error("Error while instantiating flow manager") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 463 | return errors.New("instantiating flow manager failed") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 464 | } |
| 465 | /* TODO: Instantiate Alarm , stats , BW managers */ |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 466 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 467 | // Start reading indications |
| 468 | go dh.readIndications() |
| 469 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 470 | } |
| 471 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 472 | //AdoptDevice adopts the OLT device |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 473 | func (dh *DeviceHandler) AdoptDevice(device *voltha.Device) { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 474 | dh.transitionMap = NewTransitionMap(dh) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 475 | log.Infow("Adopt_device", log.Fields{"deviceID": device.Id, "Address": device.GetHostAndPort()}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 476 | dh.transitionMap.Handle(DeviceInit) |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 477 | } |
| 478 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 479 | //GetOfpDeviceInfo Gets the Ofp information of the given device |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 480 | func (dh *DeviceHandler) GetOfpDeviceInfo(device *voltha.Device) (*ic.SwitchCapability, error) { |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 481 | return &ic.SwitchCapability{ |
| 482 | Desc: &of.OfpDesc{ |
Devmalya Paul | 70dd497 | 2019-06-10 15:19:17 +0530 | [diff] [blame] | 483 | MfrDesc: "VOLTHA Project", |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 484 | HwDesc: "open_pon", |
| 485 | SwDesc: "open_pon", |
| 486 | SerialNum: dh.device.SerialNumber, |
| 487 | }, |
| 488 | SwitchFeatures: &of.OfpSwitchFeatures{ |
| 489 | NBuffers: 256, |
| 490 | NTables: 2, |
| 491 | Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS | |
| 492 | of.OfpCapabilities_OFPC_TABLE_STATS | |
| 493 | of.OfpCapabilities_OFPC_PORT_STATS | |
| 494 | of.OfpCapabilities_OFPC_GROUP_STATS), |
| 495 | }, |
| 496 | }, nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 497 | } |
| 498 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 499 | //GetOfpPortInfo Get Ofp port information |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 500 | func (dh *DeviceHandler) GetOfpPortInfo(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 501 | capacity := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 502 | return &ic.PortCapability{ |
| 503 | Port: &voltha.LogicalPort{ |
| 504 | OfpPort: &of.OfpPort{ |
| 505 | HwAddr: macAddressToUint32Array(dh.device.MacAddress), |
| 506 | Config: 0, |
| 507 | State: uint32(of.OfpPortState_OFPPS_LIVE), |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 508 | Curr: capacity, |
| 509 | Advertised: capacity, |
| 510 | Peer: capacity, |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 511 | CurrSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD), |
| 512 | MaxSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD), |
| 513 | }, |
| 514 | DeviceId: dh.device.Id, |
| 515 | DevicePortNo: uint32(portNo), |
| 516 | }, |
| 517 | }, nil |
| 518 | } |
| 519 | |
| 520 | func (dh *DeviceHandler) omciIndication(omciInd *oop.OmciIndication) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 521 | log.Debugw("omci indication", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId}) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 522 | var deviceType string |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 523 | var deviceID string |
| 524 | var proxyDeviceID string |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 525 | |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 526 | onuKey := dh.formOnuKey(omciInd.IntfId, omciInd.OnuId) |
| 527 | if onuInCache, ok := dh.onus[onuKey]; !ok { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 528 | log.Debugw("omci indication for a device not in cache.", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId}) |
| 529 | ponPort := IntfIDToPortNo(omciInd.GetIntfId(), voltha.Port_PON_OLT) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 530 | kwargs := make(map[string]interface{}) |
| 531 | kwargs["onu_id"] = omciInd.OnuId |
| 532 | kwargs["parent_port_no"] = ponPort |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 533 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 534 | onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs) |
| 535 | if err != nil { |
| 536 | log.Errorw("onu not found", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId}) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 537 | return err |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 538 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 539 | deviceType = onuDevice.Type |
| 540 | deviceID = onuDevice.Id |
| 541 | proxyDeviceID = onuDevice.ProxyAddress.DeviceId |
| 542 | //if not exist in cache, then add to cache. |
| 543 | 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] | 544 | } else { |
| 545 | //found in cache |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 546 | 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] | 547 | deviceType = onuInCache.deviceType |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 548 | deviceID = onuInCache.deviceID |
| 549 | proxyDeviceID = onuInCache.proxyDeviceID |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 550 | } |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 551 | |
| 552 | omciMsg := &ic.InterAdapterOmciMessage{Message: omciInd.Pkt} |
| 553 | if sendErr := dh.AdapterProxy.SendInterAdapterMessage(context.Background(), omciMsg, |
| 554 | ic.InterAdapterMessageType_OMCI_REQUEST, dh.deviceType, deviceType, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 555 | deviceID, proxyDeviceID, ""); sendErr != nil { |
| 556 | log.Errorw("send omci request error", log.Fields{"fromAdapter": dh.deviceType, "toAdapter": deviceType, "onuID": deviceID, "proxyDeviceID": proxyDeviceID}) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 557 | return sendErr |
| 558 | } |
| 559 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 560 | } |
| 561 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 562 | //ProcessInterAdapterMessage sends the proxied messages to the target device |
| 563 | // If the proxy address is not found in the unmarshalled message, it first fetches the onu device for which the message |
| 564 | // is meant, and then send the unmarshalled omci message to this onu |
| 565 | func (dh *DeviceHandler) ProcessInterAdapterMessage(msg *ic.InterAdapterMessage) error { |
| 566 | log.Debugw("Process_inter_adapter_message", log.Fields{"msgID": msg.Header.Id}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 567 | if msg.Header.Type == ic.InterAdapterMessageType_OMCI_REQUEST { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 568 | msgID := msg.Header.Id |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 569 | fromTopic := msg.Header.FromTopic |
| 570 | toTopic := msg.Header.ToTopic |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 571 | toDeviceID := msg.Header.ToDeviceId |
| 572 | proxyDeviceID := msg.Header.ProxyDeviceId |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 573 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 574 | 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] | 575 | |
| 576 | msgBody := msg.GetBody() |
| 577 | |
| 578 | omciMsg := &ic.InterAdapterOmciMessage{} |
| 579 | if err := ptypes.UnmarshalAny(msgBody, omciMsg); err != nil { |
| 580 | log.Warnw("cannot-unmarshal-omci-msg-body", log.Fields{"error": err}) |
| 581 | return err |
| 582 | } |
| 583 | |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 584 | if omciMsg.GetProxyAddress() == nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 585 | onuDevice, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, toDeviceID) |
| 586 | if err != nil { |
| 587 | log.Errorw("onu not found", log.Fields{"onuDeviceId": toDeviceID, "error": err}) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 588 | return err |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 589 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 590 | log.Debugw("device retrieved from core", log.Fields{"msgID": msgID, "fromTopic": fromTopic, "toTopic": toTopic, "toDeviceID": toDeviceID, "proxyDeviceID": proxyDeviceID}) |
| 591 | dh.sendProxiedMessage(onuDevice, omciMsg) |
| 592 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 593 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 594 | 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] | 595 | dh.sendProxiedMessage(nil, omciMsg) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | } else { |
| 599 | log.Errorw("inter-adapter-unhandled-type", log.Fields{"msgType": msg.Header.Type}) |
| 600 | } |
| 601 | return nil |
Phaneendra Manda | 4c62c80 | 2019-03-06 21:37:49 +0530 | [diff] [blame] | 602 | } |
| 603 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 604 | func (dh *DeviceHandler) sendProxiedMessage(onuDevice *voltha.Device, omciMsg *ic.InterAdapterOmciMessage) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 605 | var intfID uint32 |
| 606 | var onuID uint32 |
| 607 | var connectStatus common.ConnectStatus_ConnectStatus |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 608 | if onuDevice != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 609 | intfID = onuDevice.ProxyAddress.GetChannelId() |
| 610 | onuID = onuDevice.ProxyAddress.GetOnuId() |
| 611 | connectStatus = onuDevice.ConnectStatus |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 612 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 613 | intfID = omciMsg.GetProxyAddress().GetChannelId() |
| 614 | onuID = omciMsg.GetProxyAddress().GetOnuId() |
| 615 | connectStatus = omciMsg.GetConnectStatus() |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 616 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 617 | if connectStatus != voltha.ConnectStatus_REACHABLE { |
| 618 | 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] | 619 | return |
| 620 | } |
| 621 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 622 | omciMessage := &oop.OmciMsg{IntfId: intfID, OnuId: onuID, Pkt: omciMsg.Message} |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 623 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 624 | _, err := dh.Client.OmciMsgOut(context.Background(), omciMessage) |
| 625 | if err != nil { |
| 626 | log.Errorw("unable to send omci-msg-out", log.Fields{"IntfID": intfID, "OnuID": onuID, "Msg": omciMessage}) |
| 627 | return |
| 628 | } |
| 629 | 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] | 630 | } |
| 631 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 632 | func (dh *DeviceHandler) activateONU(intfID uint32, onuID int64, serialNum *oop.SerialNumber, serialNumber string) { |
| 633 | log.Debugw("activate-onu", log.Fields{"intfID": intfID, "onuID": onuID, "serialNum": serialNum, "serialNumber": serialNumber}) |
| 634 | dh.flowMgr.UpdateOnuInfo(intfID, uint32(onuID), serialNumber) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 635 | // TODO: need resource manager |
| 636 | var pir uint32 = 1000000 |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 637 | Onu := oop.Onu{IntfId: intfID, OnuId: uint32(onuID), SerialNumber: serialNum, Pir: pir} |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 638 | if _, err := dh.Client.ActivateOnu(context.Background(), &Onu); err != nil { |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 639 | st, _ := status.FromError(err) |
| 640 | if st.Code() == codes.AlreadyExists { |
| 641 | log.Debug("ONU activation is in progress", log.Fields{"SerialNumber": serialNumber}) |
| 642 | } else { |
| 643 | log.Errorw("activate-onu-failed", log.Fields{"Onu": Onu, "err ": err}) |
| 644 | } |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 645 | } else { |
| 646 | log.Infow("activated-onu", log.Fields{"SerialNumber": serialNumber}) |
| 647 | } |
| 648 | } |
| 649 | |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 650 | func (dh *DeviceHandler) onuDiscIndication(onuDiscInd *oop.OnuDiscIndication, sn string) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 651 | channelID := onuDiscInd.GetIntfId() |
| 652 | parentPortNo := IntfIDToPortNo(onuDiscInd.GetIntfId(), voltha.Port_PON_OLT) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 653 | if _, ok := dh.discOnus[sn]; ok { |
| 654 | log.Debugw("onu-sn-is-already-being-processed", log.Fields{"sn": sn}) |
| 655 | return nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 658 | dh.lockDevice.Lock() |
| 659 | dh.discOnus[sn] = true |
| 660 | dh.lockDevice.Unlock() |
| 661 | // evict the onu serial number from local cache |
| 662 | defer func() { |
| 663 | delete(dh.discOnus, sn) |
| 664 | }() |
| 665 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 666 | kwargs := make(map[string]interface{}) |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 667 | if sn != "" { |
| 668 | kwargs["serial_number"] = sn |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 669 | } else { |
| 670 | log.Error("invalid onu serial number") |
| 671 | return errors.New("failed to fetch onu serial number") |
| 672 | } |
| 673 | |
| 674 | onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs) |
| 675 | var onuID uint32 |
| 676 | if onuDevice == nil || err != nil { |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 677 | //This is the first time ONU discovered. Create an OnuID for it. |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 678 | onuID, err = dh.resourceMgr.GetONUID(onuDiscInd.GetIntfId()) |
| 679 | if err != nil { |
| 680 | log.Errorw("failed to fetch onuID from resource manager", log.Fields{"err": err}) |
| 681 | return err |
| 682 | } |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 683 | if onuDevice, err = dh.coreProxy.ChildDeviceDetected(context.TODO(), dh.device.Id, int(parentPortNo), |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 684 | "brcm_openomci_onu", int(channelID), |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 685 | string(onuDiscInd.SerialNumber.GetVendorId()), sn, int64(onuID)); onuDevice == nil { |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 686 | log.Errorw("Create onu error", |
| 687 | log.Fields{"parent_id": dh.device.Id, "ponPort": onuDiscInd.GetIntfId(), |
| 688 | "onuID": onuID, "sn": sn, "error": err}) |
| 689 | return err |
| 690 | } |
| 691 | |
| 692 | } else { |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 693 | //ONU already discovered before. Use the same OnuID. |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 694 | onuID = onuDevice.ProxyAddress.OnuId |
Chaitrashree G S | be6ab94 | 2019-05-24 06:42:49 -0400 | [diff] [blame] | 695 | } |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 696 | //Insert the ONU into cache to use in OnuIndication. |
| 697 | //TODO: Do we need to remove this from the cache on ONU change, or wait for overwritten on next discovery. |
| 698 | onuKey := dh.formOnuKey(onuDiscInd.GetIntfId(), onuID) |
| 699 | dh.onus[onuKey] = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuID, onuDiscInd.GetIntfId(), onuDevice.ProxyAddress.DeviceId) |
Chaitrashree G S | 35b5d80 | 2019-07-08 23:12:03 -0400 | [diff] [blame] | 700 | |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 701 | err = dh.coreProxy.DeviceStateUpdate(context.TODO(), onuDevice.Id, common.ConnectStatus_REACHABLE, common.OperStatus_DISCOVERED) |
| 702 | if err != nil { |
| 703 | log.Errorw("failed to update device state", log.Fields{"DeviceID": onuDevice.Id}) |
| 704 | return err |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 705 | } |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 706 | log.Debugw("onu-discovered-reachable", log.Fields{"deviceId": onuDevice.Id}) |
| 707 | //TODO: We put this sleep here to prevent the race between state update and onuIndication |
| 708 | //In onuIndication the operStatus of device is checked. If it is still not updated in KV store |
| 709 | //then the initialisation fails. |
| 710 | time.Sleep(1 * time.Second) |
| 711 | dh.activateONU(onuDiscInd.IntfId, int64(onuID), onuDiscInd.SerialNumber, sn) |
| 712 | return nil |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | func (dh *DeviceHandler) onuIndication(onuInd *oop.OnuIndication) { |
| 716 | serialNumber := dh.stringifySerialNumber(onuInd.SerialNumber) |
| 717 | |
| 718 | kwargs := make(map[string]interface{}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 719 | ponPort := IntfIDToPortNo(onuInd.GetIntfId(), voltha.Port_PON_OLT) |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 720 | var onuDevice *voltha.Device |
| 721 | foundInCache := false |
| 722 | onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.OnuId) |
| 723 | if onuInCache, ok := dh.onus[onuKey]; ok { |
| 724 | //If ONU id is discovered before then use GetDevice to get onuDevice because it is cheaper. |
| 725 | foundInCache = true |
| 726 | onuDevice, _ = dh.coreProxy.GetDevice(nil, dh.device.Id, onuInCache.deviceID) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 727 | } else { |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 728 | //If ONU not found in adapter cache then we have to use GetChildDevice to get onuDevice |
| 729 | if serialNumber != "" { |
| 730 | kwargs["serial_number"] = serialNumber |
| 731 | } else { |
| 732 | kwargs["onu_id"] = onuInd.OnuId |
| 733 | kwargs["parent_port_no"] = ponPort |
| 734 | } |
| 735 | onuDevice, _ = dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 736 | } |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 737 | |
| 738 | if onuDevice != nil { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 739 | if onuDevice.ParentPortNo != ponPort { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 740 | //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] | 741 | 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] | 742 | } |
| 743 | |
| 744 | if onuDevice.ProxyAddress.OnuId != onuInd.OnuId { |
| 745 | 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}) |
| 746 | } |
Mahir Gunyel | e77977b | 2019-06-27 05:36:22 -0700 | [diff] [blame] | 747 | if !foundInCache { |
| 748 | onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.GetOnuId()) |
| 749 | dh.onus[onuKey] = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuInd.GetOnuId(), onuInd.GetIntfId(), onuDevice.ProxyAddress.DeviceId) |
| 750 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 751 | dh.updateOnuStates(onuDevice, onuInd) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 752 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 753 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 754 | log.Errorw("onu not found", log.Fields{"intfID": onuInd.IntfId, "onuID": onuInd.OnuId}) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 755 | return |
| 756 | } |
| 757 | |
| 758 | } |
| 759 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 760 | func (dh *DeviceHandler) updateOnuStates(onuDevice *voltha.Device, onuInd *oop.OnuIndication) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 761 | dh.updateOnuAdminState(onuInd) |
| 762 | // operState |
| 763 | if onuInd.OperState == "down" { |
| 764 | if onuDevice.ConnectStatus != common.ConnectStatus_UNREACHABLE { |
| 765 | err := dh.coreProxy.DeviceStateUpdate(context.TODO(), onuDevice.Id, common.ConnectStatus_UNREACHABLE, |
| 766 | onuDevice.OperStatus) |
| 767 | if err != nil { |
| 768 | log.Errorw("unable to update onu state", log.Fields{"DeviceID": onuDevice.Id}) |
| 769 | return |
| 770 | } |
| 771 | log.Debugln("onu-oper-state-is-down") |
| 772 | } |
| 773 | if onuDevice.OperStatus != common.OperStatus_DISCOVERED { |
| 774 | err := dh.coreProxy.DeviceStateUpdate(context.TODO(), onuDevice.Id, common.ConnectStatus_UNREACHABLE, |
| 775 | common.OperStatus_DISCOVERED) |
| 776 | if err != nil { |
| 777 | log.Errorw("unable to update onu state", log.Fields{"DeviceID": onuDevice.Id}) |
| 778 | return |
| 779 | } |
| 780 | } |
| 781 | log.Debugw("inter-adapter-send-onu-ind", log.Fields{"onuIndication": onuInd}) |
| 782 | |
| 783 | // TODO NEW CORE do not hardcode adapter name. Handler needs Adapter reference |
| 784 | err := dh.AdapterProxy.SendInterAdapterMessage(context.TODO(), onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, |
| 785 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 786 | if err != nil { |
| 787 | log.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
| 788 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id}) |
| 789 | } |
| 790 | } else if onuInd.OperState == "up" { |
| 791 | if onuDevice.ConnectStatus != common.ConnectStatus_REACHABLE { |
| 792 | err := dh.coreProxy.DeviceStateUpdate(context.TODO(), onuDevice.Id, common.ConnectStatus_REACHABLE, onuDevice.OperStatus) |
| 793 | if err != nil { |
| 794 | log.Errorw("unable to update onu state", log.Fields{"DeviceID": onuDevice.Id}) |
| 795 | return |
| 796 | } |
| 797 | } |
| 798 | if onuDevice.OperStatus != common.OperStatus_DISCOVERED { |
| 799 | log.Warnw("ignore onu indication", log.Fields{"intfID": onuInd.IntfId, "onuID": onuInd.OnuId, "operStatus": onuDevice.OperStatus, "msgOperStatus": onuInd.OperState}) |
| 800 | return |
| 801 | } |
| 802 | err := dh.AdapterProxy.SendInterAdapterMessage(context.TODO(), onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, |
| 803 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 804 | if err != nil { |
| 805 | log.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
| 806 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id}) |
| 807 | return |
| 808 | } |
| 809 | } else { |
| 810 | log.Warnw("Not-implemented-or-invalid-value-of-oper-state", log.Fields{"operState": onuInd.OperState}) |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | func (dh *DeviceHandler) updateOnuAdminState(onuInd *oop.OnuIndication) { |
| 815 | if onuInd.AdminState == "down" { |
| 816 | if onuInd.OperState != "down" { |
| 817 | log.Errorw("ONU-admin-state-down-and-oper-status-not-down", log.Fields{"operState": onuInd.OperState}) |
| 818 | // Forcing the oper state change code to execute |
| 819 | onuInd.OperState = "down" |
| 820 | } |
| 821 | // Port and logical port update is taken care of by oper state block |
| 822 | } else if onuInd.AdminState == "up" { |
| 823 | log.Debugln("received-onu-admin-state up") |
| 824 | } else { |
| 825 | log.Errorw("Invalid-or-not-implemented-admin-state", log.Fields{"received-admin-state": onuInd.AdminState}) |
| 826 | } |
| 827 | log.Debugln("admin-state-dealt-with") |
| 828 | } |
| 829 | |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 830 | func (dh *DeviceHandler) stringifySerialNumber(serialNum *oop.SerialNumber) string { |
| 831 | if serialNum != nil { |
| 832 | return string(serialNum.VendorId) + dh.stringifyVendorSpecific(serialNum.VendorSpecific) |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 833 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 834 | return "" |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | func (dh *DeviceHandler) stringifyVendorSpecific(vendorSpecific []byte) string { |
| 838 | tmp := fmt.Sprintf("%x", (uint32(vendorSpecific[0])>>4)&0x0f) + |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 839 | fmt.Sprintf("%x", uint32(vendorSpecific[0]&0x0f)) + |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 840 | fmt.Sprintf("%x", (uint32(vendorSpecific[1])>>4)&0x0f) + |
| 841 | fmt.Sprintf("%x", (uint32(vendorSpecific[1]))&0x0f) + |
| 842 | fmt.Sprintf("%x", (uint32(vendorSpecific[2])>>4)&0x0f) + |
| 843 | fmt.Sprintf("%x", (uint32(vendorSpecific[2]))&0x0f) + |
| 844 | fmt.Sprintf("%x", (uint32(vendorSpecific[3])>>4)&0x0f) + |
| 845 | fmt.Sprintf("%x", (uint32(vendorSpecific[3]))&0x0f) |
| 846 | return tmp |
| 847 | } |
| 848 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 849 | //UpdateFlowsBulk upates the bulk flow |
| 850 | func (dh *DeviceHandler) UpdateFlowsBulk() error { |
| 851 | return errors.New("unimplemented") |
cuilin2018 | 7b2a8c3 | 2019-03-26 19:52:28 -0700 | [diff] [blame] | 852 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 853 | |
| 854 | //GetChildDevice returns the child device for given parent port and onu id |
| 855 | func (dh *DeviceHandler) GetChildDevice(parentPort, onuID uint32) *voltha.Device { |
| 856 | log.Debugw("GetChildDevice", log.Fields{"pon port": parentPort, "onuID": onuID}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 857 | kwargs := make(map[string]interface{}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 858 | kwargs["onu_id"] = onuID |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 859 | kwargs["parent_port_no"] = parentPort |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 860 | onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 861 | if err != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 862 | log.Errorw("onu not found", log.Fields{"intfID": parentPort, "onuID": onuID}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 863 | return nil |
| 864 | } |
| 865 | log.Debugw("Successfully received child device from core", log.Fields{"child_device": *onuDevice}) |
| 866 | return onuDevice |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 867 | } |
| 868 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 869 | // SendPacketInToCore sends packet-in to core |
| 870 | // For this, it calls SendPacketIn of the core-proxy which uses a device specific topic to send the request. |
| 871 | // The adapter handling the device creates a device specific topic |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 872 | func (dh *DeviceHandler) SendPacketInToCore(logicalPort uint32, packetPayload []byte) { |
| 873 | log.Debugw("SendPacketInToCore", log.Fields{"port": logicalPort, "packetPayload": packetPayload}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 874 | 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] | 875 | log.Errorw("Error sending packetin to core", log.Fields{"error": err}) |
| 876 | return |
| 877 | } |
| 878 | log.Debug("Sent packet-in to core successfully") |
| 879 | } |
| 880 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 881 | //UpdateFlowsIncrementally updates the device flow |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 882 | func (dh *DeviceHandler) UpdateFlowsIncrementally(device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 883 | log.Debugw("In Update_flows_incrementally", log.Fields{"deviceID": device.Id, "flows": flows, "groups": groups}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 884 | if flows != nil { |
| 885 | for _, flow := range flows.ToAdd.Items { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 886 | log.Debug("Adding flow", log.Fields{"deviceId": device.Id, "flowToAdd": flow}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 887 | dh.flowMgr.AddFlow(flow) |
| 888 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 889 | for _, flow := range flows.ToRemove.Items { |
| 890 | log.Debug("Removing flow", log.Fields{"deviceId": device.Id, "flowToRemove": flow}) |
| 891 | dh.flowMgr.RemoveFlow(flow) |
| 892 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 893 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 894 | if groups != nil && flows != nil { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 895 | for _, flow := range flows.ToRemove.Items { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 896 | log.Debug("Removing flow", log.Fields{"deviceID": device.Id, "flowToRemove": flow}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 897 | // dh.flowMgr.RemoveFlow(flow) |
| 898 | } |
| 899 | } |
| 900 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 901 | } |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 902 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 903 | //DisableDevice disables the given device |
| 904 | //It marks the following for the given device: |
| 905 | //Device-Handler Admin-State : down |
| 906 | //Device Port-State: UNKNOWN |
| 907 | //Device Oper-State: UNKNOWN |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 908 | func (dh *DeviceHandler) DisableDevice(device *voltha.Device) error { |
| 909 | if _, err := dh.Client.DisableOlt(context.Background(), new(oop.Empty)); err != nil { |
| 910 | log.Errorw("Failed to disable olt ", log.Fields{"err": err}) |
| 911 | return err |
| 912 | } |
| 913 | dh.lockDevice.Lock() |
| 914 | dh.adminState = "down" |
| 915 | dh.lockDevice.Unlock() |
| 916 | log.Debug("olt-disabled") |
| 917 | |
| 918 | cloned := proto.Clone(device).(*voltha.Device) |
| 919 | // Update the all ports state on that device to disable |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 920 | if err := dh.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_UNKNOWN); err != nil { |
| 921 | log.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": err}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 922 | return err |
| 923 | } |
| 924 | |
| 925 | //Update the device oper state |
| 926 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 927 | dh.device = cloned |
| 928 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 929 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil { |
| 930 | 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] | 931 | return err |
| 932 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 933 | log.Debugw("Disable_device-end", log.Fields{"deviceID": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 934 | return nil |
| 935 | } |
| 936 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 937 | //ReenableDevice re-enables the olt device after disable |
| 938 | //It marks the following for the given device: |
| 939 | //Device-Handler Admin-State : up |
| 940 | //Device Port-State: ACTIVE |
| 941 | //Device Oper-State: ACTIVE |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 942 | func (dh *DeviceHandler) ReenableDevice(device *voltha.Device) error { |
| 943 | if _, err := dh.Client.ReenableOlt(context.Background(), new(oop.Empty)); err != nil { |
| 944 | log.Errorw("Failed to reenable olt ", log.Fields{"err": err}) |
| 945 | return err |
| 946 | } |
| 947 | |
| 948 | dh.lockDevice.Lock() |
| 949 | dh.adminState = "up" |
| 950 | dh.lockDevice.Unlock() |
| 951 | log.Debug("olt-reenabled") |
| 952 | |
| 953 | cloned := proto.Clone(device).(*voltha.Device) |
| 954 | // Update the all ports state on that device to enable |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 955 | if err := dh.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_ACTIVE); err != nil { |
| 956 | log.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": err}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 957 | return err |
| 958 | } |
| 959 | |
| 960 | //Update the device oper status as ACTIVE |
| 961 | cloned.OperStatus = voltha.OperStatus_ACTIVE |
| 962 | dh.device = cloned |
| 963 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 964 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil { |
| 965 | 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] | 966 | return err |
| 967 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 968 | log.Debugw("ReEnableDevice-end", log.Fields{"deviceID": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 969 | |
| 970 | return nil |
| 971 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 972 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 973 | //RebootDevice reboots the given device |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 974 | func (dh *DeviceHandler) RebootDevice(device *voltha.Device) error { |
| 975 | if _, err := dh.Client.Reboot(context.Background(), new(oop.Empty)); err != nil { |
| 976 | log.Errorw("Failed to reboot olt ", log.Fields{"err": err}) |
| 977 | return err |
| 978 | } |
| 979 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 980 | log.Debugw("rebooted-device-successfully", log.Fields{"deviceID": device.Id}) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 981 | |
| 982 | return nil |
| 983 | } |
| 984 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 985 | func (dh *DeviceHandler) handlePacketIndication(packetIn *oop.PacketIndication) { |
| 986 | log.Debugw("Received packet-in", log.Fields{"packet-indication": *packetIn}) |
| 987 | logicalPortNum, err := dh.flowMgr.GetLogicalPortFromPacketIn(packetIn) |
| 988 | if err != nil { |
| 989 | log.Errorw("Error getting logical port from packet-in", log.Fields{"error": err}) |
| 990 | return |
| 991 | } |
| 992 | 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] | 993 | 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] | 994 | log.Errorw("Error sending packet-in to core", log.Fields{"error": err}) |
| 995 | return |
| 996 | } |
| 997 | log.Debug("Success sending packet-in to core!") |
| 998 | } |
| 999 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1000 | // PacketOut sends packet-out from VOLTHA to OLT on the egress port provided |
| 1001 | func (dh *DeviceHandler) PacketOut(egressPortNo int, packet *of.OfpPacketOut) error { |
| 1002 | log.Debugw("PacketOut", log.Fields{"deviceID": dh.deviceID, "egress_port_no": egressPortNo, "pkt-length": len(packet.Data)}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1003 | var etherFrame ethernet.Frame |
| 1004 | err := (ðerFrame).UnmarshalBinary(packet.Data) |
| 1005 | if err != nil { |
| 1006 | log.Errorw("Failed to unmarshal into ethernet frame", log.Fields{"err": err, "pkt-length": len(packet.Data)}) |
| 1007 | return err |
| 1008 | } |
| 1009 | log.Debugw("Ethernet Frame", log.Fields{"Frame": etherFrame}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1010 | egressPortType := IntfIDToPortTypeName(uint32(egressPortNo)) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1011 | if egressPortType == voltha.Port_ETHERNET_UNI { |
| 1012 | if etherFrame.VLAN != nil { // If double tag, remove the outer tag |
| 1013 | nextEthType := (uint16(packet.Data[16]) << 8) | uint16(packet.Data[17]) |
| 1014 | if nextEthType == 0x8100 { |
| 1015 | etherFrame.VLAN = nil |
| 1016 | packet.Data, err = etherFrame.MarshalBinary() |
| 1017 | if err != nil { |
| 1018 | log.Fatalf("failed to marshal frame: %v", err) |
| 1019 | return err |
| 1020 | } |
| 1021 | if err := (ðerFrame).UnmarshalBinary(packet.Data); err != nil { |
| 1022 | log.Fatalf("failed to unmarshal frame: %v", err) |
| 1023 | return err |
| 1024 | } |
| 1025 | log.Debug("Double tagged packet , removed outer vlan", log.Fields{"New frame": etherFrame}) |
| 1026 | } |
| 1027 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1028 | intfID := IntfIDFromUniPortNum(uint32(egressPortNo)) |
| 1029 | onuID := OnuIDFromPortNum(uint32(egressPortNo)) |
| 1030 | uniID := UniIDFromPortNum(uint32(egressPortNo)) |
| 1031 | /*gemPortId, err := dh.flowMgr.GetPacketOutGemPortId(intfID, onuID, uint32(egress_port_no)) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1032 | if err != nil{ |
| 1033 | log.Errorw("Error while getting gemport to packet-out",log.Fields{"error": err}) |
| 1034 | return err |
| 1035 | }*/ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1036 | onuPkt := oop.OnuPacket{IntfId: intfID, OnuId: onuID, PortNo: uint32(egressPortNo), Pkt: packet.Data} |
| 1037 | log.Debug("sending-packet-to-ONU", log.Fields{"egress_port_no": egressPortNo, "IntfId": intfID, "onuID": onuID, |
| 1038 | "uniID": uniID, "packet": packet.Data}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1039 | if _, err := dh.Client.OnuPacketOut(context.Background(), &onuPkt); err != nil { |
| 1040 | log.Errorw("Error while sending packet-out to ONU", log.Fields{"error": err}) |
| 1041 | return err |
| 1042 | } |
| 1043 | } else if egressPortType == voltha.Port_ETHERNET_NNI { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1044 | uplinkPkt := oop.UplinkPacket{IntfId: IntfIDFromNniPortNum(uint32(egressPortNo)), Pkt: packet.Data} |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1045 | log.Debug("sending-packet-to-uplink", log.Fields{"uplink_pkt": uplinkPkt}) |
| 1046 | if _, err := dh.Client.UplinkPacketOut(context.Background(), &uplinkPkt); err != nil { |
| 1047 | log.Errorw("Error while sending packet-out to uplink", log.Fields{"error": err}) |
| 1048 | return err |
| 1049 | } |
| 1050 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1051 | 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] | 1052 | } |
| 1053 | return nil |
| 1054 | } |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1055 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1056 | func (dh *DeviceHandler) formOnuKey(intfID, onuID uint32) string { |
| 1057 | return "" + strconv.Itoa(int(intfID)) + "." + strconv.Itoa(int(onuID)) |
Mahir Gunyel | a3f9add | 2019-06-06 15:13:19 -0700 | [diff] [blame] | 1058 | } |