Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-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 | */ |
| 16 | |
| 17 | //Package adaptercoreonu provides the utility for onu devices, flows and statistics |
| 18 | package adaptercoreonu |
| 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "encoding/hex" |
| 23 | "errors" |
| 24 | "fmt" |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 25 | "strconv" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 26 | "sync" |
| 27 | "time" |
| 28 | |
| 29 | "github.com/gogo/protobuf/proto" |
| 30 | "github.com/golang/protobuf/ptypes" |
| 31 | "github.com/looplab/fsm" |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 32 | me "github.com/opencord/omci-lib-go/generated" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 33 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 34 | "github.com/opencord/voltha-lib-go/v3/pkg/db" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 35 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 36 | vc "github.com/opencord/voltha-protos/v3/go/common" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 37 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 38 | oop "github.com/opencord/voltha-protos/v3/go/openolt" |
| 39 | "github.com/opencord/voltha-protos/v3/go/voltha" |
| 40 | ) |
| 41 | |
| 42 | /* |
| 43 | // Constants for number of retries and for timeout |
| 44 | const ( |
| 45 | MaxRetry = 10 |
| 46 | MaxTimeOutInMs = 500 |
| 47 | ) |
| 48 | */ |
| 49 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 50 | const ( |
| 51 | // events of Device FSM |
| 52 | devEvDeviceInit = "devEvDeviceInit" |
| 53 | devEvGrpcConnected = "devEvGrpcConnected" |
| 54 | devEvGrpcDisconnected = "devEvGrpcDisconnected" |
| 55 | devEvDeviceUpInd = "devEvDeviceUpInd" |
| 56 | devEvDeviceDownInd = "devEvDeviceDownInd" |
| 57 | ) |
| 58 | const ( |
| 59 | // states of Device FSM |
| 60 | devStNull = "devStNull" |
| 61 | devStDown = "devStDown" |
| 62 | devStInit = "devStInit" |
| 63 | devStConnected = "devStConnected" |
| 64 | devStUp = "devStUp" |
| 65 | ) |
| 66 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 67 | //Event category and subcategory definitions - same as defiend for OLT in eventmgr.go - should be done more centrally |
| 68 | const ( |
| 69 | pon = voltha.EventSubCategory_PON |
| 70 | olt = voltha.EventSubCategory_OLT |
| 71 | ont = voltha.EventSubCategory_ONT |
| 72 | onu = voltha.EventSubCategory_ONU |
| 73 | nni = voltha.EventSubCategory_NNI |
| 74 | service = voltha.EventCategory_SERVICE |
| 75 | security = voltha.EventCategory_SECURITY |
| 76 | equipment = voltha.EventCategory_EQUIPMENT |
| 77 | processing = voltha.EventCategory_PROCESSING |
| 78 | environment = voltha.EventCategory_ENVIRONMENT |
| 79 | communication = voltha.EventCategory_COMMUNICATION |
| 80 | ) |
| 81 | |
| 82 | const ( |
| 83 | cEventObjectType = "ONU" |
| 84 | ) |
| 85 | const ( |
| 86 | cOnuActivatedEvent = "ONU_ACTIVATED" |
| 87 | ) |
| 88 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 89 | //DeviceHandler will interact with the ONU ? device. |
| 90 | type DeviceHandler struct { |
| 91 | deviceID string |
| 92 | DeviceType string |
| 93 | adminState string |
| 94 | device *voltha.Device |
| 95 | logicalDeviceID string |
| 96 | ProxyAddressID string |
| 97 | ProxyAddressType string |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 98 | parentId string |
| 99 | ponPortNumber uint32 |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 100 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 101 | coreProxy adapterif.CoreProxy |
| 102 | AdapterProxy adapterif.AdapterProxy |
| 103 | EventProxy adapterif.EventProxy |
| 104 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 105 | pOpenOnuAc *OpenONUAC |
| 106 | pDeviceStateFsm *fsm.FSM |
| 107 | pPonPort *voltha.Port |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 108 | deviceEntrySet chan bool //channel for DeviceEntry set event |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 109 | pOnuOmciDevice *OnuDeviceEntry |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 110 | pOnuTP *OnuUniTechProf |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 111 | exitChannel chan int |
| 112 | lockDevice sync.RWMutex |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 113 | pOnuIndication *oop.OnuIndication |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 114 | deviceReason string |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 115 | pLockStateFsm *LockStateFsm |
| 116 | pUnlockStateFsm *LockStateFsm |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 117 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 118 | //flowMgr *OpenOltFlowMgr |
| 119 | //eventMgr *OpenOltEventMgr |
| 120 | //resourceMgr *rsrcMgr.OpenOltResourceMgr |
| 121 | |
| 122 | //discOnus sync.Map |
| 123 | //onus sync.Map |
| 124 | //portStats *OpenOltStatisticsMgr |
| 125 | //metrics *pmmetrics.PmMetrics |
| 126 | stopCollector chan bool |
| 127 | stopHeartbeatCheck chan bool |
| 128 | activePorts sync.Map |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 129 | uniEntityMap map[uint32]*OnuUniPort |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 130 | reconciling bool |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 133 | //NewDeviceHandler creates a new device handler |
| 134 | func NewDeviceHandler(cp adapterif.CoreProxy, ap adapterif.AdapterProxy, ep adapterif.EventProxy, device *voltha.Device, adapter *OpenONUAC) *DeviceHandler { |
| 135 | var dh DeviceHandler |
| 136 | dh.coreProxy = cp |
| 137 | dh.AdapterProxy = ap |
| 138 | dh.EventProxy = ep |
| 139 | cloned := (proto.Clone(device)).(*voltha.Device) |
| 140 | dh.deviceID = cloned.Id |
| 141 | dh.DeviceType = cloned.Type |
| 142 | dh.adminState = "up" |
| 143 | dh.device = cloned |
| 144 | dh.pOpenOnuAc = adapter |
| 145 | dh.exitChannel = make(chan int, 1) |
| 146 | dh.lockDevice = sync.RWMutex{} |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 147 | dh.deviceEntrySet = make(chan bool, 1) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 148 | dh.stopCollector = make(chan bool, 2) |
| 149 | dh.stopHeartbeatCheck = make(chan bool, 2) |
| 150 | //dh.metrics = pmmetrics.NewPmMetrics(cloned.Id, pmmetrics.Frequency(150), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames)) |
| 151 | dh.activePorts = sync.Map{} |
| 152 | //TODO initialize the support classes. |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 153 | dh.uniEntityMap = make(map[uint32]*OnuUniPort) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 154 | dh.reconciling = false |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 155 | |
| 156 | // Device related state machine |
| 157 | dh.pDeviceStateFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 158 | devStNull, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 159 | fsm.Events{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 160 | {Name: devEvDeviceInit, Src: []string{devStNull, devStDown}, Dst: devStInit}, |
| 161 | {Name: devEvGrpcConnected, Src: []string{devStInit}, Dst: devStConnected}, |
| 162 | {Name: devEvGrpcDisconnected, Src: []string{devStConnected, devStDown}, Dst: devStInit}, |
| 163 | {Name: devEvDeviceUpInd, Src: []string{devStConnected, devStDown}, Dst: devStUp}, |
| 164 | {Name: devEvDeviceDownInd, Src: []string{devStUp}, Dst: devStDown}, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 165 | }, |
| 166 | fsm.Callbacks{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 167 | "before_event": func(e *fsm.Event) { dh.logStateChange(e) }, |
| 168 | ("before_" + devEvDeviceInit): func(e *fsm.Event) { dh.doStateInit(e) }, |
| 169 | ("after_" + devEvDeviceInit): func(e *fsm.Event) { dh.postInit(e) }, |
| 170 | ("before_" + devEvGrpcConnected): func(e *fsm.Event) { dh.doStateConnected(e) }, |
| 171 | ("before_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.doStateInit(e) }, |
| 172 | ("after_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.postInit(e) }, |
| 173 | ("before_" + devEvDeviceUpInd): func(e *fsm.Event) { dh.doStateUp(e) }, |
| 174 | ("before_" + devEvDeviceDownInd): func(e *fsm.Event) { dh.doStateDown(e) }, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 175 | }, |
| 176 | ) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 177 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 178 | return &dh |
| 179 | } |
| 180 | |
| 181 | // start save the device to the data model |
| 182 | func (dh *DeviceHandler) Start(ctx context.Context) { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 183 | logger.Debugw("starting-device-handler", log.Fields{"device": dh.device, "device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 184 | // Add the initial device to the local model |
| 185 | logger.Debug("device-handler-started") |
| 186 | } |
| 187 | |
| 188 | // stop stops the device dh. Not much to do for now |
| 189 | func (dh *DeviceHandler) stop(ctx context.Context) { |
| 190 | logger.Debug("stopping-device-handler") |
| 191 | dh.exitChannel <- 1 |
| 192 | } |
| 193 | |
| 194 | // ########################################################################################## |
| 195 | // DeviceHandler methods that implement the adapters interface requests ##### begin ######### |
| 196 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 197 | //AdoptOrReconcileDevice adopts the OLT device |
| 198 | func (dh *DeviceHandler) AdoptOrReconcileDevice(ctx context.Context, device *voltha.Device) { |
| 199 | logger.Debugw("Adopt_or_reconcile_device", log.Fields{"device-id": device.Id, "Address": device.GetHostAndPort()}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 200 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 201 | logger.Debugw("Device FSM: ", log.Fields{"state": string(dh.pDeviceStateFsm.Current())}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 202 | if dh.pDeviceStateFsm.Is(devStNull) { |
| 203 | if err := dh.pDeviceStateFsm.Event(devEvDeviceInit); err != nil { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 204 | logger.Errorw("Device FSM: Can't go to state DeviceInit", log.Fields{"err": err}) |
| 205 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 206 | logger.Debugw("Device FSM: ", log.Fields{"state": string(dh.pDeviceStateFsm.Current())}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 207 | } else { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 208 | logger.Debugw("AdoptOrReconcileDevice: Agent/device init already done", log.Fields{"device-id": device.Id}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | //ProcessInterAdapterMessage sends the proxied messages to the target device |
| 214 | // If the proxy address is not found in the unmarshalled message, it first fetches the onu device for which the message |
| 215 | // is meant, and then send the unmarshalled omci message to this onu |
| 216 | func (dh *DeviceHandler) ProcessInterAdapterMessage(msg *ic.InterAdapterMessage) error { |
| 217 | msgID := msg.Header.Id |
| 218 | msgType := msg.Header.Type |
| 219 | fromTopic := msg.Header.FromTopic |
| 220 | toTopic := msg.Header.ToTopic |
| 221 | toDeviceID := msg.Header.ToDeviceId |
| 222 | proxyDeviceID := msg.Header.ProxyDeviceId |
| 223 | logger.Debugw("InterAdapter message header", log.Fields{"msgID": msgID, "msgType": msgType, |
| 224 | "fromTopic": fromTopic, "toTopic": toTopic, "toDeviceID": toDeviceID, "proxyDeviceID": proxyDeviceID}) |
| 225 | |
| 226 | switch msgType { |
| 227 | case ic.InterAdapterMessageType_OMCI_REQUEST: |
| 228 | { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 229 | msgBody := msg.GetBody() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 230 | omciMsg := &ic.InterAdapterOmciMessage{} |
| 231 | if err := ptypes.UnmarshalAny(msgBody, omciMsg); err != nil { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 232 | logger.Warnw("cannot-unmarshal-omci-msg-body", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 233 | "device-id": dh.deviceID, "error": err}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 234 | return err |
| 235 | } |
| 236 | |
| 237 | //assuming omci message content is hex coded! |
| 238 | // with restricted output of 16(?) bytes would be ...omciMsg.Message[:16] |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 239 | logger.Debugw("inter-adapter-recv-omci", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 240 | "device-id": dh.deviceID, "RxOmciMessage": hex.EncodeToString(omciMsg.Message)}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 241 | //receive_message(omci_msg.message) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 242 | pDevEntry := dh.GetOnuDeviceEntry(true) |
| 243 | if pDevEntry != nil { |
| 244 | return pDevEntry.PDevOmciCC.ReceiveMessage(context.TODO(), omciMsg.Message) |
| 245 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 246 | logger.Errorw("No valid OnuDevice -aborting", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 247 | return errors.New("No valid OnuDevice") |
| 248 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 249 | } |
| 250 | case ic.InterAdapterMessageType_ONU_IND_REQUEST: |
| 251 | { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 252 | msgBody := msg.GetBody() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 253 | onu_indication := &oop.OnuIndication{} |
| 254 | if err := ptypes.UnmarshalAny(msgBody, onu_indication); err != nil { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 255 | logger.Warnw("cannot-unmarshal-onu-indication-msg-body", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 256 | "device-id": dh.deviceID, "error": err}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 257 | return err |
| 258 | } |
| 259 | |
| 260 | onu_operstate := onu_indication.GetOperState() |
| 261 | logger.Debugw("inter-adapter-recv-onu-ind", log.Fields{"OnuId": onu_indication.GetOnuId(), |
| 262 | "AdminState": onu_indication.GetAdminState(), "OperState": onu_operstate, |
| 263 | "SNR": onu_indication.GetSerialNumber()}) |
| 264 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 265 | //interface related functions might be error checked .... |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 266 | if onu_operstate == "up" { |
| 267 | dh.create_interface(onu_indication) |
| 268 | } else if (onu_operstate == "down") || (onu_operstate == "unreachable") { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 269 | dh.updateInterface(onu_indication) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 270 | } else { |
| 271 | logger.Errorw("unknown-onu-indication operState", log.Fields{"OnuId": onu_indication.GetOnuId()}) |
| 272 | return errors.New("InvalidOperState") |
| 273 | } |
| 274 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 275 | case ic.InterAdapterMessageType_TECH_PROFILE_DOWNLOAD_REQUEST: |
| 276 | { |
| 277 | if dh.pOnuTP == nil { |
| 278 | //should normally not happen ... |
| 279 | logger.Warnw("onuTechProf instance not set up for DLMsg request - ignoring request", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 280 | log.Fields{"device-id": dh.deviceID}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 281 | return errors.New("TechProfile DLMsg request while onuTechProf instance not setup") |
| 282 | } |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 283 | if (dh.deviceReason == "stopping-openomci") || (dh.deviceReason == "omci-admin-lock") { |
| 284 | // I've seen cases for this request, where the device was already stopped |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 285 | logger.Warnw("TechProf stopped: device-unreachable", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 286 | return errors.New("device-unreachable") |
| 287 | } |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 288 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 289 | msgBody := msg.GetBody() |
| 290 | techProfMsg := &ic.InterAdapterTechProfileDownloadMessage{} |
| 291 | if err := ptypes.UnmarshalAny(msgBody, techProfMsg); err != nil { |
| 292 | logger.Warnw("cannot-unmarshal-techprof-msg-body", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 293 | "device-id": dh.deviceID, "error": err}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 294 | return err |
| 295 | } |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 296 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 297 | // we have to lock access to TechProfile processing based on different messageType calls or |
| 298 | // even to fast subsequent calls of the same messageType |
| 299 | dh.pOnuTP.lockTpProcMutex() |
| 300 | // lock hangs as long as below decoupled or other related TechProfile processing is active |
| 301 | if bTpModify := dh.pOnuTP.updateOnuUniTpPath(techProfMsg.UniId, techProfMsg.Path); bTpModify == true { |
| 302 | // if there has been some change for some uni TechProfilePath |
| 303 | //in order to allow concurrent calls to other dh instances we do not wait for execution here |
| 304 | //but doing so we can not indicate problems to the caller (who does what with that then?) |
| 305 | //by now we just assume straightforward successful execution |
| 306 | //TODO!!! Generally: In this scheme it would be good to have some means to indicate |
| 307 | // possible problems to the caller later autonomously |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 308 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 309 | // deadline context to ensure completion of background routines waited for |
| 310 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 311 | deadline := time.Now().Add(30 * time.Second) //allowed run time to finish before execution |
| 312 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 313 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 314 | dh.pOnuTP.resetProcessingErrorIndication() |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 315 | var wg sync.WaitGroup |
| 316 | wg.Add(2) // for the 2 go routines to finish |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 317 | // attention: deadline completion check and wg.Done is to be done in both routines |
| 318 | go dh.pOnuTP.configureUniTp(dctx, techProfMsg.UniId, techProfMsg.Path, &wg) |
| 319 | go dh.pOnuTP.updateOnuTpPathKvStore(dctx, &wg) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 320 | //the wait.. function is responsible for tpProcMutex.Unlock() |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 321 | err := dh.pOnuTP.waitForTpCompletion(cancel, &wg) //wait for background process to finish and collect their result |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 322 | return err |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 323 | } |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 324 | // no change, nothing really to do |
| 325 | dh.pOnuTP.unlockTpProcMutex() |
| 326 | //return success |
| 327 | return nil |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 328 | } |
| 329 | case ic.InterAdapterMessageType_DELETE_GEM_PORT_REQUEST: |
| 330 | { |
| 331 | if dh.pOnuTP == nil { |
| 332 | //should normally not happen ... |
| 333 | logger.Warnw("onuTechProf instance not set up for DelGem request - ignoring request", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 334 | log.Fields{"device-id": dh.deviceID}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 335 | return errors.New("TechProfile DelGem request while onuTechProf instance not setup") |
| 336 | } |
| 337 | |
| 338 | msgBody := msg.GetBody() |
| 339 | delGemPortMsg := &ic.InterAdapterDeleteGemPortMessage{} |
| 340 | if err := ptypes.UnmarshalAny(msgBody, delGemPortMsg); err != nil { |
| 341 | logger.Warnw("cannot-unmarshal-delete-gem-msg-body", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 342 | "device-id": dh.deviceID, "error": err}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 343 | return err |
| 344 | } |
| 345 | |
| 346 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
| 347 | dh.pOnuTP.lockTpProcMutex() |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 348 | |
| 349 | // deadline context to ensure completion of background routines waited for |
| 350 | deadline := time.Now().Add(10 * time.Second) //allowed run time to finish before execution |
| 351 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 352 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 353 | dh.pOnuTP.resetProcessingErrorIndication() |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 354 | var wg sync.WaitGroup |
| 355 | wg.Add(1) // for the 1 go routine to finish |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 356 | go dh.pOnuTP.deleteTpResource(dctx, delGemPortMsg.UniId, delGemPortMsg.TpPath, |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 357 | cResourceGemPort, delGemPortMsg.GemPortId, &wg) |
| 358 | //the wait.. function is responsible for tpProcMutex.Unlock() |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 359 | err := dh.pOnuTP.waitForTpCompletion(cancel, &wg) //let that also run off-line to let the IA messaging return! |
| 360 | return err |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 361 | } |
| 362 | case ic.InterAdapterMessageType_DELETE_TCONT_REQUEST: |
| 363 | { |
| 364 | if dh.pOnuTP == nil { |
| 365 | //should normally not happen ... |
| 366 | logger.Warnw("onuTechProf instance not set up for DelTcont request - ignoring request", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 367 | log.Fields{"device-id": dh.deviceID}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 368 | return errors.New("TechProfile DelTcont request while onuTechProf instance not setup") |
| 369 | } |
| 370 | |
| 371 | msgBody := msg.GetBody() |
| 372 | delTcontMsg := &ic.InterAdapterDeleteTcontMessage{} |
| 373 | if err := ptypes.UnmarshalAny(msgBody, delTcontMsg); err != nil { |
| 374 | logger.Warnw("cannot-unmarshal-delete-tcont-msg-body", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 375 | "device-id": dh.deviceID, "error": err}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 376 | return err |
| 377 | } |
| 378 | |
| 379 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
| 380 | dh.pOnuTP.lockTpProcMutex() |
| 381 | if bTpModify := dh.pOnuTP.updateOnuUniTpPath(delTcontMsg.UniId, ""); bTpModify == true { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 382 | // deadline context to ensure completion of background routines waited for |
| 383 | deadline := time.Now().Add(10 * time.Second) //allowed run time to finish before execution |
| 384 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 385 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 386 | dh.pOnuTP.resetProcessingErrorIndication() |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 387 | var wg sync.WaitGroup |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 388 | wg.Add(2) // for the 2 go routines to finish |
| 389 | go dh.pOnuTP.deleteTpResource(dctx, delTcontMsg.UniId, delTcontMsg.TpPath, |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 390 | cResourceTcont, delTcontMsg.AllocId, &wg) |
| 391 | // Removal of the tcont/alloc id mapping represents the removal of the tech profile |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 392 | go dh.pOnuTP.updateOnuTpPathKvStore(dctx, &wg) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 393 | //the wait.. function is responsible for tpProcMutex.Unlock() |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 394 | err := dh.pOnuTP.waitForTpCompletion(cancel, &wg) //let that also run off-line to let the IA messaging return! |
| 395 | return err |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 396 | } |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 397 | dh.pOnuTP.unlockTpProcMutex() |
| 398 | //return success |
| 399 | return nil |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 400 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 401 | default: |
| 402 | { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 403 | logger.Errorw("inter-adapter-unhandled-type", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 404 | "device-id": dh.deviceID, "msgType": msg.Header.Type}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 405 | return errors.New("unimplemented") |
| 406 | } |
| 407 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 408 | return nil |
| 409 | } |
| 410 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 411 | //DisableDevice locks the ONU and its UNI/VEIP ports (admin lock via OMCI) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 412 | // TODO!!! Clarify usage of this method, it is for sure not used within ONOS (OLT) device disable |
| 413 | // maybe it is obsolete by now |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 414 | func (dh *DeviceHandler) DisableDevice(device *voltha.Device) { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 415 | logger.Debugw("disable-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 416 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 417 | //admin-lock reason can also be used uniquely for setting the DeviceState accordingly - inblock |
| 418 | //state checking to prevent unneeded processing (eg. on ONU 'unreachable' and 'down') |
| 419 | if dh.deviceReason != "omci-admin-lock" { |
| 420 | // disable UNI ports/ONU |
| 421 | // *** should generate UniAdminStateDone event - unrelated to DeviceProcStatusUpdate!! |
| 422 | // here the result of the processing is not checked (trusted in background) ***** |
| 423 | if dh.pLockStateFsm == nil { |
| 424 | dh.createUniLockFsm(true, UniAdminStateDone) |
| 425 | } else { //LockStateFSM already init |
| 426 | dh.pLockStateFsm.SetSuccessEvent(UniAdminStateDone) |
| 427 | dh.runUniLockFsm(true) |
| 428 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 429 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 430 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "omci-admin-lock"); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 431 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 432 | logger.Errorw("error-updating-reason-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 433 | } |
| 434 | dh.deviceReason = "omci-admin-lock" |
| 435 | //200604: ConnState improved to 'unreachable' (was not set in python-code), OperState 'unknown' seems to be best choice |
| 436 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, voltha.ConnectStatus_UNREACHABLE, |
| 437 | voltha.OperStatus_UNKNOWN); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 438 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 439 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 440 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 444 | //ReenableDevice unlocks the ONU and its UNI/VEIP ports (admin unlock via OMCI) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 445 | // TODO!!! Clarify usage of this method, compare above DisableDevice, usage may clarify resulting states |
| 446 | // maybe it is obsolete by now |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 447 | func (dh *DeviceHandler) ReenableDevice(device *voltha.Device) { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 448 | logger.Debugw("reenable-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 449 | |
| 450 | // TODO!!! ConnectStatus and OperStatus to be set here could be more accurate, for now just ...(like python code) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 451 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, voltha.ConnectStatus_REACHABLE, |
| 452 | voltha.OperStatus_ACTIVE); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 453 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 454 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 455 | } |
| 456 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 457 | // TODO!!! DeviceReason to be set here could be more accurate, for now just ...(like python code) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 458 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "initial-mib-downloaded"); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 459 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 460 | logger.Errorw("error-updating-reason-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 461 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 462 | dh.deviceReason = "initial-mib-downloaded" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 463 | |
| 464 | // enable ONU/UNI ports |
| 465 | // *** should generate UniAdminStateDone event - unrelated to DeviceProcStatusUpdate!! |
| 466 | // here the result of the processing is not checked (trusted in background) ***** |
| 467 | if dh.pUnlockStateFsm == nil { |
| 468 | dh.createUniLockFsm(false, UniAdminStateDone) |
| 469 | } else { //UnlockStateFSM already init |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 470 | dh.pUnlockStateFsm.SetSuccessEvent(UniAdminStateDone) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 471 | dh.runUniLockFsm(false) |
| 472 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 473 | } |
| 474 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 475 | func (dh *DeviceHandler) ReconcileDeviceOnuInd() { |
| 476 | logger.Debugw("reconciling - simulate onu indication", log.Fields{"device-id": dh.deviceID}) |
| 477 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 478 | if err := dh.pOnuTP.restoreFromOnuTpPathKvStore(context.TODO()); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 479 | logger.Errorw("reconciling - restoring OnuTp-data failed - abort", log.Fields{"err": err, "device-id": dh.deviceID}) |
| 480 | dh.reconciling = false |
| 481 | return |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 482 | } |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 483 | var onu_indication oop.OnuIndication |
| 484 | onu_indication.IntfId = dh.pOnuTP.sOnuPersistentData.PersIntfID |
| 485 | onu_indication.OnuId = dh.pOnuTP.sOnuPersistentData.PersOnuID |
| 486 | onu_indication.OperState = dh.pOnuTP.sOnuPersistentData.PersOperState |
| 487 | onu_indication.AdminState = dh.pOnuTP.sOnuPersistentData.PersAdminState |
| 488 | dh.create_interface(&onu_indication) |
| 489 | } |
| 490 | |
| 491 | func (dh *DeviceHandler) ReconcileDeviceTechProf() { |
| 492 | logger.Debugw("reconciling - trigger tech profile config", log.Fields{"device-id": dh.deviceID}) |
| 493 | |
| 494 | dh.pOnuTP.lockTpProcMutex() |
| 495 | // lock hangs as long as below decoupled or other related TechProfile processing is active |
| 496 | for _, uniData := range dh.pOnuTP.sOnuPersistentData.PersUniTpPath { |
| 497 | //In order to allow concurrent calls to other dh instances we do not wait for execution here |
| 498 | //but doing so we can not indicate problems to the caller (who does what with that then?) |
| 499 | //by now we just assume straightforward successful execution |
| 500 | //TODO!!! Generally: In this scheme it would be good to have some means to indicate |
| 501 | // possible problems to the caller later autonomously |
| 502 | |
| 503 | // deadline context to ensure completion of background routines waited for |
| 504 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 505 | deadline := time.Now().Add(30 * time.Second) //allowed run time to finish before execution |
| 506 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 507 | |
| 508 | dh.pOnuTP.resetProcessingErrorIndication() |
| 509 | var wg sync.WaitGroup |
| 510 | wg.Add(1) // for the 1 go routines to finish |
| 511 | // attention: deadline completion check and wg.Done is to be done in both routines |
| 512 | go dh.pOnuTP.configureUniTp(dctx, uniData.PersUniId, uniData.PersTpPath, &wg) |
| 513 | //the wait.. function is responsible for tpProcMutex.Unlock() |
| 514 | dh.pOnuTP.waitForTpCompletion(cancel, &wg) //wait for background process to finish and collect their result |
| 515 | return |
| 516 | } |
| 517 | dh.pOnuTP.unlockTpProcMutex() |
| 518 | //TODO: reset of reconciling-flag has always to be done in the last ReconcileDevice*() function |
| 519 | dh.reconciling = false |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | func (dh *DeviceHandler) DeleteDevice(device *voltha.Device) error { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 523 | logger.Debugw("delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 524 | if err := dh.pOnuTP.deleteOnuTpPathKvStore(context.TODO()); err != nil { |
| 525 | return err |
| 526 | } |
| 527 | // TODO: further actions - stop metrics and FSMs, remove device ... |
| 528 | return nil |
| 529 | } |
| 530 | |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 531 | func (dh *DeviceHandler) RebootDevice(device *voltha.Device) error { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 532 | logger.Debugw("reboot-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 533 | if device.ConnectStatus != voltha.ConnectStatus_REACHABLE { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 534 | logger.Errorw("device-unreachable", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 535 | return errors.New("device-unreachable") |
| 536 | } |
| 537 | dh.pOnuOmciDevice.Reboot(context.TODO()) |
| 538 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, voltha.ConnectStatus_UNREACHABLE, |
| 539 | voltha.OperStatus_DISCOVERED); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 540 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 541 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 542 | return err |
| 543 | } |
| 544 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "rebooting-onu"); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 545 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 546 | logger.Errorw("error-updating-reason-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 547 | return err |
| 548 | } |
| 549 | dh.deviceReason = "rebooting-onu" |
| 550 | return nil |
| 551 | } |
| 552 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 553 | // DeviceHandler methods that implement the adapters interface requests## end ######### |
| 554 | // ##################################################################################### |
| 555 | |
| 556 | // ################ to be updated acc. needs of ONU Device ######################## |
| 557 | // DeviceHandler StateMachine related state transition methods ##### begin ######### |
| 558 | |
| 559 | func (dh *DeviceHandler) logStateChange(e *fsm.Event) { |
| 560 | logger.Debugw("Device FSM: ", log.Fields{"event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst), "device-id": dh.deviceID}) |
| 561 | } |
| 562 | |
| 563 | // doStateInit provides the device update to the core |
| 564 | func (dh *DeviceHandler) doStateInit(e *fsm.Event) { |
| 565 | |
| 566 | logger.Debug("doStateInit-started") |
| 567 | var err error |
| 568 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 569 | // populate what we know. rest comes later after mib sync |
| 570 | dh.device.Root = false |
| 571 | dh.device.Vendor = "OpenONU" |
| 572 | dh.device.Model = "go" |
| 573 | dh.device.Reason = "activating-onu" |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 574 | dh.deviceReason = "activating-onu" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 575 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 576 | dh.logicalDeviceID = dh.deviceID // really needed - what for ??? //TODO!!! |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 577 | |
| 578 | if !dh.reconciling { |
| 579 | dh.coreProxy.DeviceUpdate(context.TODO(), dh.device) |
| 580 | } else { |
| 581 | logger.Debugw("reconciling - don't notify core about DeviceUpdate", |
| 582 | log.Fields{"device-id": dh.deviceID}) |
| 583 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 584 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 585 | dh.parentId = dh.device.ParentId |
| 586 | dh.ponPortNumber = dh.device.ParentPortNo |
| 587 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 588 | // store proxy parameters for later communication - assumption: invariant, else they have to be requested dynamically!! |
| 589 | dh.ProxyAddressID = dh.device.ProxyAddress.GetDeviceId() |
| 590 | dh.ProxyAddressType = dh.device.ProxyAddress.GetDeviceType() |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 591 | logger.Debugw("device-updated", log.Fields{"device-id": dh.deviceID, "proxyAddressID": dh.ProxyAddressID, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 592 | "proxyAddressType": dh.ProxyAddressType, "SNR": dh.device.SerialNumber, |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 593 | "ParentId": dh.parentId, "ParentPortNo": dh.ponPortNumber}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 594 | |
| 595 | /* |
| 596 | self._pon = PonPort.create(self, self._pon_port_number) |
| 597 | self._pon.add_peer(self.parent_id, self._pon_port_number) |
| 598 | self.logger.debug('adding-pon-port-to-agent', |
| 599 | type=self._pon.get_port().type, |
| 600 | admin_state=self._pon.get_port().admin_state, |
| 601 | oper_status=self._pon.get_port().oper_status, |
| 602 | ) |
| 603 | */ |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 604 | if !dh.reconciling { |
| 605 | logger.Debugw("adding-pon-port", log.Fields{"deviceID": dh.deviceID, "ponPortNo": dh.ponPortNumber}) |
| 606 | var ponPortNo uint32 = 1 |
| 607 | if dh.ponPortNumber != 0 { |
| 608 | ponPortNo = dh.ponPortNumber |
| 609 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 610 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 611 | pPonPort := &voltha.Port{ |
| 612 | PortNo: ponPortNo, |
| 613 | Label: fmt.Sprintf("pon-%d", ponPortNo), |
| 614 | Type: voltha.Port_PON_ONU, |
| 615 | OperStatus: voltha.OperStatus_ACTIVE, |
| 616 | Peers: []*voltha.Port_PeerPort{{DeviceId: dh.parentId, // Peer device is OLT |
| 617 | PortNo: ponPortNo}}, // Peer port is parent's port number |
| 618 | } |
| 619 | if err = dh.coreProxy.PortCreated(context.TODO(), dh.deviceID, pPonPort); err != nil { |
| 620 | logger.Fatalf("Device FSM: PortCreated-failed-%s", err) |
| 621 | e.Cancel(err) |
| 622 | return |
| 623 | } |
| 624 | } else { |
| 625 | logger.Debugw("reconciling - pon-port already added", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 626 | } |
| 627 | logger.Debug("doStateInit-done") |
| 628 | } |
| 629 | |
| 630 | // postInit setups the DeviceEntry for the conerned device |
| 631 | func (dh *DeviceHandler) postInit(e *fsm.Event) { |
| 632 | |
| 633 | logger.Debug("postInit-started") |
| 634 | var err error |
| 635 | /* |
| 636 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
| 637 | dh.pTransitionMap.Handle(ctx, GrpcConnected) |
| 638 | return nil |
| 639 | */ |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 640 | if err = dh.AddOnuDeviceEntry(context.TODO()); err != nil { |
| 641 | logger.Fatalf("Device FSM: AddOnuDeviceEntry-failed-%s", err) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 642 | e.Cancel(err) |
| 643 | return |
| 644 | } |
| 645 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 646 | if dh.reconciling { |
| 647 | go dh.ReconcileDeviceOnuInd() |
| 648 | // reconcilement will be continued after mib download is done |
| 649 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 650 | /* |
| 651 | ############################################################################ |
| 652 | # Setup Alarm handler |
| 653 | self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id, |
| 654 | device.serial_number) |
| 655 | ############################################################################ |
| 656 | # Setup PM configuration for this device |
| 657 | # Pass in ONU specific options |
| 658 | kwargs = { |
| 659 | OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY, |
| 660 | 'heartbeat': self.heartbeat, |
| 661 | OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device |
| 662 | } |
| 663 | self.logger.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number) |
| 664 | self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id, |
| 665 | self.logical_device_id, device.serial_number, |
| 666 | grouped=True, freq_override=False, **kwargs) |
| 667 | pm_config = self._pm_metrics.make_proto() |
| 668 | self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm) |
| 669 | self.logger.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number) |
| 670 | yield self.core_proxy.device_pm_config_update(pm_config, init=True) |
| 671 | |
| 672 | # Note, ONU ID and UNI intf set in add_uni_port method |
| 673 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events, |
| 674 | ani_ports=[self._pon]) |
| 675 | |
| 676 | # Code to Run OMCI Test Action |
| 677 | kwargs_omci_test_action = { |
| 678 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 679 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 680 | } |
| 681 | serial_number = device.serial_number |
| 682 | self._test_request = OmciTestRequest(self.core_proxy, |
| 683 | self.omci_agent, self.device_id, |
| 684 | AniG, serial_number, |
| 685 | self.logical_device_id, |
| 686 | exclusive=False, |
| 687 | **kwargs_omci_test_action) |
| 688 | |
| 689 | self.enabled = True |
| 690 | else: |
| 691 | self.logger.info('onu-already-activated') |
| 692 | */ |
| 693 | logger.Debug("postInit-done") |
| 694 | } |
| 695 | |
| 696 | // doStateConnected get the device info and update to voltha core |
| 697 | // for comparison of the original method (not that easy to uncomment): compare here: |
| 698 | // voltha-openolt-adapter/adaptercore/device_handler.go |
| 699 | // -> this one obviously initiates all communication interfaces of the device ...? |
| 700 | func (dh *DeviceHandler) doStateConnected(e *fsm.Event) { |
| 701 | |
| 702 | logger.Debug("doStateConnected-started") |
| 703 | var err error |
| 704 | err = errors.New("Device FSM: function not implemented yet!") |
| 705 | e.Cancel(err) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 706 | logger.Debug("doStateConnected-done") |
Matteo Scandolo | d132c0e | 2020-04-24 17:06:25 -0700 | [diff] [blame] | 707 | return |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | // doStateUp handle the onu up indication and update to voltha core |
| 711 | func (dh *DeviceHandler) doStateUp(e *fsm.Event) { |
| 712 | |
| 713 | logger.Debug("doStateUp-started") |
| 714 | var err error |
| 715 | err = errors.New("Device FSM: function not implemented yet!") |
| 716 | e.Cancel(err) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 717 | logger.Debug("doStateUp-done") |
Matteo Scandolo | d132c0e | 2020-04-24 17:06:25 -0700 | [diff] [blame] | 718 | return |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 719 | |
| 720 | /* |
| 721 | // Synchronous call to update device state - this method is run in its own go routine |
| 722 | if err := dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_REACHABLE, |
| 723 | voltha.OperStatus_ACTIVE); err != nil { |
| 724 | logger.Errorw("Failed to update device with OLT UP indication", log.Fields{"deviceID": dh.device.Id, "error": err}) |
| 725 | return err |
| 726 | } |
| 727 | return nil |
| 728 | */ |
| 729 | } |
| 730 | |
| 731 | // doStateDown handle the onu down indication |
| 732 | func (dh *DeviceHandler) doStateDown(e *fsm.Event) { |
| 733 | |
| 734 | logger.Debug("doStateDown-started") |
| 735 | var err error |
| 736 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 737 | device := dh.device |
| 738 | if device == nil { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 739 | /*TODO: needs to handle error scenarios */ |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 740 | logger.Error("Failed to fetch handler device") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 741 | e.Cancel(err) |
| 742 | return |
| 743 | } |
| 744 | |
| 745 | cloned := proto.Clone(device).(*voltha.Device) |
| 746 | logger.Debugw("do-state-down", log.Fields{"ClonedDeviceID": cloned.Id}) |
| 747 | /* |
| 748 | // Update the all ports state on that device to disable |
| 749 | if er := dh.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_UNKNOWN); er != nil { |
| 750 | logger.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": er}) |
| 751 | return er |
| 752 | } |
| 753 | |
| 754 | //Update the device oper state and connection status |
| 755 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 756 | cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE |
| 757 | dh.device = cloned |
| 758 | |
| 759 | if er := dh.coreProxy.DeviceStateUpdate(ctx, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil { |
| 760 | logger.Errorw("error-updating-device-state", log.Fields{"deviceID": device.Id, "error": er}) |
| 761 | return er |
| 762 | } |
| 763 | |
| 764 | //get the child device for the parent device |
| 765 | onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id) |
| 766 | if err != nil { |
| 767 | logger.Errorw("failed to get child devices information", log.Fields{"deviceID": dh.device.Id, "error": err}) |
| 768 | return err |
| 769 | } |
| 770 | for _, onuDevice := range onuDevices.Items { |
| 771 | |
| 772 | // Update onu state as down in onu adapter |
| 773 | onuInd := oop.OnuIndication{} |
| 774 | onuInd.OperState = "down" |
| 775 | er := dh.AdapterProxy.SendInterAdapterMessage(ctx, &onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, |
| 776 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 777 | if er != nil { |
| 778 | logger.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
| 779 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id}) |
| 780 | //Do not return here and continue to process other ONUs |
| 781 | } |
| 782 | } |
| 783 | // * Discovered ONUs entries need to be cleared , since after OLT |
| 784 | // is up, it starts sending discovery indications again* / |
| 785 | dh.discOnus = sync.Map{} |
| 786 | logger.Debugw("do-state-down-end", log.Fields{"deviceID": device.Id}) |
| 787 | return nil |
| 788 | */ |
| 789 | err = errors.New("Device FSM: function not implemented yet!") |
| 790 | e.Cancel(err) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 791 | logger.Debug("doStateDown-done") |
Matteo Scandolo | d132c0e | 2020-04-24 17:06:25 -0700 | [diff] [blame] | 792 | return |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | // DeviceHandler StateMachine related state transition methods ##### end ######### |
| 796 | // ################################################################################# |
| 797 | |
| 798 | // ################################################### |
| 799 | // DeviceHandler utility methods ##### begin ######### |
| 800 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 801 | //GetOnuDeviceEntry getsthe ONU device entry and may wait until its value is defined |
| 802 | func (dh *DeviceHandler) GetOnuDeviceEntry(aWait bool) *OnuDeviceEntry { |
| 803 | dh.lockDevice.RLock() |
| 804 | pOnuDeviceEntry := dh.pOnuOmciDevice |
| 805 | if aWait && pOnuDeviceEntry == nil { |
| 806 | //keep the read sema short to allow for subsequent write |
| 807 | dh.lockDevice.RUnlock() |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 808 | logger.Debugw("Waiting for DeviceEntry to be set ...", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 809 | // based on concurrent processing the deviceEntry setup may not yet be finished at his point |
| 810 | // so it might be needed to wait here for that event with some timeout |
| 811 | select { |
| 812 | case <-time.After(60 * time.Second): //timer may be discussed ... |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 813 | logger.Errorw("No valid DeviceEntry set after maxTime", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 814 | return nil |
| 815 | case <-dh.deviceEntrySet: |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 816 | logger.Debugw("devicEntry ready now - continue", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 817 | // if written now, we can return the written value without sema |
| 818 | return dh.pOnuOmciDevice |
| 819 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 820 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 821 | dh.lockDevice.RUnlock() |
| 822 | return pOnuDeviceEntry |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 823 | } |
| 824 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 825 | //SetOnuDeviceEntry sets the ONU device entry within the handler |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 826 | func (dh *DeviceHandler) SetOnuDeviceEntry( |
| 827 | apDeviceEntry *OnuDeviceEntry, apOnuTp *OnuUniTechProf) error { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 828 | dh.lockDevice.Lock() |
| 829 | defer dh.lockDevice.Unlock() |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 830 | dh.pOnuOmciDevice = apDeviceEntry |
| 831 | dh.pOnuTP = apOnuTp |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 832 | return nil |
| 833 | } |
| 834 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 835 | //AddOnuDeviceEntry creates a new ONU device or returns the existing |
| 836 | func (dh *DeviceHandler) AddOnuDeviceEntry(ctx context.Context) error { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 837 | logger.Debugw("adding-deviceEntry", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 838 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 839 | deviceEntry := dh.GetOnuDeviceEntry(false) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 840 | if deviceEntry == nil { |
| 841 | /* costum_me_map in python code seems always to be None, |
| 842 | we omit that here first (declaration unclear) -> todo at Adapter specialization ...*/ |
| 843 | /* also no 'clock' argument - usage open ...*/ |
| 844 | /* and no alarm_db yet (oo.alarm_db) */ |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 845 | deviceEntry = NewOnuDeviceEntry(ctx, dh.deviceID, dh.pOpenOnuAc.KVStoreHost, |
| 846 | dh.pOpenOnuAc.KVStorePort, dh.pOpenOnuAc.KVStoreType, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 847 | dh, dh.coreProxy, dh.AdapterProxy, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 848 | dh.pOpenOnuAc.pSupportedFsms) //nil as FSM pointer would yield deviceEntry internal defaults ... |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 849 | onuTechProfProc := NewOnuUniTechProf(ctx, dh.deviceID, dh) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 850 | //error treatment possible //TODO!!! |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 851 | dh.SetOnuDeviceEntry(deviceEntry, onuTechProfProc) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 852 | // fire deviceEntry ready event to spread to possibly waiting processing |
| 853 | dh.deviceEntrySet <- true |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 854 | logger.Infow("onuDeviceEntry-added", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 855 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 856 | logger.Infow("onuDeviceEntry-add: Device already exists", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 857 | } |
| 858 | // might be updated with some error handling !!! |
| 859 | return nil |
| 860 | } |
| 861 | |
| 862 | // doStateInit provides the device update to the core |
| 863 | func (dh *DeviceHandler) create_interface(onuind *oop.OnuIndication) error { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 864 | logger.Debugw("create_interface-started", log.Fields{"OnuId": onuind.GetOnuId(), |
| 865 | "OnuIntfId": onuind.GetIntfId(), "OnuSerialNumber": onuind.GetSerialNumber()}) |
| 866 | |
| 867 | dh.pOnuIndication = onuind // let's revise if storing the pointer is sufficient... |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 868 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 869 | if !dh.reconciling { |
| 870 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, |
| 871 | voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVATING); err != nil { |
| 872 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 873 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 874 | } |
| 875 | } else { |
| 876 | logger.Debugw("reconciling - don't notify core about DeviceStateUpdate to ACTIVATING", |
| 877 | log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 878 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 879 | // It does not look to me as if makes sense to work with the real core device here, (not the stored clone)? |
| 880 | // in this code the GetDevice would just make a check if the DeviceID's Device still exists in core |
| 881 | // in python code it looks as the started onu_omci_device might have been updated with some new instance state of the core device |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 882 | // but I would not know why, and the go code anyway does not work with the device directly anymore in the OnuDeviceEntry |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 883 | // so let's just try to keep it simple ... |
| 884 | /* |
| 885 | device, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, dh.device.Id) |
| 886 | if err != nil || device == nil { |
| 887 | //TODO: needs to handle error scenarios |
| 888 | logger.Errorw("Failed to fetch device device at creating If", log.Fields{"err": err}) |
| 889 | return errors.New("Voltha Device not found") |
| 890 | } |
| 891 | */ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 892 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 893 | pDevEntry := dh.GetOnuDeviceEntry(true) |
| 894 | if pDevEntry != nil { |
| 895 | pDevEntry.Start(context.TODO()) |
| 896 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 897 | logger.Errorw("No valid OnuDevice -aborting", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 898 | return errors.New("No valid OnuDevice") |
| 899 | } |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 900 | if !dh.reconciling { |
| 901 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "starting-openomci"); err != nil { |
| 902 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 903 | logger.Errorw("error-DeviceReasonUpdate to starting-openomci", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 904 | } |
| 905 | } else { |
| 906 | logger.Debugw("reconciling - don't notify core about DeviceReasonUpdate to starting-openomci", |
| 907 | log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 908 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 909 | dh.deviceReason = "starting-openomci" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 910 | |
| 911 | /* this might be a good time for Omci Verify message? */ |
| 912 | verifyExec := make(chan bool) |
| 913 | omci_verify := NewOmciTestRequest(context.TODO(), |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 914 | dh.device.Id, pDevEntry.PDevOmciCC, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 915 | true, true) //eclusive and allowFailure (anyway not yet checked) |
| 916 | omci_verify.PerformOmciTest(context.TODO(), verifyExec) |
| 917 | |
| 918 | /* give the handler some time here to wait for the OMCi verification result |
| 919 | after Timeout start and try MibUpload FSM anyway |
| 920 | (to prevent stopping on just not supported OMCI verification from ONU) */ |
| 921 | select { |
| 922 | case <-time.After(2 * time.Second): |
| 923 | logger.Warn("omci start-verification timed out (continue normal)") |
| 924 | case testresult := <-verifyExec: |
| 925 | logger.Infow("Omci start verification done", log.Fields{"result": testresult}) |
| 926 | } |
| 927 | |
| 928 | /* In py code it looks earlier (on activate ..) |
| 929 | # Code to Run OMCI Test Action |
| 930 | kwargs_omci_test_action = { |
| 931 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 932 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 933 | } |
| 934 | serial_number = device.serial_number |
| 935 | self._test_request = OmciTestRequest(self.core_proxy, |
| 936 | self.omci_agent, self.device_id, |
| 937 | AniG, serial_number, |
| 938 | self.logical_device_id, |
| 939 | exclusive=False, |
| 940 | **kwargs_omci_test_action) |
| 941 | ... |
| 942 | # Start test requests after a brief pause |
| 943 | if not self._test_request_started: |
| 944 | self._test_request_started = True |
| 945 | tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 946 | reactor.callLater(tststart, self._test_request.start_collector) |
| 947 | |
| 948 | */ |
| 949 | /* which is then: in omci_test_request.py : */ |
| 950 | /* |
| 951 | def start_collector(self, callback=None): |
| 952 | """ |
| 953 | Start the collection loop for an adapter if the frequency > 0 |
| 954 | |
| 955 | :param callback: (callable) Function to call to collect PM data |
| 956 | """ |
| 957 | self.logger.info("starting-pm-collection", device_name=self.name, default_freq=self.default_freq) |
| 958 | if callback is None: |
| 959 | callback = self.perform_test_omci |
| 960 | |
| 961 | if self.lc is None: |
| 962 | self.lc = LoopingCall(callback) |
| 963 | |
| 964 | if self.default_freq > 0: |
| 965 | self.lc.start(interval=self.default_freq / 10) |
| 966 | |
| 967 | def perform_test_omci(self): |
| 968 | """ |
| 969 | Perform the initial test request |
| 970 | """ |
| 971 | ani_g_entities = self._device.configuration.ani_g_entities |
| 972 | ani_g_entities_ids = list(ani_g_entities.keys()) if ani_g_entities \ |
| 973 | is not None else None |
| 974 | self._entity_id = ani_g_entities_ids[0] |
| 975 | self.logger.info('perform-test', entity_class=self._entity_class, |
| 976 | entity_id=self._entity_id) |
| 977 | try: |
| 978 | frame = MEFrame(self._entity_class, self._entity_id, []).test() |
| 979 | result = yield self._device.omci_cc.send(frame) |
| 980 | if not result.fields['omci_message'].fields['success_code']: |
| 981 | self.logger.info('Self-Test Submitted Successfully', |
| 982 | code=result.fields[ |
| 983 | 'omci_message'].fields['success_code']) |
| 984 | else: |
| 985 | raise TestFailure('Test Failure: {}'.format( |
| 986 | result.fields['omci_message'].fields['success_code'])) |
| 987 | except TimeoutError as e: |
| 988 | self.deferred.errback(failure.Failure(e)) |
| 989 | |
| 990 | except Exception as e: |
| 991 | self.logger.exception('perform-test-Error', e=e, |
| 992 | class_id=self._entity_class, |
| 993 | entity_id=self._entity_id) |
| 994 | self.deferred.errback(failure.Failure(e)) |
| 995 | |
| 996 | */ |
| 997 | |
| 998 | // PM related heartbeat??? !!!TODO.... |
| 999 | //self._heartbeat.enabled = True |
| 1000 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1001 | /* Note: Even though FSM calls look 'synchronous' here, FSM is running in background with the effect that possible errors |
| 1002 | * within the MibUpload are not notified in the OnuIndication response, this might be acceptable here, |
| 1003 | * as further OltAdapter processing may rely on the deviceReason event 'MibUploadDone' as a result of the FSM processing |
| 1004 | * otherwise some processing synchronisation would be required - cmp. e.g TechProfile processing |
| 1005 | */ |
| 1006 | //call MibUploadFSM - transition up to state ulStInSync |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1007 | pMibUlFsm := pDevEntry.pMibUploadFsm.pFsm |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1008 | if pMibUlFsm != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1009 | if pMibUlFsm.Is(ulStDisabled) { |
| 1010 | if err := pMibUlFsm.Event(ulEvStart); err != nil { |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1011 | logger.Errorw("MibSyncFsm: Can't go to state starting", log.Fields{"err": err}) |
| 1012 | return errors.New("Can't go to state starting") |
| 1013 | } else { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1014 | logger.Debugw("MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())}) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1015 | //Determine ONU status and start/re-start MIB Synchronization tasks |
| 1016 | //Determine if this ONU has ever synchronized |
| 1017 | if true { //TODO: insert valid check |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1018 | if err := pMibUlFsm.Event(ulEvResetMib); err != nil { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 1019 | logger.Errorw("MibSyncFsm: Can't go to state resetting_mib", log.Fields{"err": err}) |
| 1020 | return errors.New("Can't go to state resetting_mib") |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1021 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1022 | } else { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1023 | pMibUlFsm.Event(ulEvExamineMds) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1024 | logger.Debugw("state of MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())}) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1025 | //Examine the MIB Data Sync |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1026 | // callbacks to be handled: |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1027 | // Event(ulEvSuccess) |
| 1028 | // Event(ulEvTimeout) |
| 1029 | // Event(ulEvMismatch) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1030 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1031 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1032 | } else { |
| 1033 | logger.Errorw("wrong state of MibSyncFsm - want: disabled", log.Fields{"have": string(pMibUlFsm.Current())}) |
| 1034 | return errors.New("wrong state of MibSyncFsm") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1035 | } |
| 1036 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1037 | logger.Errorw("MibSyncFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1038 | return errors.New("cannot execut MibSync") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1039 | } |
| 1040 | return nil |
| 1041 | } |
| 1042 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1043 | func (dh *DeviceHandler) updateInterface(onuind *oop.OnuIndication) error { |
| 1044 | //state checking to prevent unneeded processing (eg. on ONU 'unreachable' and 'down') |
| 1045 | if dh.deviceReason != "stopping-openomci" { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1046 | logger.Debugw("updateInterface-started - stopping-device", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1047 | //stop all running SM processing - make use of the DH-state as mirrored in the deviceReason |
| 1048 | pDevEntry := dh.GetOnuDeviceEntry(false) |
| 1049 | if pDevEntry == nil { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1050 | logger.Errorw("No valid OnuDevice -aborting", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1051 | return errors.New("No valid OnuDevice") |
| 1052 | } |
| 1053 | |
| 1054 | switch dh.deviceReason { |
| 1055 | case "starting-openomci": |
| 1056 | { //MIBSync FSM may run |
| 1057 | pMibUlFsm := pDevEntry.pMibUploadFsm.pFsm |
| 1058 | if pMibUlFsm != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1059 | pMibUlFsm.Event(ulEvStop) //TODO!! verify if MibSyncFsm stop-processing is sufficient (to allow it again afterwards) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | case "discovery-mibsync-complete": |
| 1063 | { //MibDownload may run |
| 1064 | pMibDlFsm := pDevEntry.pMibDownloadFsm.pFsm |
| 1065 | if pMibDlFsm != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1066 | pMibDlFsm.Event(dlEvReset) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | default: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1070 | { |
| 1071 | //port lock/unlock FSM's may be active |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1072 | if dh.pUnlockStateFsm != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1073 | dh.pUnlockStateFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1074 | } |
| 1075 | if dh.pLockStateFsm != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1076 | dh.pLockStateFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1077 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1078 | //techProfile related PonAniConfigFsm FSM may be active |
| 1079 | // maybe encapsulated as OnuTP method - perhaps later in context of module splitting |
| 1080 | if dh.pOnuTP.pAniConfigFsm != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1081 | dh.pOnuTP.pAniConfigFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1082 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1083 | } |
| 1084 | //TODO!!! care about PM/Alarm processing once started |
| 1085 | } |
| 1086 | //TODO: from here the deviceHandler FSM itself may be stuck in some of the initial states |
| 1087 | // (mainly the still seperate 'Event states') |
| 1088 | // so it is questionable, how this is resolved after some possible re-enable |
| 1089 | // assumption there is obviously, that the system may continue with some 'after "mib-download-done" state' |
| 1090 | |
| 1091 | //stop/remove(?) the device entry |
| 1092 | pDevEntry.Stop(context.TODO()) //maybe some more sophisticated context treatment should be used here? |
| 1093 | |
| 1094 | //TODO!!! remove existing traffic profiles |
| 1095 | /* from py code, if TP's exist, remove them - not yet implemented |
| 1096 | self._tp = dict() |
| 1097 | # Let TP download happen again |
| 1098 | for uni_id in self._tp_service_specific_task: |
| 1099 | self._tp_service_specific_task[uni_id].clear() |
| 1100 | for uni_id in self._tech_profile_download_done: |
| 1101 | self._tech_profile_download_done[uni_id].clear() |
| 1102 | */ |
| 1103 | |
| 1104 | dh.disableUniPortStateUpdate() |
| 1105 | |
| 1106 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "stopping-openomci"); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1107 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1108 | logger.Errorw("error-DeviceReasonUpdate to 'stopping-openomci'", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1109 | log.Fields{"device-id": dh.deviceID, "error": err}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1110 | // abort: system behavior is just unstable ... |
| 1111 | return err |
| 1112 | } |
| 1113 | dh.deviceReason = "stopping-openomci" |
| 1114 | |
| 1115 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, |
| 1116 | voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_DISCOVERED); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1117 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1118 | logger.Errorw("error-updating-device-state unreachable-discovered", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1119 | log.Fields{"device-id": dh.deviceID, "error": err}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1120 | // abort: system behavior is just unstable ... |
| 1121 | return err |
| 1122 | } |
| 1123 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1124 | logger.Debugw("updateInterface - device already stopped", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1125 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1126 | return nil |
| 1127 | } |
| 1128 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1129 | //DeviceProcStatusUpdate evaluates possible processing events and initiates according next activities |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1130 | func (dh *DeviceHandler) DeviceProcStatusUpdate(dev_Event OnuDeviceEvent) { |
| 1131 | switch dev_Event { |
| 1132 | case MibDatabaseSync: |
| 1133 | { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1134 | logger.Debugw("MibInSync event received", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1135 | if !dh.reconciling { |
| 1136 | //initiate DevStateUpdate |
| 1137 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "discovery-mibsync-complete"); err != nil { |
| 1138 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1139 | logger.Errorw("error-DeviceReasonUpdate to 'mibsync-complete'", log.Fields{ |
| 1140 | "device-id": dh.deviceID, "error": err}) |
| 1141 | } else { |
| 1142 | logger.Infow("dev reason updated to 'MibSync complete'", log.Fields{"deviceID": dh.deviceID}) |
| 1143 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1144 | } else { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1145 | logger.Debugw("reconciling - don't notify core about DeviceReasonUpdate to mibsync-complete", |
| 1146 | log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1147 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1148 | //set internal state anyway - as it was done |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1149 | dh.deviceReason = "discovery-mibsync-complete" |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1150 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1151 | i := uint8(0) //UNI Port limit: see MaxUnisPerOnu (by now 16) (OMCI supports max 255 p.b.) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1152 | pDevEntry := dh.GetOnuDeviceEntry(false) |
| 1153 | if unigInstKeys := pDevEntry.pOnuDB.GetSortedInstKeys(me.UniGClassID); len(unigInstKeys) > 0 { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1154 | for _, mgmtEntityId := range unigInstKeys { |
| 1155 | logger.Debugw("Add UNI port for stored UniG instance:", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1156 | "device-id": dh.deviceID, "UnigMe EntityID": mgmtEntityId}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1157 | dh.addUniPort(mgmtEntityId, i, UniPPTP) |
| 1158 | i++ |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1159 | } |
| 1160 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1161 | logger.Debugw("No UniG instances found", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1162 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1163 | if veipInstKeys := pDevEntry.pOnuDB.GetSortedInstKeys(me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1164 | for _, mgmtEntityId := range veipInstKeys { |
| 1165 | logger.Debugw("Add VEIP acc. to stored VEIP instance:", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1166 | "device-id": dh.deviceID, "VEIP EntityID": mgmtEntityId}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1167 | dh.addUniPort(mgmtEntityId, i, UniVEIP) |
| 1168 | i++ |
| 1169 | } |
| 1170 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1171 | logger.Debugw("No VEIP instances found", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1172 | } |
| 1173 | if i == 0 { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1174 | logger.Warnw("No PPTP instances found", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1175 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1176 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1177 | /* 200605: lock processing after initial MIBUpload removed now as the ONU should be in the lock state per default here |
| 1178 | * left the code here as comment in case such processing should prove needed unexpectedly |
| 1179 | // Init Uni Ports to Admin locked state |
| 1180 | // maybe not really needed here as UNI ports should be locked by default, but still left as available in python code |
| 1181 | // *** should generate UniLockStateDone event ***** |
| 1182 | if dh.pLockStateFsm == nil { |
| 1183 | dh.createUniLockFsm(true, UniLockStateDone) |
| 1184 | } else { //LockStateFSM already init |
| 1185 | dh.pLockStateFsm.SetSuccessEvent(UniLockStateDone) |
| 1186 | dh.runUniLockFsm(true) |
| 1187 | } |
| 1188 | } |
| 1189 | case UniLockStateDone: |
| 1190 | { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1191 | logger.Infow("UniLockStateDone event: Starting MIB download", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1192 | * lockState processing commented out |
| 1193 | */ |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1194 | /* Mib download procedure - |
| 1195 | ***** should run over 'downloaded' state and generate MibDownloadDone event ***** |
| 1196 | */ |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1197 | pMibDlFsm := pDevEntry.pMibDownloadFsm.pFsm |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1198 | if pMibDlFsm != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1199 | if pMibDlFsm.Is(dlStDisabled) { |
| 1200 | if err := pMibDlFsm.Event(dlEvStart); err != nil { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1201 | logger.Errorw("MibDownloadFsm: Can't go to state starting", log.Fields{"err": err}) |
| 1202 | // maybe try a FSM reset and then again ... - TODO!!! |
| 1203 | } else { |
| 1204 | logger.Debugw("MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())}) |
| 1205 | // maybe use more specific states here for the specific download steps ... |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1206 | if err := pMibDlFsm.Event(dlEvCreateGal); err != nil { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1207 | logger.Errorw("MibDownloadFsm: Can't start CreateGal", log.Fields{"err": err}) |
| 1208 | } else { |
| 1209 | logger.Debugw("state of MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())}) |
| 1210 | //Begin MIB data download (running autonomously) |
| 1211 | } |
| 1212 | } |
| 1213 | } else { |
| 1214 | logger.Errorw("wrong state of MibDownloadFsm - want: disabled", log.Fields{"have": string(pMibDlFsm.Current())}) |
| 1215 | // maybe try a FSM reset and then again ... - TODO!!! |
| 1216 | } |
| 1217 | /***** Mib download started */ |
| 1218 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1219 | logger.Errorw("MibDownloadFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1220 | } |
| 1221 | } |
| 1222 | case MibDownloadDone: |
| 1223 | { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1224 | logger.Debugw("MibDownloadDone event received", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1225 | //initiate DevStateUpdate |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1226 | if !dh.reconciling { |
| 1227 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, |
| 1228 | voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE); err != nil { |
| 1229 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1230 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1231 | } else { |
| 1232 | logger.Debugw("dev state updated to 'Oper.Active'", log.Fields{"device-id": dh.deviceID}) |
| 1233 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1234 | } else { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1235 | logger.Debugw("reconciling - don't notify core about DeviceStateUpdate to ACTIVE", |
| 1236 | log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1237 | } |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1238 | if !dh.reconciling { |
| 1239 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "initial-mib-downloaded"); err != nil { |
| 1240 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1241 | logger.Errorw("error-DeviceReasonUpdate to 'initial-mib-downloaded'", |
| 1242 | log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1243 | } else { |
| 1244 | logger.Infow("dev reason updated to 'initial-mib-downloaded'", log.Fields{"device-id": dh.deviceID}) |
| 1245 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1246 | } else { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1247 | logger.Debugw("reconciling - don't notify core about DeviceReasonUpdate to initial-mib-downloaded", |
| 1248 | log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1249 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1250 | //set internal state anyway - as it was done |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1251 | dh.deviceReason = "initial-mib-downloaded" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1252 | // *** should generate UniUnlockStateDone event ***** |
| 1253 | if dh.pUnlockStateFsm == nil { |
| 1254 | dh.createUniLockFsm(false, UniUnlockStateDone) |
| 1255 | } else { //UnlockStateFSM already init |
| 1256 | dh.pUnlockStateFsm.SetSuccessEvent(UniUnlockStateDone) |
| 1257 | dh.runUniLockFsm(false) |
| 1258 | } |
| 1259 | } |
| 1260 | case UniUnlockStateDone: |
| 1261 | { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1262 | go dh.enableUniPortStateUpdate() //cmp python yield self.enable_ports() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1263 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1264 | if !dh.reconciling { |
| 1265 | logger.Infow("UniUnlockStateDone event: Sending OnuUp event", log.Fields{"device-id": dh.deviceID}) |
| 1266 | raisedTs := time.Now().UnixNano() |
| 1267 | go dh.sendOnuOperStateEvent(voltha.OperStatus_ACTIVE, dh.deviceID, raisedTs) //cmp python onu_active_event |
| 1268 | } else { |
| 1269 | logger.Debugw("reconciling - don't notify core that onu went to active but trigger tech profile config", |
| 1270 | log.Fields{"device-id": dh.deviceID}) |
| 1271 | go dh.ReconcileDeviceTechProf() |
| 1272 | //TODO: further actions e.g. restore flows, metrics, ... |
| 1273 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1274 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1275 | case OmciAniConfigDone: |
| 1276 | { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1277 | logger.Debugw("OmciAniConfigDone event received", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1278 | //TODO!: it might be needed to check some 'cached' pending flow configuration (vlan setting) |
| 1279 | // - to consider with outstanding flow implementation |
| 1280 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 1281 | // - which may cause some inconsistency |
| 1282 | if dh.deviceReason != "tech-profile-config-download-success" { |
| 1283 | // which may be the case from some previous actvity on another UNI Port of the ONU |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1284 | if !dh.reconciling { |
| 1285 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "tech-profile-config-download-success"); err != nil { |
| 1286 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1287 | logger.Errorw("error-DeviceReasonUpdate to 'tech-profile-config-download-success'", |
| 1288 | log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1289 | } else { |
| 1290 | logger.Infow("update dev reason to 'tech-profile-config-download-success'", |
| 1291 | log.Fields{"device-id": dh.deviceID}) |
| 1292 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1293 | } else { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1294 | logger.Debugw("reconciling - don't notify core about DeviceReasonUpdate to tech-profile-config-download-success", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1295 | log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1296 | } |
| 1297 | //set internal state anyway - as it was done |
| 1298 | dh.deviceReason = "tech-profile-config-download-success" |
| 1299 | } |
| 1300 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1301 | default: |
| 1302 | { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1303 | logger.Warnw("unhandled-device-event", log.Fields{"device-id": dh.deviceID, "event": dev_Event}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1304 | } |
| 1305 | } //switch |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 1308 | func (dh *DeviceHandler) addUniPort(a_uniInstNo uint16, a_uniId uint8, a_portType UniPortType) { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1309 | // parameters are IntfId, OnuId, uniId |
| 1310 | uniNo := MkUniPortNum(dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), |
| 1311 | uint32(a_uniId)) |
| 1312 | if _, present := dh.uniEntityMap[uniNo]; present { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1313 | logger.Warnw("onuUniPort-add: Port already exists", log.Fields{"for InstanceId": a_uniInstNo}) |
| 1314 | } else { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1315 | //with arguments a_uniId, a_portNo, a_portType |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1316 | pUniPort := NewOnuUniPort(a_uniId, uniNo, a_uniInstNo, a_portType) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1317 | if pUniPort == nil { |
| 1318 | logger.Warnw("onuUniPort-add: Could not create Port", log.Fields{"for InstanceId": a_uniInstNo}) |
| 1319 | } else { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1320 | //store UniPort with the System-PortNumber key |
| 1321 | dh.uniEntityMap[uniNo] = pUniPort |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1322 | if !dh.reconciling { |
| 1323 | // create announce the UniPort to the core as VOLTHA Port object |
| 1324 | if err := pUniPort.CreateVolthaPort(dh); err == nil { |
| 1325 | logger.Infow("onuUniPort-added", log.Fields{"for PortNo": uniNo}) |
| 1326 | } //error logging already within UniPort method |
| 1327 | } else { |
| 1328 | logger.Debugw("reconciling - onuUniPort already added", log.Fields{"for PortNo": uniNo, "device-id": dh.deviceID}) |
| 1329 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1333 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1334 | // enableUniPortStateUpdate enables UniPortState and update core port state accordingly |
| 1335 | func (dh *DeviceHandler) enableUniPortStateUpdate() { |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 1336 | // py code was updated 2003xx to activate the real ONU UNI ports per OMCI (VEIP or PPTP) |
| 1337 | // but towards core only the first port active state is signalled |
| 1338 | // with following remark: |
| 1339 | // # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow |
| 1340 | // # load on the core |
| 1341 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1342 | // lock_ports(false) as done in py code here is shifted to separate call from devicevent processing |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 1343 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1344 | for uniNo, uniPort := range dh.uniEntityMap { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1345 | // only if this port is validated for operState transfer |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 1346 | if (1<<uniPort.uniId)&ActiveUniPortStateUpdateMask == (1 << uniPort.uniId) { |
| 1347 | logger.Infow("onuUniPort-forced-OperState-ACTIVE", log.Fields{"for PortNo": uniNo}) |
| 1348 | uniPort.SetOperState(vc.OperStatus_ACTIVE) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1349 | if !dh.reconciling { |
| 1350 | //maybe also use getter functions on uniPort - perhaps later ... |
| 1351 | go dh.coreProxy.PortStateUpdate(context.TODO(), dh.deviceID, voltha.Port_ETHERNET_UNI, uniPort.portNo, uniPort.operState) |
| 1352 | } else { |
| 1353 | logger.Debugw("reconciling - don't notify core about PortStateUpdate", log.Fields{"device-id": dh.deviceID}) |
| 1354 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1355 | } |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | // Disable UniPortState and update core port state accordingly |
| 1360 | func (dh *DeviceHandler) disableUniPortStateUpdate() { |
| 1361 | // compare enableUniPortStateUpdate() above |
| 1362 | // -> use current restriction to operate only on first UNI port as inherited from actual Py code |
| 1363 | for uniNo, uniPort := range dh.uniEntityMap { |
| 1364 | // only if this port is validated for operState transfer |
| 1365 | if (1<<uniPort.uniId)&ActiveUniPortStateUpdateMask == (1 << uniPort.uniId) { |
| 1366 | logger.Infow("onuUniPort-forced-OperState-UNKNOWN", log.Fields{"for PortNo": uniNo}) |
| 1367 | uniPort.SetOperState(vc.OperStatus_UNKNOWN) |
| 1368 | //maybe also use getter functions on uniPort - perhaps later ... |
| 1369 | go dh.coreProxy.PortStateUpdate(context.TODO(), dh.deviceID, voltha.Port_ETHERNET_UNI, uniPort.portNo, uniPort.operState) |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 1370 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | // ONU_Active/Inactive announcement on system KAFKA bus |
| 1375 | // tried to re-use procedure of oltUpDownIndication from openolt_eventmgr.go with used values from Py code |
| 1376 | func (dh *DeviceHandler) sendOnuOperStateEvent(a_OperState vc.OperStatus_Types, a_deviceID string, raisedTs int64) { |
| 1377 | var de voltha.DeviceEvent |
| 1378 | eventContext := make(map[string]string) |
| 1379 | //Populating event context |
| 1380 | // assume giving ParentId in GetDevice twice really gives the ParentDevice (there is no GetParentDevice()...) |
| 1381 | parentDevice, err := dh.coreProxy.GetDevice(context.TODO(), dh.parentId, dh.parentId) |
| 1382 | if err != nil || parentDevice == nil { |
| 1383 | logger.Errorw("Failed to fetch parent device for OnuEvent", |
| 1384 | log.Fields{"parentId": dh.parentId, "err": err}) |
| 1385 | } |
| 1386 | oltSerialNumber := parentDevice.SerialNumber |
| 1387 | |
| 1388 | eventContext["pon-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.IntfId), 10) |
| 1389 | eventContext["onu-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.OnuId), 10) |
| 1390 | eventContext["serial-number"] = dh.device.SerialNumber |
| 1391 | eventContext["olt_serial_number"] = oltSerialNumber |
| 1392 | eventContext["device_id"] = a_deviceID |
| 1393 | eventContext["registration_id"] = a_deviceID //py: string(device_id)?? |
| 1394 | logger.Debugw("prepare ONU_ACTIVATED event", |
| 1395 | log.Fields{"DeviceId": a_deviceID, "EventContext": eventContext}) |
| 1396 | |
| 1397 | /* Populating device event body */ |
| 1398 | de.Context = eventContext |
| 1399 | de.ResourceId = a_deviceID |
| 1400 | if a_OperState == voltha.OperStatus_ACTIVE { |
| 1401 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "RAISE_EVENT") |
| 1402 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 1403 | cEventObjectType, cOnuActivatedEvent, "Raised") |
| 1404 | } else { |
| 1405 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "CLEAR_EVENT") |
| 1406 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 1407 | cEventObjectType, cOnuActivatedEvent, "Cleared") |
| 1408 | } |
| 1409 | /* Send event to KAFKA */ |
| 1410 | if err := dh.EventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil { |
| 1411 | logger.Warnw("could not send ONU_ACTIVATED event", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1412 | log.Fields{"device-id": a_deviceID, "error": err}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1413 | } |
| 1414 | logger.Debugw("ONU_ACTIVATED event sent to KAFKA", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1415 | log.Fields{"device-id": a_deviceID, "with-EventName": de.DeviceEventName}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1416 | } |
| 1417 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1418 | // createUniLockFsm initialises and runs the UniLock FSM to transfer teh OMCi related commands for port lock/unlock |
| 1419 | func (dh *DeviceHandler) createUniLockFsm(aAdminState bool, devEvent OnuDeviceEvent) { |
| 1420 | chLSFsm := make(chan Message, 2048) |
| 1421 | var sFsmName string |
| 1422 | if aAdminState == true { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1423 | logger.Infow("createLockStateFSM", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1424 | sFsmName = "LockStateFSM" |
| 1425 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1426 | logger.Infow("createUnlockStateFSM", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1427 | sFsmName = "UnLockStateFSM" |
| 1428 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1429 | |
| 1430 | pDevEntry := dh.GetOnuDeviceEntry(true) |
| 1431 | if pDevEntry == nil { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1432 | logger.Errorw("No valid OnuDevice -aborting", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1433 | return |
| 1434 | } |
| 1435 | pLSFsm := NewLockStateFsm(pDevEntry.PDevOmciCC, aAdminState, devEvent, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1436 | sFsmName, dh.deviceID, chLSFsm) |
| 1437 | if pLSFsm != nil { |
| 1438 | if aAdminState == true { |
| 1439 | dh.pLockStateFsm = pLSFsm |
| 1440 | } else { |
| 1441 | dh.pUnlockStateFsm = pLSFsm |
| 1442 | } |
| 1443 | dh.runUniLockFsm(aAdminState) |
| 1444 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1445 | logger.Errorw("LockStateFSM could not be created - abort!!", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | // runUniLockFsm starts the UniLock FSM to transfer the OMCI related commands for port lock/unlock |
| 1450 | func (dh *DeviceHandler) runUniLockFsm(aAdminState bool) { |
| 1451 | /* Uni Port lock/unlock procedure - |
| 1452 | ***** should run via 'adminDone' state and generate the argument requested event ***** |
| 1453 | */ |
| 1454 | var pLSStatemachine *fsm.FSM |
| 1455 | if aAdminState == true { |
| 1456 | pLSStatemachine = dh.pLockStateFsm.pAdaptFsm.pFsm |
| 1457 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 1458 | if (dh.pUnlockStateFsm != nil) && |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1459 | (dh.pUnlockStateFsm.pAdaptFsm.pFsm.Current() != uniStDisabled) { |
| 1460 | dh.pUnlockStateFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1461 | } |
| 1462 | } else { |
| 1463 | pLSStatemachine = dh.pUnlockStateFsm.pAdaptFsm.pFsm |
| 1464 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 1465 | if (dh.pLockStateFsm != nil) && |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1466 | (dh.pLockStateFsm.pAdaptFsm.pFsm.Current() != uniStDisabled) { |
| 1467 | dh.pLockStateFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1468 | } |
| 1469 | } |
| 1470 | if pLSStatemachine != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1471 | if pLSStatemachine.Is(uniStDisabled) { |
| 1472 | if err := pLSStatemachine.Event(uniEvStart); err != nil { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1473 | logger.Warnw("LockStateFSM: can't start", log.Fields{"err": err}) |
| 1474 | // maybe try a FSM reset and then again ... - TODO!!! |
| 1475 | } else { |
| 1476 | /***** LockStateFSM started */ |
| 1477 | logger.Debugw("LockStateFSM started", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1478 | "state": pLSStatemachine.Current(), "device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1479 | } |
| 1480 | } else { |
| 1481 | logger.Warnw("wrong state of LockStateFSM - want: disabled", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1482 | "have": pLSStatemachine.Current(), "device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1483 | // maybe try a FSM reset and then again ... - TODO!!! |
| 1484 | } |
| 1485 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1486 | logger.Errorw("LockStateFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1487 | // maybe try a FSM reset and then again ... - TODO!!! |
| 1488 | } |
| 1489 | } |
| 1490 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 1491 | //SetBackend provides a DB backend for the specified path on the existing KV client |
| 1492 | func (dh *DeviceHandler) SetBackend(aBasePathKvStore string) *db.Backend { |
| 1493 | addr := dh.pOpenOnuAc.KVStoreHost + ":" + strconv.Itoa(dh.pOpenOnuAc.KVStorePort) |
| 1494 | logger.Debugw("SetKVStoreBackend", log.Fields{"IpTarget": addr, |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1495 | "BasePathKvStore": aBasePathKvStore, "device-id": dh.deviceID}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 1496 | kvbackend := &db.Backend{ |
| 1497 | Client: dh.pOpenOnuAc.kvClient, |
| 1498 | StoreType: dh.pOpenOnuAc.KVStoreType, |
| 1499 | /* address config update acc. to [VOL-2736] */ |
| 1500 | Address: addr, |
| 1501 | Timeout: dh.pOpenOnuAc.KVStoreTimeout, |
| 1502 | PathPrefix: aBasePathKvStore} |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 1503 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 1504 | return kvbackend |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1505 | } |