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" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 35 | flow "github.com/opencord/voltha-lib-go/v3/pkg/flows" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 36 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 37 | vc "github.com/opencord/voltha-protos/v3/go/common" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 38 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 39 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 40 | of "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 41 | ofp "github.com/opencord/voltha-protos/v3/go/openflow_13" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 42 | oop "github.com/opencord/voltha-protos/v3/go/openolt" |
| 43 | "github.com/opencord/voltha-protos/v3/go/voltha" |
| 44 | ) |
| 45 | |
| 46 | /* |
| 47 | // Constants for number of retries and for timeout |
| 48 | const ( |
| 49 | MaxRetry = 10 |
| 50 | MaxTimeOutInMs = 500 |
| 51 | ) |
| 52 | */ |
| 53 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 54 | const ( |
| 55 | // events of Device FSM |
| 56 | devEvDeviceInit = "devEvDeviceInit" |
| 57 | devEvGrpcConnected = "devEvGrpcConnected" |
| 58 | devEvGrpcDisconnected = "devEvGrpcDisconnected" |
| 59 | devEvDeviceUpInd = "devEvDeviceUpInd" |
| 60 | devEvDeviceDownInd = "devEvDeviceDownInd" |
| 61 | ) |
| 62 | const ( |
| 63 | // states of Device FSM |
| 64 | devStNull = "devStNull" |
| 65 | devStDown = "devStDown" |
| 66 | devStInit = "devStInit" |
| 67 | devStConnected = "devStConnected" |
| 68 | devStUp = "devStUp" |
| 69 | ) |
| 70 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 71 | //Event category and subcategory definitions - same as defiend for OLT in eventmgr.go - should be done more centrally |
| 72 | const ( |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 73 | pon = voltha.EventSubCategory_PON |
| 74 | //olt = voltha.EventSubCategory_OLT |
| 75 | //ont = voltha.EventSubCategory_ONT |
| 76 | //onu = voltha.EventSubCategory_ONU |
| 77 | //nni = voltha.EventSubCategory_NNI |
| 78 | //service = voltha.EventCategory_SERVICE |
| 79 | //security = voltha.EventCategory_SECURITY |
| 80 | equipment = voltha.EventCategory_EQUIPMENT |
| 81 | //processing = voltha.EventCategory_PROCESSING |
| 82 | //environment = voltha.EventCategory_ENVIRONMENT |
| 83 | //communication = voltha.EventCategory_COMMUNICATION |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 84 | ) |
| 85 | |
| 86 | const ( |
| 87 | cEventObjectType = "ONU" |
| 88 | ) |
| 89 | const ( |
| 90 | cOnuActivatedEvent = "ONU_ACTIVATED" |
| 91 | ) |
| 92 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 93 | //deviceHandler will interact with the ONU ? device. |
| 94 | type deviceHandler struct { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 95 | deviceID string |
| 96 | DeviceType string |
| 97 | adminState string |
| 98 | device *voltha.Device |
| 99 | logicalDeviceID string |
| 100 | ProxyAddressID string |
| 101 | ProxyAddressType string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 102 | parentID string |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 103 | ponPortNumber uint32 |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 104 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 105 | coreProxy adapterif.CoreProxy |
| 106 | AdapterProxy adapterif.AdapterProxy |
| 107 | EventProxy adapterif.EventProxy |
| 108 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 109 | pOpenOnuAc *OpenONUAC |
| 110 | pDeviceStateFsm *fsm.FSM |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 111 | //pPonPort *voltha.Port |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 112 | deviceEntrySet chan bool //channel for DeviceEntry set event |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 113 | pOnuOmciDevice *OnuDeviceEntry |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 114 | pOnuTP *onuUniTechProf |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 115 | exitChannel chan int |
| 116 | lockDevice sync.RWMutex |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 117 | pOnuIndication *oop.OnuIndication |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 118 | deviceReason string |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 119 | pLockStateFsm *lockStateFsm |
| 120 | pUnlockStateFsm *lockStateFsm |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 121 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 122 | //flowMgr *OpenOltFlowMgr |
| 123 | //eventMgr *OpenOltEventMgr |
| 124 | //resourceMgr *rsrcMgr.OpenOltResourceMgr |
| 125 | |
| 126 | //discOnus sync.Map |
| 127 | //onus sync.Map |
| 128 | //portStats *OpenOltStatisticsMgr |
| 129 | //metrics *pmmetrics.PmMetrics |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 130 | stopCollector chan bool |
| 131 | stopHeartbeatCheck chan bool |
| 132 | activePorts sync.Map |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 133 | uniEntityMap map[uint32]*onuUniPort |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 134 | UniVlanConfigFsmMap map[uint8]*UniVlanConfigFsm |
| 135 | reconciling bool |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 138 | //newDeviceHandler creates a new device handler |
| 139 | func newDeviceHandler(cp adapterif.CoreProxy, ap adapterif.AdapterProxy, ep adapterif.EventProxy, device *voltha.Device, adapter *OpenONUAC) *deviceHandler { |
| 140 | var dh deviceHandler |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 141 | dh.coreProxy = cp |
| 142 | dh.AdapterProxy = ap |
| 143 | dh.EventProxy = ep |
| 144 | cloned := (proto.Clone(device)).(*voltha.Device) |
| 145 | dh.deviceID = cloned.Id |
| 146 | dh.DeviceType = cloned.Type |
| 147 | dh.adminState = "up" |
| 148 | dh.device = cloned |
| 149 | dh.pOpenOnuAc = adapter |
| 150 | dh.exitChannel = make(chan int, 1) |
| 151 | dh.lockDevice = sync.RWMutex{} |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 152 | dh.deviceEntrySet = make(chan bool, 1) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 153 | dh.stopCollector = make(chan bool, 2) |
| 154 | dh.stopHeartbeatCheck = make(chan bool, 2) |
| 155 | //dh.metrics = pmmetrics.NewPmMetrics(cloned.Id, pmmetrics.Frequency(150), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames)) |
| 156 | dh.activePorts = sync.Map{} |
| 157 | //TODO initialize the support classes. |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 158 | dh.uniEntityMap = make(map[uint32]*onuUniPort) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 159 | dh.UniVlanConfigFsmMap = make(map[uint8]*UniVlanConfigFsm) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 160 | dh.reconciling = false |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 161 | |
| 162 | // Device related state machine |
| 163 | dh.pDeviceStateFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 164 | devStNull, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 165 | fsm.Events{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 166 | {Name: devEvDeviceInit, Src: []string{devStNull, devStDown}, Dst: devStInit}, |
| 167 | {Name: devEvGrpcConnected, Src: []string{devStInit}, Dst: devStConnected}, |
| 168 | {Name: devEvGrpcDisconnected, Src: []string{devStConnected, devStDown}, Dst: devStInit}, |
| 169 | {Name: devEvDeviceUpInd, Src: []string{devStConnected, devStDown}, Dst: devStUp}, |
| 170 | {Name: devEvDeviceDownInd, Src: []string{devStUp}, Dst: devStDown}, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 171 | }, |
| 172 | fsm.Callbacks{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 173 | "before_event": func(e *fsm.Event) { dh.logStateChange(e) }, |
| 174 | ("before_" + devEvDeviceInit): func(e *fsm.Event) { dh.doStateInit(e) }, |
| 175 | ("after_" + devEvDeviceInit): func(e *fsm.Event) { dh.postInit(e) }, |
| 176 | ("before_" + devEvGrpcConnected): func(e *fsm.Event) { dh.doStateConnected(e) }, |
| 177 | ("before_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.doStateInit(e) }, |
| 178 | ("after_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.postInit(e) }, |
| 179 | ("before_" + devEvDeviceUpInd): func(e *fsm.Event) { dh.doStateUp(e) }, |
| 180 | ("before_" + devEvDeviceDownInd): func(e *fsm.Event) { dh.doStateDown(e) }, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 181 | }, |
| 182 | ) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 183 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 184 | return &dh |
| 185 | } |
| 186 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 187 | // start save the device to the data model |
| 188 | func (dh *deviceHandler) start(ctx context.Context) { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 189 | 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] | 190 | // Add the initial device to the local model |
| 191 | logger.Debug("device-handler-started") |
| 192 | } |
| 193 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 194 | /* |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 195 | // stop stops the device dh. Not much to do for now |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 196 | func (dh *deviceHandler) stop(ctx context.Context) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 197 | logger.Debug("stopping-device-handler") |
| 198 | dh.exitChannel <- 1 |
| 199 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 200 | */ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 201 | |
| 202 | // ########################################################################################## |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 203 | // deviceHandler methods that implement the adapters interface requests ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 204 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 205 | //adoptOrReconcileDevice adopts the OLT device |
| 206 | func (dh *deviceHandler) adoptOrReconcileDevice(ctx context.Context, device *voltha.Device) { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 207 | 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] | 208 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 209 | logger.Debugw("Device FSM: ", log.Fields{"state": string(dh.pDeviceStateFsm.Current())}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 210 | if dh.pDeviceStateFsm.Is(devStNull) { |
| 211 | if err := dh.pDeviceStateFsm.Event(devEvDeviceInit); err != nil { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 212 | logger.Errorw("Device FSM: Can't go to state DeviceInit", log.Fields{"err": err}) |
| 213 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 214 | logger.Debugw("Device FSM: ", log.Fields{"state": string(dh.pDeviceStateFsm.Current())}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 215 | } else { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 216 | 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] | 217 | } |
| 218 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 221 | func (dh *deviceHandler) processInterAdapterOMCIReqMessage(msg *ic.InterAdapterMessage) error { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 222 | msgBody := msg.GetBody() |
| 223 | omciMsg := &ic.InterAdapterOmciMessage{} |
| 224 | if err := ptypes.UnmarshalAny(msgBody, omciMsg); err != nil { |
| 225 | logger.Warnw("cannot-unmarshal-omci-msg-body", log.Fields{ |
| 226 | "device-id": dh.deviceID, "error": err}) |
| 227 | return err |
| 228 | } |
| 229 | |
| 230 | //assuming omci message content is hex coded! |
| 231 | // with restricted output of 16(?) bytes would be ...omciMsg.Message[:16] |
| 232 | logger.Debugw("inter-adapter-recv-omci", log.Fields{ |
| 233 | "device-id": dh.deviceID, "RxOmciMessage": hex.EncodeToString(omciMsg.Message)}) |
| 234 | //receive_message(omci_msg.message) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 235 | pDevEntry := dh.getOnuDeviceEntry(true) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 236 | if pDevEntry != nil { |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame^] | 237 | if pDevEntry.PDevOmciCC != nil { |
| 238 | return pDevEntry.PDevOmciCC.receiveMessage(context.TODO(), omciMsg.Message) |
| 239 | } |
| 240 | logger.Debugw("omciCC not ready to receive omci messages - incoming omci message ignored", log.Fields{"rxMsg": omciMsg.Message}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 241 | } |
| 242 | logger.Errorw("No valid OnuDevice -aborting", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 243 | return fmt.Errorf("no valid OnuDevice: %s", dh.deviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 244 | } |
| 245 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 246 | func (dh *deviceHandler) processInterAdapterONUIndReqMessage(msg *ic.InterAdapterMessage) error { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 247 | msgBody := msg.GetBody() |
| 248 | onuIndication := &oop.OnuIndication{} |
| 249 | if err := ptypes.UnmarshalAny(msgBody, onuIndication); err != nil { |
| 250 | logger.Warnw("cannot-unmarshal-onu-indication-msg-body", log.Fields{ |
| 251 | "device-id": dh.deviceID, "error": err}) |
| 252 | return err |
| 253 | } |
| 254 | |
| 255 | onuOperstate := onuIndication.GetOperState() |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 256 | logger.Debugw("inter-adapter-recv-onu-ind", log.Fields{"device-id": dh.deviceID, |
| 257 | "OnuId": onuIndication.GetOnuId(), |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 258 | "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate, |
| 259 | "SNR": onuIndication.GetSerialNumber()}) |
| 260 | |
| 261 | //interface related functions might be error checked .... |
| 262 | if onuOperstate == "up" { |
| 263 | _ = dh.createInterface(onuIndication) |
| 264 | } else if (onuOperstate == "down") || (onuOperstate == "unreachable") { |
| 265 | _ = dh.updateInterface(onuIndication) |
| 266 | } else { |
| 267 | logger.Errorw("unknown-onu-indication operState", log.Fields{"OnuId": onuIndication.GetOnuId()}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 268 | return fmt.Errorf("invalidOperState: %s, %s", onuOperstate, dh.deviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 269 | } |
| 270 | return nil |
| 271 | } |
| 272 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 273 | func (dh *deviceHandler) processInterAdapterTechProfileDownloadReqMessage( |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 274 | msg *ic.InterAdapterMessage) error { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 275 | |
| 276 | pDevEntry := dh.getOnuDeviceEntry(true) |
| 277 | if pDevEntry == nil { |
| 278 | logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": dh.deviceID}) |
| 279 | return fmt.Errorf("no valid OnuDevice: %s", dh.deviceID) |
| 280 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 281 | if dh.pOnuTP == nil { |
| 282 | //should normally not happen ... |
| 283 | logger.Warnw("onuTechProf instance not set up for DLMsg request - ignoring request", |
| 284 | log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 285 | return fmt.Errorf("techProfile DLMsg request while onuTechProf instance not setup: %s", dh.deviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 286 | } |
| 287 | if (dh.deviceReason == "stopping-openomci") || (dh.deviceReason == "omci-admin-lock") { |
| 288 | // I've seen cases for this request, where the device was already stopped |
| 289 | logger.Warnw("TechProf stopped: device-unreachable", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 290 | return fmt.Errorf("device-unreachable: %s", dh.deviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | msgBody := msg.GetBody() |
| 294 | techProfMsg := &ic.InterAdapterTechProfileDownloadMessage{} |
| 295 | if err := ptypes.UnmarshalAny(msgBody, techProfMsg); err != nil { |
| 296 | logger.Warnw("cannot-unmarshal-techprof-msg-body", log.Fields{ |
| 297 | "device-id": dh.deviceID, "error": err}) |
| 298 | return err |
| 299 | } |
| 300 | |
| 301 | // we have to lock access to TechProfile processing based on different messageType calls or |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 302 | // even to fast subsequent calls of the same messageType as well as OnuKVStore processing due |
| 303 | // to possible concurrent access by flow processing |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 304 | dh.pOnuTP.lockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 305 | defer dh.pOnuTP.unlockTpProcMutex() |
| 306 | pDevEntry.lockOnuKVStoreMutex() |
| 307 | defer pDevEntry.unlockOnuKVStoreMutex() |
| 308 | |
| 309 | if techProfMsg.UniId > 255 { |
| 310 | return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s", |
| 311 | techProfMsg.UniId, dh.deviceID)) |
| 312 | } |
| 313 | uniID := uint8(techProfMsg.UniId) |
| 314 | |
| 315 | if bTpModify := pDevEntry.updateOnuUniTpPath(uniID, techProfMsg.Path); bTpModify { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 316 | // if there has been some change for some uni TechProfilePath |
| 317 | //in order to allow concurrent calls to other dh instances we do not wait for execution here |
| 318 | //but doing so we can not indicate problems to the caller (who does what with that then?) |
| 319 | //by now we just assume straightforward successful execution |
| 320 | //TODO!!! Generally: In this scheme it would be good to have some means to indicate |
| 321 | // possible problems to the caller later autonomously |
| 322 | |
| 323 | // deadline context to ensure completion of background routines waited for |
| 324 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 325 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 326 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 327 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 328 | dh.pOnuTP.resetTpProcessingErrorIndication() |
| 329 | pDevEntry.resetKvProcessingErrorIndication() |
| 330 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 331 | var wg sync.WaitGroup |
| 332 | wg.Add(2) // for the 2 go routines to finish |
| 333 | // attention: deadline completion check and wg.Done is to be done in both routines |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 334 | go dh.pOnuTP.configureUniTp(dctx, uniID, techProfMsg.Path, &wg) |
| 335 | go pDevEntry.updateOnuKvStore(dctx, &wg) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 336 | dh.waitForCompletion(cancel, &wg, "TechProfDwld") //wait for background process to finish |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 337 | |
| 338 | return dh.combineErrorStrings(dh.pOnuTP.getTpProcessingErrorIndication(), pDevEntry.getKvProcessingErrorIndication()) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 339 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 340 | // no change, nothing really to do - return success |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 341 | return nil |
| 342 | } |
| 343 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 344 | func (dh *deviceHandler) processInterAdapterDeleteGemPortReqMessage( |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 345 | msg *ic.InterAdapterMessage) error { |
| 346 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 347 | pDevEntry := dh.getOnuDeviceEntry(true) |
| 348 | if pDevEntry == nil { |
| 349 | logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": dh.deviceID}) |
| 350 | return fmt.Errorf("no valid OnuDevice: %s", dh.deviceID) |
| 351 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 352 | if dh.pOnuTP == nil { |
| 353 | //should normally not happen ... |
| 354 | logger.Warnw("onuTechProf instance not set up for DelGem request - ignoring request", |
| 355 | log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 356 | return fmt.Errorf("techProfile DelGem request while onuTechProf instance not setup: %s", dh.deviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | msgBody := msg.GetBody() |
| 360 | delGemPortMsg := &ic.InterAdapterDeleteGemPortMessage{} |
| 361 | if err := ptypes.UnmarshalAny(msgBody, delGemPortMsg); err != nil { |
| 362 | logger.Warnw("cannot-unmarshal-delete-gem-msg-body", log.Fields{ |
| 363 | "device-id": dh.deviceID, "error": err}) |
| 364 | return err |
| 365 | } |
| 366 | |
| 367 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
| 368 | dh.pOnuTP.lockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 369 | defer dh.pOnuTP.unlockTpProcMutex() |
| 370 | pDevEntry.lockOnuKVStoreMutex() |
| 371 | defer pDevEntry.unlockOnuKVStoreMutex() |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 372 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 373 | if delGemPortMsg.UniId > 255 { |
| 374 | return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s", |
| 375 | delGemPortMsg.UniId, dh.deviceID)) |
| 376 | } |
| 377 | uniID := uint8(delGemPortMsg.UniId) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 378 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 379 | if bTpModify := pDevEntry.updateOnuUniTpPath(uniID, ""); bTpModify { |
| 380 | // deadline context to ensure completion of background routines waited for |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 381 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 382 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 383 | |
| 384 | dh.pOnuTP.resetTpProcessingErrorIndication() |
| 385 | pDevEntry.resetKvProcessingErrorIndication() |
| 386 | |
| 387 | var wg sync.WaitGroup |
| 388 | wg.Add(2) // for the 2 go routines to finish |
| 389 | go pDevEntry.deleteTpResource(dctx, uniID, delGemPortMsg.TpPath, |
| 390 | cResourceGemPort, delGemPortMsg.GemPortId, &wg) |
| 391 | // Removal of the tcont/alloc id mapping represents the removal of the tech profile |
| 392 | go pDevEntry.updateOnuKvStore(dctx, &wg) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 393 | dh.waitForCompletion(cancel, &wg, "GemDelete") //wait for background process to finish |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 394 | |
| 395 | return dh.combineErrorStrings(dh.pOnuTP.getTpProcessingErrorIndication(), pDevEntry.getKvProcessingErrorIndication()) |
| 396 | } |
| 397 | return nil |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 398 | } |
| 399 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 400 | func (dh *deviceHandler) processInterAdapterDeleteTcontReqMessage( |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 401 | msg *ic.InterAdapterMessage) error { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 402 | |
| 403 | pDevEntry := dh.getOnuDeviceEntry(true) |
| 404 | if pDevEntry == nil { |
| 405 | logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": dh.deviceID}) |
| 406 | return fmt.Errorf("no valid OnuDevice: %s", dh.deviceID) |
| 407 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 408 | if dh.pOnuTP == nil { |
| 409 | //should normally not happen ... |
| 410 | logger.Warnw("onuTechProf instance not set up for DelTcont request - ignoring request", |
| 411 | log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 412 | return fmt.Errorf("techProfile DelTcont request while onuTechProf instance not setup: %s", dh.deviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | msgBody := msg.GetBody() |
| 416 | delTcontMsg := &ic.InterAdapterDeleteTcontMessage{} |
| 417 | if err := ptypes.UnmarshalAny(msgBody, delTcontMsg); err != nil { |
| 418 | logger.Warnw("cannot-unmarshal-delete-tcont-msg-body", log.Fields{ |
| 419 | "device-id": dh.deviceID, "error": err}) |
| 420 | return err |
| 421 | } |
| 422 | |
| 423 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
| 424 | dh.pOnuTP.lockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 425 | defer dh.pOnuTP.unlockTpProcMutex() |
| 426 | pDevEntry.lockOnuKVStoreMutex() |
| 427 | defer pDevEntry.unlockOnuKVStoreMutex() |
| 428 | |
| 429 | if delTcontMsg.UniId > 255 { |
| 430 | return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s", |
| 431 | delTcontMsg.UniId, dh.deviceID)) |
| 432 | } |
| 433 | uniID := uint8(delTcontMsg.UniId) |
| 434 | |
| 435 | if bTpModify := pDevEntry.updateOnuUniTpPath(uniID, ""); bTpModify { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 436 | // deadline context to ensure completion of background routines waited for |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 437 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 438 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 439 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 440 | dh.pOnuTP.resetTpProcessingErrorIndication() |
| 441 | pDevEntry.resetKvProcessingErrorIndication() |
| 442 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 443 | var wg sync.WaitGroup |
| 444 | wg.Add(2) // for the 2 go routines to finish |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 445 | go pDevEntry.deleteTpResource(dctx, uniID, delTcontMsg.TpPath, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 446 | cResourceTcont, delTcontMsg.AllocId, &wg) |
| 447 | // Removal of the tcont/alloc id mapping represents the removal of the tech profile |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 448 | go pDevEntry.updateOnuKvStore(dctx, &wg) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 449 | dh.waitForCompletion(cancel, &wg, "TContDelete") //wait for background process to finish |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 450 | |
| 451 | return dh.combineErrorStrings(dh.pOnuTP.getTpProcessingErrorIndication(), pDevEntry.getKvProcessingErrorIndication()) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 452 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 453 | return nil |
| 454 | } |
| 455 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 456 | //processInterAdapterMessage sends the proxied messages to the target device |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 457 | // If the proxy address is not found in the unmarshalled message, it first fetches the onu device for which the message |
| 458 | // is meant, and then send the unmarshalled omci message to this onu |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 459 | func (dh *deviceHandler) processInterAdapterMessage(msg *ic.InterAdapterMessage) error { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 460 | msgID := msg.Header.Id |
| 461 | msgType := msg.Header.Type |
| 462 | fromTopic := msg.Header.FromTopic |
| 463 | toTopic := msg.Header.ToTopic |
| 464 | toDeviceID := msg.Header.ToDeviceId |
| 465 | proxyDeviceID := msg.Header.ProxyDeviceId |
| 466 | logger.Debugw("InterAdapter message header", log.Fields{"msgID": msgID, "msgType": msgType, |
| 467 | "fromTopic": fromTopic, "toTopic": toTopic, "toDeviceID": toDeviceID, "proxyDeviceID": proxyDeviceID}) |
| 468 | |
| 469 | switch msgType { |
| 470 | case ic.InterAdapterMessageType_OMCI_REQUEST: |
| 471 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 472 | return dh.processInterAdapterOMCIReqMessage(msg) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 473 | } |
| 474 | case ic.InterAdapterMessageType_ONU_IND_REQUEST: |
| 475 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 476 | return dh.processInterAdapterONUIndReqMessage(msg) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 477 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 478 | case ic.InterAdapterMessageType_TECH_PROFILE_DOWNLOAD_REQUEST: |
| 479 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 480 | return dh.processInterAdapterTechProfileDownloadReqMessage(msg) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 481 | } |
| 482 | case ic.InterAdapterMessageType_DELETE_GEM_PORT_REQUEST: |
| 483 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 484 | return dh.processInterAdapterDeleteGemPortReqMessage(msg) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 485 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 486 | } |
| 487 | case ic.InterAdapterMessageType_DELETE_TCONT_REQUEST: |
| 488 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 489 | return dh.processInterAdapterDeleteTcontReqMessage(msg) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 490 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 491 | default: |
| 492 | { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 493 | logger.Errorw("inter-adapter-unhandled-type", log.Fields{ |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 494 | "msgType": msg.Header.Type, "device-id": dh.deviceID}) |
| 495 | return fmt.Errorf("inter-adapter-unhandled-type: %d, %s", msg.Header.Type, dh.deviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 496 | } |
| 497 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 498 | } |
| 499 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 500 | //FlowUpdateIncremental removes and/or adds the flow changes on a given device |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 501 | func (dh *deviceHandler) FlowUpdateIncremental(apOfFlowChanges *openflow_13.FlowChanges, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 502 | apOfGroupChanges *openflow_13.FlowGroupChanges, apFlowMetaData *voltha.FlowMetadata) error { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 503 | logger.Debugw("FlowUpdateIncremental started", log.Fields{"device-id": dh.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 504 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 505 | var retError error = nil |
| 506 | //Remove flows (always remove flows first - remove old and add new with same cookie may be part of the same request) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 507 | if apOfFlowChanges.ToRemove != nil { |
| 508 | for _, flowItem := range apOfFlowChanges.ToRemove.Items { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 509 | if flowItem.GetCookie() == 0 { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 510 | logger.Warnw("flow-remove no cookie: ignore and continuing on checking further flows", log.Fields{ |
| 511 | "device-id": dh.deviceID}) |
| 512 | retError = fmt.Errorf("flow-remove no cookie, device-id %s", dh.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 513 | continue |
| 514 | } |
| 515 | flowInPort := flow.GetInPort(flowItem) |
| 516 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 517 | logger.Warnw("flow-remove inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.deviceID}) |
| 518 | retError = fmt.Errorf("flow-remove inPort invalid, device-id %s", dh.deviceID) |
| 519 | continue |
| 520 | //return fmt.Errorf("flow inPort invalid: %s", dh.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 521 | } else if flowInPort == dh.ponPortNumber { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 522 | //this is some downstream flow, not regarded as error, just ignored |
| 523 | logger.Debugw("flow-remove for downstream: ignore and continuing on checking further flows", log.Fields{ |
| 524 | "device-id": dh.deviceID, "inPort": flowInPort}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 525 | continue |
| 526 | } else { |
| 527 | // this is the relevant upstream flow |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 528 | var loUniPort *onuUniPort |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 529 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 530 | loUniPort = uniPort |
| 531 | } else { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 532 | logger.Warnw("flow-remove inPort not found in UniPorts: ignore and continuing on checking further flows", |
| 533 | log.Fields{"device-id": dh.deviceID, "inPort": flowInPort}) |
| 534 | retError = fmt.Errorf("flow-remove inPort not found in UniPorts, inPort %d, device-id %s", |
| 535 | flowInPort, dh.deviceID) |
| 536 | continue |
| 537 | //return fmt.Errorf("flow-parameter inPort %d not found in internal UniPorts", flowInPort) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 538 | } |
| 539 | flowOutPort := flow.GetOutPort(flowItem) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 540 | logger.Debugw("flow-remove port indications", log.Fields{ |
| 541 | "device-id": dh.deviceID, "inPort": flowInPort, "outPort": flowOutPort, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 542 | "uniPortName": loUniPort.name}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 543 | err := dh.removeFlowItemFromUniPort(flowItem, loUniPort) |
| 544 | //try next flow after processing error |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 545 | if err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 546 | logger.Warnw("flow-remove processing error: continuing on checking further flows", |
| 547 | log.Fields{"device-id": dh.deviceID, "error": err}) |
| 548 | retError = err |
| 549 | continue |
| 550 | //return err |
| 551 | } else { // if last setting succeeds, overwrite possibly previously set error |
| 552 | retError = nil |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | } |
| 556 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 557 | if apOfFlowChanges.ToAdd != nil { |
| 558 | for _, flowItem := range apOfFlowChanges.ToAdd.Items { |
| 559 | if flowItem.GetCookie() == 0 { |
| 560 | logger.Debugw("incremental flow-add no cookie: ignore and continuing on checking further flows", log.Fields{ |
| 561 | "device-id": dh.deviceID}) |
| 562 | retError = fmt.Errorf("flow-add no cookie, device-id %s", dh.deviceID) |
| 563 | continue |
| 564 | } |
| 565 | flowInPort := flow.GetInPort(flowItem) |
| 566 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
| 567 | logger.Warnw("flow-add inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.deviceID}) |
| 568 | retError = fmt.Errorf("flow-add inPort invalid, device-id %s", dh.deviceID) |
| 569 | continue |
| 570 | //return fmt.Errorf("flow inPort invalid: %s", dh.deviceID) |
| 571 | } else if flowInPort == dh.ponPortNumber { |
| 572 | //this is some downstream flow |
| 573 | logger.Debugw("flow-add for downstream: ignore and continuing on checking further flows", log.Fields{ |
| 574 | "device-id": dh.deviceID, "inPort": flowInPort}) |
| 575 | continue |
| 576 | } else { |
| 577 | // this is the relevant upstream flow |
| 578 | var loUniPort *onuUniPort |
| 579 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 580 | loUniPort = uniPort |
| 581 | } else { |
| 582 | logger.Warnw("flow-add inPort not found in UniPorts: ignore and continuing on checking further flows", |
| 583 | log.Fields{"device-id": dh.deviceID, "inPort": flowInPort}) |
| 584 | retError = fmt.Errorf("flow-add inPort not found in UniPorts, inPort %d, device-id %s", |
| 585 | flowInPort, dh.deviceID) |
| 586 | continue |
| 587 | //return fmt.Errorf("flow-parameter inPort %d not found in internal UniPorts", flowInPort) |
| 588 | } |
| 589 | flowOutPort := flow.GetOutPort(flowItem) |
| 590 | logger.Debugw("flow-add port indications", log.Fields{ |
| 591 | "device-id": dh.deviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 592 | "uniPortName": loUniPort.name}) |
| 593 | err := dh.addFlowItemToUniPort(flowItem, loUniPort) |
| 594 | //try next flow after processing error |
| 595 | if err != nil { |
| 596 | logger.Warnw("flow-add processing error: continuing on checking further flows", |
| 597 | log.Fields{"device-id": dh.deviceID, "error": err}) |
| 598 | retError = err |
| 599 | continue |
| 600 | //return err |
| 601 | } else { // if last setting succeeds, overwrite possibly previously set error |
| 602 | retError = nil |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | return retError |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 608 | } |
| 609 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 610 | //disableDevice locks the ONU and its UNI/VEIP ports (admin lock via OMCI) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 611 | func (dh *deviceHandler) disableDevice(device *voltha.Device) { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 612 | 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] | 613 | |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 614 | //admin-lock reason can also be used uniquely for setting the DeviceState accordingly |
| 615 | // - inblock state checking to prevent possibly unneeded processing (on command repitition) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 616 | if dh.deviceReason != "omci-admin-lock" { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 617 | //running FSM's are stopped/reset here to avoid indirect stucking |
| 618 | // due to blocked OMCI transmission on disabled state |
| 619 | // but with possibly aborted FSM's there might be complications as the expected state |
| 620 | // after some re-enable would then be quite undefined |
| 621 | // maybe after re-enabling some additional checks would be required to possibly enforce new |
| 622 | // (reconcile-like) config (which would require some indication from 'aborted' FSM's first) |
| 623 | // for now let's assume no running FSM is active at this time point here ... -> TODO!!! |
| 624 | if err := dh.resetFsms(); err != nil { |
| 625 | logger.Errorw("error-disableDevice at FSM stop", |
| 626 | log.Fields{"device-id": dh.deviceID, "error": err}) |
| 627 | // abort: system behavior is just unstable ... |
| 628 | return |
| 629 | } |
| 630 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 631 | if dh.deviceReason != "rebooting" { |
| 632 | // disable UNI ports/ONU |
| 633 | // *** should generate UniDisableStateDone event - used to disable the port(s) on success |
| 634 | if dh.pLockStateFsm == nil { |
| 635 | dh.createUniLockFsm(true, UniDisableStateDone) |
| 636 | } else { //LockStateFSM already init |
| 637 | dh.pLockStateFsm.setSuccessEvent(UniDisableStateDone) |
| 638 | dh.runUniLockFsm(true) |
| 639 | } |
| 640 | } else { |
| 641 | logger.Debugw("DeviceStateUpdate upon disable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
| 642 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.deviceID}) |
| 643 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), |
| 644 | dh.deviceID, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN); err != nil { |
| 645 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 646 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 647 | } |
| 648 | |
| 649 | logger.Debugw("DeviceReasonUpdate upon re-enable", log.Fields{ |
| 650 | "reason": "omci-admin-lock", "device-id": dh.deviceID}) |
| 651 | // DeviceReason to update acc.to modified py code as per beginning of Sept 2020 |
| 652 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "omci-admin-lock"); err != nil { |
| 653 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 654 | logger.Errorw("error-updating-reason-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 655 | } |
| 656 | dh.deviceReason = "omci-admin-lock" |
| 657 | |
| 658 | //stop the device entry which resets the attached omciCC |
| 659 | pDevEntry := dh.getOnuDeviceEntry(false) |
| 660 | if pDevEntry == nil { |
| 661 | logger.Errorw("No valid OnuDevice -aborting", log.Fields{"device-id": dh.deviceID}) |
| 662 | return |
| 663 | } |
| 664 | _ = pDevEntry.stop(context.TODO(), true) //stop deviceEntry with omciCC reset |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 665 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 669 | //reEnableDevice unlocks the ONU and its UNI/VEIP ports (admin unlock via OMCI) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 670 | func (dh *deviceHandler) reEnableDevice(device *voltha.Device) { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 671 | logger.Debugw("reenable-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 672 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 673 | // enable ONU/UNI ports |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 674 | // *** should generate UniEnableStateDone event - used to disable the port(s) on success |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 675 | if dh.pUnlockStateFsm == nil { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 676 | dh.createUniLockFsm(false, UniEnableStateDone) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 677 | } else { //UnlockStateFSM already init |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 678 | dh.pUnlockStateFsm.setSuccessEvent(UniEnableStateDone) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 679 | dh.runUniLockFsm(false) |
| 680 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 681 | } |
| 682 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 683 | func (dh *deviceHandler) reconcileDeviceOnuInd() { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 684 | logger.Debugw("reconciling - simulate onu indication", log.Fields{"device-id": dh.deviceID}) |
| 685 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 686 | pDevEntry := dh.getOnuDeviceEntry(true) |
| 687 | if pDevEntry == nil { |
| 688 | logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": dh.deviceID}) |
| 689 | return |
| 690 | } |
| 691 | if err := pDevEntry.restoreDataFromOnuKvStore(context.TODO()); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 692 | logger.Errorw("reconciling - restoring OnuTp-data failed - abort", log.Fields{"err": err, "device-id": dh.deviceID}) |
| 693 | dh.reconciling = false |
| 694 | return |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 695 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 696 | var onuIndication oop.OnuIndication |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 697 | onuIndication.IntfId = pDevEntry.sOnuPersistentData.PersIntfID |
| 698 | onuIndication.OnuId = pDevEntry.sOnuPersistentData.PersOnuID |
| 699 | onuIndication.OperState = pDevEntry.sOnuPersistentData.PersOperState |
| 700 | onuIndication.AdminState = pDevEntry.sOnuPersistentData.PersAdminState |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 701 | _ = dh.createInterface(&onuIndication) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 704 | func (dh *deviceHandler) reconcileDeviceTechProf() { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 705 | logger.Debugw("reconciling - trigger tech profile config", log.Fields{"device-id": dh.deviceID}) |
| 706 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 707 | pDevEntry := dh.getOnuDeviceEntry(true) |
| 708 | if pDevEntry == nil { |
| 709 | logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": dh.deviceID}) |
| 710 | return |
| 711 | } |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 712 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 713 | dh.pOnuTP.lockTpProcMutex() |
| 714 | defer dh.pOnuTP.unlockTpProcMutex() |
| 715 | |
| 716 | for _, uniData := range pDevEntry.sOnuPersistentData.PersUniConfig { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 717 | // deadline context to ensure completion of background routines waited for |
| 718 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 719 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 720 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 721 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 722 | dh.pOnuTP.resetTpProcessingErrorIndication() |
| 723 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 724 | var wg sync.WaitGroup |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 725 | wg.Add(1) // for the 1 go routine to finish |
| 726 | go dh.pOnuTP.configureUniTp(dctx, uniData.PersUniID, uniData.PersTpPath, &wg) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 727 | dh.waitForCompletion(cancel, &wg, "TechProfReconcile") //wait for background process to finish |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 728 | |
| 729 | if err := dh.pOnuTP.getTpProcessingErrorIndication(); err != nil { |
| 730 | logger.Errorw(err.Error(), log.Fields{"device-id": dh.deviceID}) |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | func (dh *deviceHandler) reconcileDeviceFlowConfig() { |
| 736 | logger.Debugw("reconciling - trigger flow config", log.Fields{"device-id": dh.deviceID}) |
| 737 | |
| 738 | pDevEntry := dh.getOnuDeviceEntry(true) |
| 739 | if pDevEntry == nil { |
| 740 | logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 741 | return |
| 742 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 743 | for _, uniData := range pDevEntry.sOnuPersistentData.PersUniConfig { |
| 744 | var uniPort *onuUniPort |
| 745 | var exist bool |
| 746 | uniNo := mkUniPortNum(dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), uint32(uniData.PersUniID)) |
| 747 | if uniPort, exist = dh.uniEntityMap[uniNo]; !exist { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 748 | logger.Errorw("onuUniPort data not found!", log.Fields{"uniNo": uniNo, "device-id": dh.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 749 | return |
| 750 | } |
| 751 | for _, flowData := range uniData.PersFlowParams { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 752 | logger.Debugw("add flow with cookie slice", log.Fields{"device-id": dh.deviceID, "cookies": flowData.CookieSlice}) |
| 753 | //the slice can be passed 'by value' here, - which internally passes its reference copy |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 754 | if _, exist = dh.UniVlanConfigFsmMap[uniData.PersUniID]; exist { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 755 | if err := dh.UniVlanConfigFsmMap[uniData.PersUniID].SetUniFlowParams(flowData.VlanRuleParams.TpID, |
| 756 | flowData.CookieSlice, uint16(flowData.VlanRuleParams.MatchVid), uint16(flowData.VlanRuleParams.SetVid), |
| 757 | uint8(flowData.VlanRuleParams.SetPcp)); err != nil { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 758 | logger.Errorw(err.Error(), log.Fields{"device-id": dh.deviceID}) |
| 759 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 760 | } else { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 761 | if err := dh.createVlanFilterFsm(uniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice, |
| 762 | uint16(flowData.VlanRuleParams.MatchVid), uint16(flowData.VlanRuleParams.SetVid), |
| 763 | uint8(flowData.VlanRuleParams.SetPcp), OmciVlanFilterDone); err != nil { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 764 | logger.Errorw(err.Error(), log.Fields{"device-id": dh.deviceID}) |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | func (dh *deviceHandler) reconcileMetrics() { |
| 772 | logger.Debugw("reconciling - trigger metrics - to be implemented in scope of VOL-3324!", log.Fields{"device-id": dh.deviceID}) |
| 773 | |
| 774 | //TODO: reset of reconciling-flag has always to be done in the last reconcile*() function |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 775 | dh.reconciling = false |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 778 | func (dh *deviceHandler) deleteDevice(device *voltha.Device) error { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 779 | logger.Debugw("delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 780 | |
| 781 | pDevEntry := dh.getOnuDeviceEntry(true) |
| 782 | if pDevEntry == nil { |
| 783 | logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": dh.deviceID}) |
| 784 | return fmt.Errorf("no valid OnuDevice: %s", dh.deviceID) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 785 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 786 | pDevEntry.lockOnuKVStoreMutex() |
| 787 | defer pDevEntry.unlockOnuKVStoreMutex() |
| 788 | |
| 789 | // deadline context to ensure completion of background routines waited for |
| 790 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 791 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 792 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 793 | |
| 794 | pDevEntry.resetKvProcessingErrorIndication() |
| 795 | |
| 796 | var wg sync.WaitGroup |
| 797 | wg.Add(1) // for the 1 go routine to finish |
| 798 | go pDevEntry.deleteDataFromOnuKvStore(dctx, &wg) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 799 | dh.waitForCompletion(cancel, &wg, "DeleteDevice") //wait for background process to finish |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 800 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 801 | // TODO: further actions - stop metrics and FSMs, remove device ... |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 802 | return pDevEntry.getKvProcessingErrorIndication() |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 805 | func (dh *deviceHandler) rebootDevice(device *voltha.Device) error { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 806 | logger.Debugw("reboot-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 807 | if device.ConnectStatus != voltha.ConnectStatus_REACHABLE { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 808 | logger.Errorw("device-unreachable", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 809 | return fmt.Errorf("device-unreachable: %s, %s", dh.deviceID, device.SerialNumber) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 810 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 811 | if err := dh.pOnuOmciDevice.reboot(context.TODO()); err != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 812 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 813 | logger.Errorw("error-rebooting-device", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 814 | return err |
| 815 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 816 | |
| 817 | //transfer the possibly modified logical uni port state |
| 818 | dh.disableUniPortStateUpdate() |
| 819 | |
Andrea Campanella | bef4e54 | 2020-10-22 11:01:28 +0200 | [diff] [blame] | 820 | logger.Debugw("call DeviceStateUpdate upon reboot", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 821 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.deviceID}) |
Andrea Campanella | bef4e54 | 2020-10-22 11:01:28 +0200 | [diff] [blame] | 822 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, voltha.ConnectStatus_REACHABLE, |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 823 | voltha.OperStatus_DISCOVERED); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 824 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 825 | 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] | 826 | return err |
| 827 | } |
Andrea Campanella | bef4e54 | 2020-10-22 11:01:28 +0200 | [diff] [blame] | 828 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "rebooting"); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 829 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 830 | 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] | 831 | return err |
| 832 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 833 | dh.deviceReason = "rebooting" |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 834 | return nil |
| 835 | } |
| 836 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 837 | // deviceHandler methods that implement the adapters interface requests## end ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 838 | // ##################################################################################### |
| 839 | |
| 840 | // ################ to be updated acc. needs of ONU Device ######################## |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 841 | // deviceHandler StateMachine related state transition methods ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 842 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 843 | func (dh *deviceHandler) logStateChange(e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 844 | 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}) |
| 845 | } |
| 846 | |
| 847 | // doStateInit provides the device update to the core |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 848 | func (dh *deviceHandler) doStateInit(e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 849 | |
| 850 | logger.Debug("doStateInit-started") |
| 851 | var err error |
| 852 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 853 | // populate what we know. rest comes later after mib sync |
| 854 | dh.device.Root = false |
| 855 | dh.device.Vendor = "OpenONU" |
| 856 | dh.device.Model = "go" |
| 857 | dh.device.Reason = "activating-onu" |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 858 | dh.deviceReason = "activating-onu" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 859 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 860 | dh.logicalDeviceID = dh.deviceID // really needed - what for ??? //TODO!!! |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 861 | |
| 862 | if !dh.reconciling { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 863 | _ = dh.coreProxy.DeviceUpdate(context.TODO(), dh.device) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 864 | } else { |
| 865 | logger.Debugw("reconciling - don't notify core about DeviceUpdate", |
| 866 | log.Fields{"device-id": dh.deviceID}) |
| 867 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 868 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 869 | dh.parentID = dh.device.ParentId |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 870 | dh.ponPortNumber = dh.device.ParentPortNo |
| 871 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 872 | // store proxy parameters for later communication - assumption: invariant, else they have to be requested dynamically!! |
| 873 | dh.ProxyAddressID = dh.device.ProxyAddress.GetDeviceId() |
| 874 | dh.ProxyAddressType = dh.device.ProxyAddress.GetDeviceType() |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 875 | 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] | 876 | "proxyAddressType": dh.ProxyAddressType, "SNR": dh.device.SerialNumber, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 877 | "ParentId": dh.parentID, "ParentPortNo": dh.ponPortNumber}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 878 | |
| 879 | /* |
| 880 | self._pon = PonPort.create(self, self._pon_port_number) |
| 881 | self._pon.add_peer(self.parent_id, self._pon_port_number) |
| 882 | self.logger.debug('adding-pon-port-to-agent', |
| 883 | type=self._pon.get_port().type, |
| 884 | admin_state=self._pon.get_port().admin_state, |
| 885 | oper_status=self._pon.get_port().oper_status, |
| 886 | ) |
| 887 | */ |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 888 | if !dh.reconciling { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 889 | logger.Debugw("adding-pon-port", log.Fields{"device-id": dh.deviceID, "ponPortNo": dh.ponPortNumber}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 890 | var ponPortNo uint32 = 1 |
| 891 | if dh.ponPortNumber != 0 { |
| 892 | ponPortNo = dh.ponPortNumber |
| 893 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 894 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 895 | pPonPort := &voltha.Port{ |
| 896 | PortNo: ponPortNo, |
| 897 | Label: fmt.Sprintf("pon-%d", ponPortNo), |
| 898 | Type: voltha.Port_PON_ONU, |
| 899 | OperStatus: voltha.OperStatus_ACTIVE, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 900 | Peers: []*voltha.Port_PeerPort{{DeviceId: dh.parentID, // Peer device is OLT |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 901 | PortNo: ponPortNo}}, // Peer port is parent's port number |
| 902 | } |
| 903 | if err = dh.coreProxy.PortCreated(context.TODO(), dh.deviceID, pPonPort); err != nil { |
| 904 | logger.Fatalf("Device FSM: PortCreated-failed-%s", err) |
| 905 | e.Cancel(err) |
| 906 | return |
| 907 | } |
| 908 | } else { |
| 909 | 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] | 910 | } |
| 911 | logger.Debug("doStateInit-done") |
| 912 | } |
| 913 | |
| 914 | // postInit setups the DeviceEntry for the conerned device |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 915 | func (dh *deviceHandler) postInit(e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 916 | |
| 917 | logger.Debug("postInit-started") |
| 918 | var err error |
| 919 | /* |
| 920 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
| 921 | dh.pTransitionMap.Handle(ctx, GrpcConnected) |
| 922 | return nil |
| 923 | */ |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 924 | if err = dh.addOnuDeviceEntry(context.TODO()); err != nil { |
| 925 | logger.Fatalf("Device FSM: addOnuDeviceEntry-failed-%s", err) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 926 | e.Cancel(err) |
| 927 | return |
| 928 | } |
| 929 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 930 | if dh.reconciling { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 931 | go dh.reconcileDeviceOnuInd() |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 932 | // reconcilement will be continued after mib download is done |
| 933 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 934 | /* |
| 935 | ############################################################################ |
| 936 | # Setup Alarm handler |
| 937 | self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id, |
| 938 | device.serial_number) |
| 939 | ############################################################################ |
| 940 | # Setup PM configuration for this device |
| 941 | # Pass in ONU specific options |
| 942 | kwargs = { |
| 943 | OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY, |
| 944 | 'heartbeat': self.heartbeat, |
| 945 | OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device |
| 946 | } |
| 947 | self.logger.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number) |
| 948 | self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id, |
| 949 | self.logical_device_id, device.serial_number, |
| 950 | grouped=True, freq_override=False, **kwargs) |
| 951 | pm_config = self._pm_metrics.make_proto() |
| 952 | self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm) |
| 953 | self.logger.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number) |
| 954 | yield self.core_proxy.device_pm_config_update(pm_config, init=True) |
| 955 | |
| 956 | # Note, ONU ID and UNI intf set in add_uni_port method |
| 957 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events, |
| 958 | ani_ports=[self._pon]) |
| 959 | |
| 960 | # Code to Run OMCI Test Action |
| 961 | kwargs_omci_test_action = { |
| 962 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 963 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 964 | } |
| 965 | serial_number = device.serial_number |
| 966 | self._test_request = OmciTestRequest(self.core_proxy, |
| 967 | self.omci_agent, self.device_id, |
| 968 | AniG, serial_number, |
| 969 | self.logical_device_id, |
| 970 | exclusive=False, |
| 971 | **kwargs_omci_test_action) |
| 972 | |
| 973 | self.enabled = True |
| 974 | else: |
| 975 | self.logger.info('onu-already-activated') |
| 976 | */ |
| 977 | logger.Debug("postInit-done") |
| 978 | } |
| 979 | |
| 980 | // doStateConnected get the device info and update to voltha core |
| 981 | // for comparison of the original method (not that easy to uncomment): compare here: |
| 982 | // voltha-openolt-adapter/adaptercore/device_handler.go |
| 983 | // -> this one obviously initiates all communication interfaces of the device ...? |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 984 | func (dh *deviceHandler) doStateConnected(e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 985 | |
| 986 | logger.Debug("doStateConnected-started") |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 987 | err := errors.New("device FSM: function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 988 | e.Cancel(err) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 989 | logger.Debug("doStateConnected-done") |
| 990 | } |
| 991 | |
| 992 | // doStateUp handle the onu up indication and update to voltha core |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 993 | func (dh *deviceHandler) doStateUp(e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 994 | |
| 995 | logger.Debug("doStateUp-started") |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 996 | err := errors.New("device FSM: function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 997 | e.Cancel(err) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 998 | logger.Debug("doStateUp-done") |
| 999 | |
| 1000 | /* |
| 1001 | // Synchronous call to update device state - this method is run in its own go routine |
| 1002 | if err := dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_REACHABLE, |
| 1003 | voltha.OperStatus_ACTIVE); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1004 | logger.Errorw("Failed to update device with OLT UP indication", log.Fields{"device-id": dh.device.Id, "error": err}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1005 | return err |
| 1006 | } |
| 1007 | return nil |
| 1008 | */ |
| 1009 | } |
| 1010 | |
| 1011 | // doStateDown handle the onu down indication |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1012 | func (dh *deviceHandler) doStateDown(e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1013 | |
| 1014 | logger.Debug("doStateDown-started") |
| 1015 | var err error |
| 1016 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1017 | device := dh.device |
| 1018 | if device == nil { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1019 | /*TODO: needs to handle error scenarios */ |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 1020 | logger.Errorw("Failed to fetch handler device", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1021 | e.Cancel(err) |
| 1022 | return |
| 1023 | } |
| 1024 | |
| 1025 | cloned := proto.Clone(device).(*voltha.Device) |
| 1026 | logger.Debugw("do-state-down", log.Fields{"ClonedDeviceID": cloned.Id}) |
| 1027 | /* |
| 1028 | // Update the all ports state on that device to disable |
| 1029 | if er := dh.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_UNKNOWN); er != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1030 | logger.Errorw("updating-ports-failed", log.Fields{"device-id": device.Id, "error": er}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1031 | return er |
| 1032 | } |
| 1033 | |
| 1034 | //Update the device oper state and connection status |
| 1035 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 1036 | cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE |
| 1037 | dh.device = cloned |
| 1038 | |
| 1039 | if er := dh.coreProxy.DeviceStateUpdate(ctx, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1040 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": device.Id, "error": er}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1041 | return er |
| 1042 | } |
| 1043 | |
| 1044 | //get the child device for the parent device |
| 1045 | onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id) |
| 1046 | if err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1047 | logger.Errorw("failed to get child devices information", log.Fields{"device-id": dh.device.Id, "error": err}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1048 | return err |
| 1049 | } |
| 1050 | for _, onuDevice := range onuDevices.Items { |
| 1051 | |
| 1052 | // Update onu state as down in onu adapter |
| 1053 | onuInd := oop.OnuIndication{} |
| 1054 | onuInd.OperState = "down" |
| 1055 | er := dh.AdapterProxy.SendInterAdapterMessage(ctx, &onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, |
| 1056 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 1057 | if er != nil { |
| 1058 | logger.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1059 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "device-id": onuDevice.Id}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1060 | //Do not return here and continue to process other ONUs |
| 1061 | } |
| 1062 | } |
| 1063 | // * Discovered ONUs entries need to be cleared , since after OLT |
| 1064 | // is up, it starts sending discovery indications again* / |
| 1065 | dh.discOnus = sync.Map{} |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1066 | logger.Debugw("do-state-down-end", log.Fields{"device-id": device.Id}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1067 | return nil |
| 1068 | */ |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1069 | err = errors.New("device FSM: function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1070 | e.Cancel(err) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1071 | logger.Debug("doStateDown-done") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1074 | // deviceHandler StateMachine related state transition methods ##### end ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1075 | // ################################################################################# |
| 1076 | |
| 1077 | // ################################################### |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1078 | // deviceHandler utility methods ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1079 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1080 | //getOnuDeviceEntry gets the ONU device entry and may wait until its value is defined |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1081 | func (dh *deviceHandler) getOnuDeviceEntry(aWait bool) *OnuDeviceEntry { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1082 | dh.lockDevice.RLock() |
| 1083 | pOnuDeviceEntry := dh.pOnuOmciDevice |
| 1084 | if aWait && pOnuDeviceEntry == nil { |
| 1085 | //keep the read sema short to allow for subsequent write |
| 1086 | dh.lockDevice.RUnlock() |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1087 | 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] | 1088 | // based on concurrent processing the deviceEntry setup may not yet be finished at his point |
| 1089 | // so it might be needed to wait here for that event with some timeout |
| 1090 | select { |
| 1091 | case <-time.After(60 * time.Second): //timer may be discussed ... |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1092 | 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] | 1093 | return nil |
| 1094 | case <-dh.deviceEntrySet: |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1095 | logger.Debugw("devicEntry ready now - continue", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1096 | // if written now, we can return the written value without sema |
| 1097 | return dh.pOnuOmciDevice |
| 1098 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1099 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1100 | dh.lockDevice.RUnlock() |
| 1101 | return pOnuDeviceEntry |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1104 | //setOnuDeviceEntry sets the ONU device entry within the handler |
| 1105 | func (dh *deviceHandler) setOnuDeviceEntry( |
| 1106 | apDeviceEntry *OnuDeviceEntry, apOnuTp *onuUniTechProf) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1107 | dh.lockDevice.Lock() |
| 1108 | defer dh.lockDevice.Unlock() |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 1109 | dh.pOnuOmciDevice = apDeviceEntry |
| 1110 | dh.pOnuTP = apOnuTp |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1113 | //addOnuDeviceEntry creates a new ONU device or returns the existing |
| 1114 | func (dh *deviceHandler) addOnuDeviceEntry(ctx context.Context) error { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1115 | logger.Debugw("adding-deviceEntry", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1116 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1117 | deviceEntry := dh.getOnuDeviceEntry(false) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1118 | if deviceEntry == nil { |
| 1119 | /* costum_me_map in python code seems always to be None, |
| 1120 | we omit that here first (declaration unclear) -> todo at Adapter specialization ...*/ |
| 1121 | /* also no 'clock' argument - usage open ...*/ |
| 1122 | /* and no alarm_db yet (oo.alarm_db) */ |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1123 | deviceEntry = newOnuDeviceEntry(ctx, dh.deviceID, dh.pOpenOnuAc.KVStoreHost, |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 1124 | dh.pOpenOnuAc.KVStorePort, dh.pOpenOnuAc.KVStoreType, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1125 | dh, dh.coreProxy, dh.AdapterProxy, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1126 | dh.pOpenOnuAc.pSupportedFsms) //nil as FSM pointer would yield deviceEntry internal defaults ... |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1127 | onuTechProfProc := newOnuUniTechProf(ctx, dh) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1128 | //error treatment possible //TODO!!! |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1129 | dh.setOnuDeviceEntry(deviceEntry, onuTechProfProc) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1130 | // fire deviceEntry ready event to spread to possibly waiting processing |
| 1131 | dh.deviceEntrySet <- true |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1132 | logger.Infow("onuDeviceEntry-added", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1133 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1134 | 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] | 1135 | } |
| 1136 | // might be updated with some error handling !!! |
| 1137 | return nil |
| 1138 | } |
| 1139 | |
| 1140 | // doStateInit provides the device update to the core |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1141 | func (dh *deviceHandler) createInterface(onuind *oop.OnuIndication) error { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1142 | logger.Debugw("create_interface-started", log.Fields{"OnuId": onuind.GetOnuId(), |
| 1143 | "OnuIntfId": onuind.GetIntfId(), "OnuSerialNumber": onuind.GetSerialNumber()}) |
| 1144 | |
| 1145 | dh.pOnuIndication = onuind // let's revise if storing the pointer is sufficient... |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1146 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1147 | if !dh.reconciling { |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 1148 | logger.Debugw("call DeviceStateUpdate upon create interface", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
| 1149 | "OperStatus": voltha.OperStatus_ACTIVATING, "device-id": dh.deviceID}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1150 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, |
| 1151 | voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVATING); err != nil { |
| 1152 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1153 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1154 | } |
| 1155 | } else { |
| 1156 | logger.Debugw("reconciling - don't notify core about DeviceStateUpdate to ACTIVATING", |
| 1157 | log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1158 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1159 | // It does not look to me as if makes sense to work with the real core device here, (not the stored clone)? |
| 1160 | // in this code the GetDevice would just make a check if the DeviceID's Device still exists in core |
| 1161 | // 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] | 1162 | // 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] | 1163 | // so let's just try to keep it simple ... |
| 1164 | /* |
| 1165 | device, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, dh.device.Id) |
| 1166 | if err != nil || device == nil { |
| 1167 | //TODO: needs to handle error scenarios |
| 1168 | logger.Errorw("Failed to fetch device device at creating If", log.Fields{"err": err}) |
| 1169 | return errors.New("Voltha Device not found") |
| 1170 | } |
| 1171 | */ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1172 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1173 | pDevEntry := dh.getOnuDeviceEntry(true) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1174 | if pDevEntry != nil { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1175 | if err := pDevEntry.start(context.TODO()); err != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1176 | return err |
| 1177 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1178 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1179 | logger.Errorw("No valid OnuDevice -aborting", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1180 | return fmt.Errorf("no valid OnuDevice: %s", dh.deviceID) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1181 | } |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1182 | if !dh.reconciling { |
| 1183 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "starting-openomci"); err != nil { |
| 1184 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1185 | logger.Errorw("error-DeviceReasonUpdate to starting-openomci", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1186 | } |
| 1187 | } else { |
| 1188 | logger.Debugw("reconciling - don't notify core about DeviceReasonUpdate to starting-openomci", |
| 1189 | log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1190 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1191 | dh.deviceReason = "starting-openomci" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1192 | |
| 1193 | /* this might be a good time for Omci Verify message? */ |
| 1194 | verifyExec := make(chan bool) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1195 | omciVerify := newOmciTestRequest(context.TODO(), |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1196 | dh.device.Id, pDevEntry.PDevOmciCC, |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1197 | true, true) //exclusive and allowFailure (anyway not yet checked) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1198 | omciVerify.performOmciTest(context.TODO(), verifyExec) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1199 | |
| 1200 | /* give the handler some time here to wait for the OMCi verification result |
| 1201 | after Timeout start and try MibUpload FSM anyway |
| 1202 | (to prevent stopping on just not supported OMCI verification from ONU) */ |
| 1203 | select { |
| 1204 | case <-time.After(2 * time.Second): |
| 1205 | logger.Warn("omci start-verification timed out (continue normal)") |
| 1206 | case testresult := <-verifyExec: |
| 1207 | logger.Infow("Omci start verification done", log.Fields{"result": testresult}) |
| 1208 | } |
| 1209 | |
| 1210 | /* In py code it looks earlier (on activate ..) |
| 1211 | # Code to Run OMCI Test Action |
| 1212 | kwargs_omci_test_action = { |
| 1213 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 1214 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 1215 | } |
| 1216 | serial_number = device.serial_number |
| 1217 | self._test_request = OmciTestRequest(self.core_proxy, |
| 1218 | self.omci_agent, self.device_id, |
| 1219 | AniG, serial_number, |
| 1220 | self.logical_device_id, |
| 1221 | exclusive=False, |
| 1222 | **kwargs_omci_test_action) |
| 1223 | ... |
| 1224 | # Start test requests after a brief pause |
| 1225 | if not self._test_request_started: |
| 1226 | self._test_request_started = True |
| 1227 | tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 1228 | reactor.callLater(tststart, self._test_request.start_collector) |
| 1229 | |
| 1230 | */ |
| 1231 | /* which is then: in omci_test_request.py : */ |
| 1232 | /* |
| 1233 | def start_collector(self, callback=None): |
| 1234 | """ |
| 1235 | Start the collection loop for an adapter if the frequency > 0 |
| 1236 | |
| 1237 | :param callback: (callable) Function to call to collect PM data |
| 1238 | """ |
| 1239 | self.logger.info("starting-pm-collection", device_name=self.name, default_freq=self.default_freq) |
| 1240 | if callback is None: |
| 1241 | callback = self.perform_test_omci |
| 1242 | |
| 1243 | if self.lc is None: |
| 1244 | self.lc = LoopingCall(callback) |
| 1245 | |
| 1246 | if self.default_freq > 0: |
| 1247 | self.lc.start(interval=self.default_freq / 10) |
| 1248 | |
| 1249 | def perform_test_omci(self): |
| 1250 | """ |
| 1251 | Perform the initial test request |
| 1252 | """ |
| 1253 | ani_g_entities = self._device.configuration.ani_g_entities |
| 1254 | ani_g_entities_ids = list(ani_g_entities.keys()) if ani_g_entities \ |
| 1255 | is not None else None |
| 1256 | self._entity_id = ani_g_entities_ids[0] |
| 1257 | self.logger.info('perform-test', entity_class=self._entity_class, |
| 1258 | entity_id=self._entity_id) |
| 1259 | try: |
| 1260 | frame = MEFrame(self._entity_class, self._entity_id, []).test() |
| 1261 | result = yield self._device.omci_cc.send(frame) |
| 1262 | if not result.fields['omci_message'].fields['success_code']: |
| 1263 | self.logger.info('Self-Test Submitted Successfully', |
| 1264 | code=result.fields[ |
| 1265 | 'omci_message'].fields['success_code']) |
| 1266 | else: |
| 1267 | raise TestFailure('Test Failure: {}'.format( |
| 1268 | result.fields['omci_message'].fields['success_code'])) |
| 1269 | except TimeoutError as e: |
| 1270 | self.deferred.errback(failure.Failure(e)) |
| 1271 | |
| 1272 | except Exception as e: |
| 1273 | self.logger.exception('perform-test-Error', e=e, |
| 1274 | class_id=self._entity_class, |
| 1275 | entity_id=self._entity_id) |
| 1276 | self.deferred.errback(failure.Failure(e)) |
| 1277 | |
| 1278 | */ |
| 1279 | |
| 1280 | // PM related heartbeat??? !!!TODO.... |
| 1281 | //self._heartbeat.enabled = True |
| 1282 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1283 | /* Note: Even though FSM calls look 'synchronous' here, FSM is running in background with the effect that possible errors |
| 1284 | * within the MibUpload are not notified in the OnuIndication response, this might be acceptable here, |
| 1285 | * as further OltAdapter processing may rely on the deviceReason event 'MibUploadDone' as a result of the FSM processing |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1286 | * otherwise some processing synchronization would be required - cmp. e.g TechProfile processing |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1287 | */ |
| 1288 | //call MibUploadFSM - transition up to state ulStInSync |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1289 | pMibUlFsm := pDevEntry.pMibUploadFsm.pFsm |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1290 | if pMibUlFsm != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1291 | if pMibUlFsm.Is(ulStDisabled) { |
| 1292 | if err := pMibUlFsm.Event(ulEvStart); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1293 | logger.Errorw("MibSyncFsm: Can't go to state starting", log.Fields{"device-id": dh.deviceID, "err": err}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1294 | return fmt.Errorf("can't go to state starting: %s", dh.deviceID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1295 | } |
| 1296 | logger.Debugw("MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())}) |
| 1297 | //Determine ONU status and start/re-start MIB Synchronization tasks |
| 1298 | //Determine if this ONU has ever synchronized |
| 1299 | if true { //TODO: insert valid check |
| 1300 | if err := pMibUlFsm.Event(ulEvResetMib); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1301 | logger.Errorw("MibSyncFsm: Can't go to state resetting_mib", log.Fields{"device-id": dh.deviceID, "err": err}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1302 | return fmt.Errorf("can't go to state resetting_mib: %s", dh.deviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1303 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1304 | } else { |
| 1305 | if err := pMibUlFsm.Event(ulEvExamineMds); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1306 | logger.Errorw("MibSyncFsm: Can't go to state examine_mds", log.Fields{"device-id": dh.deviceID, "err": err}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1307 | return fmt.Errorf("can't go to examine_mds: %s", dh.deviceID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1308 | } |
| 1309 | logger.Debugw("state of MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())}) |
| 1310 | //Examine the MIB Data Sync |
| 1311 | // callbacks to be handled: |
| 1312 | // Event(ulEvSuccess) |
| 1313 | // Event(ulEvTimeout) |
| 1314 | // Event(ulEvMismatch) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1315 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1316 | } else { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 1317 | logger.Errorw("wrong state of MibSyncFsm - want: disabled", log.Fields{"have": string(pMibUlFsm.Current()), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1318 | "device-id": dh.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1319 | return fmt.Errorf("wrong state of MibSyncFsm: %s", dh.deviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1320 | } |
| 1321 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1322 | logger.Errorw("MibSyncFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1323 | return fmt.Errorf("can't execute MibSync: %s", dh.deviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1324 | } |
| 1325 | return nil |
| 1326 | } |
| 1327 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1328 | func (dh *deviceHandler) updateInterface(onuind *oop.OnuIndication) error { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1329 | //state checking to prevent unneeded processing (eg. on ONU 'unreachable' and 'down') |
| 1330 | if dh.deviceReason != "stopping-openomci" { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1331 | logger.Debugw("updateInterface-started - stopping-device", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1332 | //stop all running FSM processing - make use of the DH-state as mirrored in the deviceReason |
| 1333 | //here no conflict with aborted FSM's should arise as a complete OMCI initialization is assumed on ONU-Up |
| 1334 | //but that might change with some simple MDS check on ONU-Up treatment -> attention!!! |
| 1335 | if err := dh.resetFsms(); err != nil { |
| 1336 | logger.Errorw("error-updateInterface at FSM stop", |
| 1337 | log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1338 | // abort: system behavior is just unstable ... |
| 1339 | return err |
| 1340 | } |
| 1341 | |
| 1342 | //deviceEntry stop without omciCC reset here, regarding the OMCI_CC still valid for this ONU |
| 1343 | // - in contrary to disableDevice - compare with processUniDisableStateDoneEvent |
| 1344 | //stop the device entry which resets the attached omciCC |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1345 | pDevEntry := dh.getOnuDeviceEntry(false) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1346 | if pDevEntry == nil { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1347 | logger.Errorw("No valid OnuDevice -aborting", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1348 | return fmt.Errorf("no valid OnuDevice: %s", dh.deviceID) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1349 | } |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1350 | _ = pDevEntry.stop(context.TODO(), false) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1351 | |
| 1352 | //TODO!!! remove existing traffic profiles |
| 1353 | /* from py code, if TP's exist, remove them - not yet implemented |
| 1354 | self._tp = dict() |
| 1355 | # Let TP download happen again |
| 1356 | for uni_id in self._tp_service_specific_task: |
| 1357 | self._tp_service_specific_task[uni_id].clear() |
| 1358 | for uni_id in self._tech_profile_download_done: |
| 1359 | self._tech_profile_download_done[uni_id].clear() |
| 1360 | */ |
| 1361 | |
| 1362 | dh.disableUniPortStateUpdate() |
| 1363 | |
| 1364 | 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] | 1365 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1366 | logger.Errorw("error-DeviceReasonUpdate to 'stopping-openomci'", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1367 | log.Fields{"device-id": dh.deviceID, "error": err}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1368 | // abort: system behavior is just unstable ... |
| 1369 | return err |
| 1370 | } |
| 1371 | dh.deviceReason = "stopping-openomci" |
| 1372 | |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 1373 | logger.Debugw("call DeviceStateUpdate upon update interface", log.Fields{"ConnectStatus": voltha.ConnectStatus_UNREACHABLE, |
| 1374 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1375 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, |
| 1376 | voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_DISCOVERED); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1377 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1378 | logger.Errorw("error-updating-device-state unreachable-discovered", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1379 | log.Fields{"device-id": dh.deviceID, "error": err}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1380 | // abort: system behavior is just unstable ... |
| 1381 | return err |
| 1382 | } |
| 1383 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1384 | logger.Debugw("updateInterface - device already stopped", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1385 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1386 | return nil |
| 1387 | } |
| 1388 | |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1389 | func (dh *deviceHandler) resetFsms() error { |
| 1390 | //all possible FSM's are stopped or reset here to ensure their transition to 'disabled' |
| 1391 | //it is not sufficient to stop/reset the latest running FSM as done in previous versions |
| 1392 | // as after down/up procedures all FSM's might be active/ongoing (in theory) |
| 1393 | // and using the stop/reset event should never harm |
| 1394 | |
| 1395 | pDevEntry := dh.getOnuDeviceEntry(false) |
| 1396 | if pDevEntry == nil { |
| 1397 | logger.Errorw("No valid OnuDevice -aborting", log.Fields{"device-id": dh.deviceID}) |
| 1398 | return fmt.Errorf("no valid OnuDevice: %s", dh.deviceID) |
| 1399 | } |
| 1400 | |
| 1401 | //the MibSync FSM might be active all the ONU-active time, |
| 1402 | // hence it must be stopped unconditionally |
| 1403 | pMibUlFsm := pDevEntry.pMibUploadFsm.pFsm |
| 1404 | if pMibUlFsm != nil { |
| 1405 | _ = pMibUlFsm.Event(ulEvStop) //TODO!! verify if MibSyncFsm stop-processing is sufficient (to allow it again afterwards) |
| 1406 | } |
| 1407 | //MibDownload may run |
| 1408 | pMibDlFsm := pDevEntry.pMibDownloadFsm.pFsm |
| 1409 | if pMibDlFsm != nil { |
| 1410 | _ = pMibDlFsm.Event(dlEvReset) |
| 1411 | } |
| 1412 | //port lock/unlock FSM's may be active |
| 1413 | if dh.pUnlockStateFsm != nil { |
| 1414 | _ = dh.pUnlockStateFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
| 1415 | } |
| 1416 | if dh.pLockStateFsm != nil { |
| 1417 | _ = dh.pLockStateFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
| 1418 | } |
| 1419 | //techProfile related PonAniConfigFsm FSM may be active |
| 1420 | if dh.pOnuTP != nil { |
| 1421 | // should always be the case here |
| 1422 | // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting |
| 1423 | if dh.pOnuTP.pAniConfigFsm != nil { |
| 1424 | _ = dh.pOnuTP.pAniConfigFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
| 1425 | } |
| 1426 | for _, uniPort := range dh.uniEntityMap { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1427 | // reset the possibly existing VlanConfigFsm |
| 1428 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniPort.uniID]; exist { |
| 1429 | //VlanFilterFsm exists and was already started |
| 1430 | pVlanFilterStatemachine := pVlanFilterFsm.pAdaptFsm.pFsm |
| 1431 | if pVlanFilterStatemachine != nil { |
| 1432 | _ = pVlanFilterStatemachine.Event(vlanEvReset) |
| 1433 | } |
| 1434 | } |
| 1435 | } |
| 1436 | } |
| 1437 | //TODO!!! care about PM/Alarm processing once started |
| 1438 | return nil |
| 1439 | } |
| 1440 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1441 | func (dh *deviceHandler) processMibDatabaseSyncEvent(devEvent OnuDeviceEvent) { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1442 | logger.Debugw("MibInSync event received", log.Fields{"device-id": dh.deviceID}) |
| 1443 | if !dh.reconciling { |
| 1444 | //initiate DevStateUpdate |
| 1445 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "discovery-mibsync-complete"); err != nil { |
| 1446 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1447 | logger.Errorw("error-DeviceReasonUpdate to 'mibsync-complete'", log.Fields{ |
| 1448 | "device-id": dh.deviceID, "error": err}) |
| 1449 | } else { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1450 | logger.Infow("dev reason updated to 'MibSync complete'", log.Fields{"device-id": dh.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1451 | } |
| 1452 | } else { |
| 1453 | logger.Debugw("reconciling - don't notify core about DeviceReasonUpdate to mibsync-complete", |
| 1454 | log.Fields{"device-id": dh.deviceID}) |
| 1455 | } |
| 1456 | //set internal state anyway - as it was done |
| 1457 | dh.deviceReason = "discovery-mibsync-complete" |
| 1458 | |
| 1459 | i := uint8(0) //UNI Port limit: see MaxUnisPerOnu (by now 16) (OMCI supports max 255 p.b.) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1460 | pDevEntry := dh.getOnuDeviceEntry(false) |
| 1461 | if unigInstKeys := pDevEntry.pOnuDB.getSortedInstKeys(me.UniGClassID); len(unigInstKeys) > 0 { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1462 | for _, mgmtEntityID := range unigInstKeys { |
| 1463 | logger.Debugw("Add UNI port for stored UniG instance:", log.Fields{ |
| 1464 | "device-id": dh.deviceID, "UnigMe EntityID": mgmtEntityID}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1465 | dh.addUniPort(mgmtEntityID, i, uniPPTP) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1466 | i++ |
| 1467 | } |
| 1468 | } else { |
| 1469 | logger.Debugw("No UniG instances found", log.Fields{"device-id": dh.deviceID}) |
| 1470 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1471 | if veipInstKeys := pDevEntry.pOnuDB.getSortedInstKeys(me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1472 | for _, mgmtEntityID := range veipInstKeys { |
| 1473 | logger.Debugw("Add VEIP acc. to stored VEIP instance:", log.Fields{ |
| 1474 | "device-id": dh.deviceID, "VEIP EntityID": mgmtEntityID}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1475 | dh.addUniPort(mgmtEntityID, i, uniVEIP) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1476 | i++ |
| 1477 | } |
| 1478 | } else { |
| 1479 | logger.Debugw("No VEIP instances found", log.Fields{"device-id": dh.deviceID}) |
| 1480 | } |
| 1481 | if i == 0 { |
| 1482 | logger.Warnw("No PPTP instances found", log.Fields{"device-id": dh.deviceID}) |
| 1483 | } |
| 1484 | |
| 1485 | /* 200605: lock processing after initial MIBUpload removed now as the ONU should be in the lock state per default here |
| 1486 | * left the code here as comment in case such processing should prove needed unexpectedly |
| 1487 | // Init Uni Ports to Admin locked state |
| 1488 | // maybe not really needed here as UNI ports should be locked by default, but still left as available in python code |
| 1489 | // *** should generate UniLockStateDone event ***** |
| 1490 | if dh.pLockStateFsm == nil { |
| 1491 | dh.createUniLockFsm(true, UniLockStateDone) |
| 1492 | } else { //LockStateFSM already init |
| 1493 | dh.pLockStateFsm.SetSuccessEvent(UniLockStateDone) |
| 1494 | dh.runUniLockFsm(true) |
| 1495 | } |
| 1496 | } |
| 1497 | case UniLockStateDone: |
| 1498 | { |
| 1499 | logger.Infow("UniLockStateDone event: Starting MIB download", log.Fields{"device-id": dh.deviceID}) |
| 1500 | * lockState processing commented out |
| 1501 | */ |
| 1502 | /* Mib download procedure - |
| 1503 | ***** should run over 'downloaded' state and generate MibDownloadDone event ***** |
| 1504 | */ |
| 1505 | pMibDlFsm := pDevEntry.pMibDownloadFsm.pFsm |
| 1506 | if pMibDlFsm != nil { |
| 1507 | if pMibDlFsm.Is(dlStDisabled) { |
| 1508 | if err := pMibDlFsm.Event(dlEvStart); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1509 | logger.Errorw("MibDownloadFsm: Can't go to state starting", log.Fields{"device-id": dh.deviceID, "err": err}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1510 | // maybe try a FSM reset and then again ... - TODO!!! |
| 1511 | } else { |
| 1512 | logger.Debugw("MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())}) |
| 1513 | // maybe use more specific states here for the specific download steps ... |
| 1514 | if err := pMibDlFsm.Event(dlEvCreateGal); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1515 | logger.Errorw("MibDownloadFsm: Can't start CreateGal", log.Fields{"device-id": dh.deviceID, "err": err}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1516 | } else { |
| 1517 | logger.Debugw("state of MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())}) |
| 1518 | //Begin MIB data download (running autonomously) |
| 1519 | } |
| 1520 | } |
| 1521 | } else { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 1522 | logger.Errorw("wrong state of MibDownloadFsm - want: disabled", log.Fields{"have": string(pMibDlFsm.Current()), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1523 | "device-id": dh.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1524 | // maybe try a FSM reset and then again ... - TODO!!! |
| 1525 | } |
| 1526 | /***** Mib download started */ |
| 1527 | } else { |
| 1528 | logger.Errorw("MibDownloadFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.deviceID}) |
| 1529 | } |
| 1530 | } |
| 1531 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1532 | func (dh *deviceHandler) processMibDownloadDoneEvent(devEvent OnuDeviceEvent) { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1533 | logger.Debugw("MibDownloadDone event received", log.Fields{"device-id": dh.deviceID}) |
| 1534 | //initiate DevStateUpdate |
| 1535 | if !dh.reconciling { |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 1536 | logger.Debugw("call DeviceStateUpdate upon mib-download done", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
| 1537 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1538 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, |
| 1539 | voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE); err != nil { |
| 1540 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1541 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1542 | } else { |
| 1543 | logger.Debugw("dev state updated to 'Oper.Active'", log.Fields{"device-id": dh.deviceID}) |
| 1544 | } |
| 1545 | } else { |
| 1546 | logger.Debugw("reconciling - don't notify core about DeviceStateUpdate to ACTIVE", |
| 1547 | log.Fields{"device-id": dh.deviceID}) |
| 1548 | } |
| 1549 | if !dh.reconciling { |
| 1550 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "initial-mib-downloaded"); err != nil { |
| 1551 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1552 | logger.Errorw("error-DeviceReasonUpdate to 'initial-mib-downloaded'", |
| 1553 | log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1554 | } else { |
| 1555 | logger.Infow("dev reason updated to 'initial-mib-downloaded'", log.Fields{"device-id": dh.deviceID}) |
| 1556 | } |
| 1557 | } else { |
| 1558 | logger.Debugw("reconciling - don't notify core about DeviceReasonUpdate to initial-mib-downloaded", |
| 1559 | log.Fields{"device-id": dh.deviceID}) |
| 1560 | } |
| 1561 | //set internal state anyway - as it was done |
| 1562 | dh.deviceReason = "initial-mib-downloaded" |
| 1563 | // *** should generate UniUnlockStateDone event ***** |
| 1564 | if dh.pUnlockStateFsm == nil { |
| 1565 | dh.createUniLockFsm(false, UniUnlockStateDone) |
| 1566 | } else { //UnlockStateFSM already init |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1567 | dh.pUnlockStateFsm.setSuccessEvent(UniUnlockStateDone) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1568 | dh.runUniLockFsm(false) |
| 1569 | } |
| 1570 | } |
| 1571 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1572 | func (dh *deviceHandler) processUniUnlockStateDoneEvent(devEvent OnuDeviceEvent) { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1573 | dh.enableUniPortStateUpdate() //cmp python yield self.enable_ports() |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1574 | |
| 1575 | if !dh.reconciling { |
| 1576 | logger.Infow("UniUnlockStateDone event: Sending OnuUp event", log.Fields{"device-id": dh.deviceID}) |
| 1577 | raisedTs := time.Now().UnixNano() |
| 1578 | go dh.sendOnuOperStateEvent(voltha.OperStatus_ACTIVE, dh.deviceID, raisedTs) //cmp python onu_active_event |
| 1579 | } else { |
| 1580 | logger.Debugw("reconciling - don't notify core that onu went to active but trigger tech profile config", |
| 1581 | log.Fields{"device-id": dh.deviceID}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1582 | go dh.reconcileDeviceTechProf() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1583 | // reconcilement will be continued after ani config is done |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1584 | } |
| 1585 | } |
| 1586 | |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1587 | func (dh *deviceHandler) processUniDisableStateDoneEvent(devEvent OnuDeviceEvent) { |
| 1588 | logger.Debugw("DeviceStateUpdate upon disable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
| 1589 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.deviceID}) |
| 1590 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), |
| 1591 | dh.deviceID, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN); err != nil { |
| 1592 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1593 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1594 | } |
| 1595 | |
| 1596 | logger.Debugw("DeviceReasonUpdate upon re-enable", log.Fields{ |
| 1597 | "reason": "omci-admin-lock", "device-id": dh.deviceID}) |
| 1598 | // DeviceReason to update acc.to modified py code as per beginning of Sept 2020 |
| 1599 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "omci-admin-lock"); err != nil { |
| 1600 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1601 | logger.Errorw("error-updating-reason-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1602 | } |
| 1603 | dh.deviceReason = "omci-admin-lock" |
| 1604 | |
| 1605 | //transfer the modified logical uni port state |
| 1606 | dh.disableUniPortStateUpdate() |
| 1607 | |
| 1608 | //stop the device entry which resets the attached omciCC |
| 1609 | pDevEntry := dh.getOnuDeviceEntry(false) |
| 1610 | if pDevEntry == nil { |
| 1611 | logger.Errorw("No valid OnuDevice -aborting", log.Fields{"device-id": dh.deviceID}) |
| 1612 | return |
| 1613 | } |
| 1614 | _ = pDevEntry.stop(context.TODO(), true) //stop deviceEntry with omciCC reset |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | func (dh *deviceHandler) processUniEnableStateDoneEvent(devEvent OnuDeviceEvent) { |
| 1618 | logger.Debugw("DeviceStateUpdate upon re-enable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
| 1619 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.deviceID}) |
| 1620 | if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, voltha.ConnectStatus_REACHABLE, |
| 1621 | voltha.OperStatus_ACTIVE); err != nil { |
| 1622 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1623 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1624 | } |
| 1625 | |
| 1626 | logger.Debugw("DeviceReasonUpdate upon re-enable", log.Fields{ |
| 1627 | "reason": "onu-reenabled", "device-id": dh.deviceID}) |
| 1628 | // DeviceReason to update acc.to modified py code as per beginning of Sept 2020 |
| 1629 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "onu-reenabled"); err != nil { |
| 1630 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1631 | logger.Errorw("error-updating-reason-state", log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1632 | } |
| 1633 | dh.deviceReason = "onu-reenabled" |
| 1634 | |
| 1635 | //transfer the modified logical uni port state |
| 1636 | dh.enableUniPortStateUpdate() |
| 1637 | } |
| 1638 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1639 | func (dh *deviceHandler) processOmciAniConfigDoneEvent(devEvent OnuDeviceEvent) { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1640 | logger.Debugw("OmciAniConfigDone event received", log.Fields{"device-id": dh.deviceID}) |
| 1641 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 1642 | // - which may cause some inconsistency |
| 1643 | if dh.deviceReason != "tech-profile-config-download-success" { |
| 1644 | // which may be the case from some previous actvity on another UNI Port of the ONU |
| 1645 | if !dh.reconciling { |
| 1646 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "tech-profile-config-download-success"); err != nil { |
| 1647 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1648 | logger.Errorw("error-DeviceReasonUpdate to 'tech-profile-config-download-success'", |
| 1649 | log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1650 | } else { |
| 1651 | logger.Infow("update dev reason to 'tech-profile-config-download-success'", |
| 1652 | log.Fields{"device-id": dh.deviceID}) |
| 1653 | } |
| 1654 | } else { |
| 1655 | logger.Debugw("reconciling - don't notify core about DeviceReasonUpdate to tech-profile-config-download-success", |
| 1656 | log.Fields{"device-id": dh.deviceID}) |
| 1657 | } |
| 1658 | //set internal state anyway - as it was done |
| 1659 | dh.deviceReason = "tech-profile-config-download-success" |
| 1660 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1661 | if dh.reconciling { |
| 1662 | go dh.reconcileDeviceFlowConfig() |
| 1663 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1664 | } |
| 1665 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1666 | func (dh *deviceHandler) processOmciVlanFilterDoneEvent(devEvent OnuDeviceEvent) { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1667 | logger.Debugw("OmciVlanFilterDone event received", |
| 1668 | log.Fields{"device-id": dh.deviceID}) |
| 1669 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 1670 | // - which may cause some inconsistency |
| 1671 | // yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed') |
| 1672 | |
| 1673 | if dh.deviceReason != "omci-flows-pushed" { |
| 1674 | // which may be the case from some previous actvity on another UNI Port of the ONU |
| 1675 | // or even some previous flow add activity on the same port |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1676 | if !dh.reconciling { |
| 1677 | if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "omci-flows-pushed"); err != nil { |
| 1678 | logger.Errorw("error-DeviceReasonUpdate to 'omci-flows-pushed'", |
| 1679 | log.Fields{"device-id": dh.deviceID, "error": err}) |
| 1680 | } else { |
| 1681 | logger.Infow("updated dev reason to ''omci-flows-pushed'", |
| 1682 | log.Fields{"device-id": dh.deviceID}) |
| 1683 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1684 | } else { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1685 | logger.Debugw("reconciling - don't notify core about DeviceReasonUpdate to omci-flows-pushed", |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1686 | log.Fields{"device-id": dh.deviceID}) |
| 1687 | } |
| 1688 | //set internal state anyway - as it was done |
| 1689 | dh.deviceReason = "omci-flows-pushed" |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1690 | |
| 1691 | if dh.reconciling { |
| 1692 | go dh.reconcileMetrics() |
| 1693 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1694 | } |
| 1695 | } |
| 1696 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1697 | //deviceProcStatusUpdate evaluates possible processing events and initiates according next activities |
| 1698 | func (dh *deviceHandler) deviceProcStatusUpdate(devEvent OnuDeviceEvent) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1699 | switch devEvent { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1700 | case MibDatabaseSync: |
| 1701 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1702 | dh.processMibDatabaseSyncEvent(devEvent) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1703 | } |
| 1704 | case MibDownloadDone: |
| 1705 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1706 | dh.processMibDownloadDoneEvent(devEvent) |
| 1707 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1708 | } |
| 1709 | case UniUnlockStateDone: |
| 1710 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1711 | dh.processUniUnlockStateDoneEvent(devEvent) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1712 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1713 | } |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1714 | case UniEnableStateDone: |
| 1715 | { |
| 1716 | dh.processUniEnableStateDoneEvent(devEvent) |
| 1717 | |
| 1718 | } |
| 1719 | case UniDisableStateDone: |
| 1720 | { |
| 1721 | dh.processUniDisableStateDoneEvent(devEvent) |
| 1722 | |
| 1723 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1724 | case OmciAniConfigDone: |
| 1725 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1726 | dh.processOmciAniConfigDoneEvent(devEvent) |
| 1727 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1728 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1729 | case OmciVlanFilterDone: |
| 1730 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1731 | dh.processOmciVlanFilterDoneEvent(devEvent) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1732 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1733 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1734 | default: |
| 1735 | { |
Andrea Campanella | ab7b6a5 | 2020-10-06 16:17:13 +0200 | [diff] [blame] | 1736 | logger.Debugw("unhandled-device-event", log.Fields{"device-id": dh.deviceID, "event": devEvent}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1737 | } |
| 1738 | } //switch |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1741 | func (dh *deviceHandler) addUniPort(aUniInstNo uint16, aUniID uint8, aPortType uniPortType) { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1742 | // parameters are IntfId, OnuId, uniId |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1743 | uniNo := mkUniPortNum(dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1744 | uint32(aUniID)) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1745 | if _, present := dh.uniEntityMap[uniNo]; present { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1746 | logger.Warnw("onuUniPort-add: Port already exists", log.Fields{"for InstanceId": aUniInstNo}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1747 | } else { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1748 | //with arguments aUniID, a_portNo, aPortType |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1749 | pUniPort := newOnuUniPort(aUniID, uniNo, aUniInstNo, aPortType) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1750 | if pUniPort == nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1751 | logger.Warnw("onuUniPort-add: Could not create Port", log.Fields{"for InstanceId": aUniInstNo}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1752 | } else { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1753 | //store UniPort with the System-PortNumber key |
| 1754 | dh.uniEntityMap[uniNo] = pUniPort |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1755 | if !dh.reconciling { |
| 1756 | // create announce the UniPort to the core as VOLTHA Port object |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1757 | if err := pUniPort.createVolthaPort(dh); err == nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1758 | logger.Infow("onuUniPort-added", log.Fields{"for PortNo": uniNo}) |
| 1759 | } //error logging already within UniPort method |
| 1760 | } else { |
| 1761 | logger.Debugw("reconciling - onuUniPort already added", log.Fields{"for PortNo": uniNo, "device-id": dh.deviceID}) |
| 1762 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1763 | } |
| 1764 | } |
| 1765 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1766 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1767 | // enableUniPortStateUpdate enables UniPortState and update core port state accordingly |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1768 | func (dh *deviceHandler) enableUniPortStateUpdate() { |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 1769 | // py code was updated 2003xx to activate the real ONU UNI ports per OMCI (VEIP or PPTP) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1770 | // but towards core only the first port active state is signaled |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 1771 | // with following remark: |
| 1772 | // # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow |
| 1773 | // # load on the core |
| 1774 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1775 | // 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] | 1776 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1777 | for uniNo, uniPort := range dh.uniEntityMap { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1778 | // only if this port is validated for operState transfer |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1779 | if (1<<uniPort.uniID)&activeUniPortStateUpdateMask == (1 << uniPort.uniID) { |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 1780 | logger.Infow("onuUniPort-forced-OperState-ACTIVE", log.Fields{"for PortNo": uniNo}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1781 | uniPort.setOperState(vc.OperStatus_ACTIVE) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1782 | if !dh.reconciling { |
| 1783 | //maybe also use getter functions on uniPort - perhaps later ... |
| 1784 | go dh.coreProxy.PortStateUpdate(context.TODO(), dh.deviceID, voltha.Port_ETHERNET_UNI, uniPort.portNo, uniPort.operState) |
| 1785 | } else { |
Andrea Campanella | ab7b6a5 | 2020-10-06 16:17:13 +0200 | [diff] [blame] | 1786 | //TODO there is no retry mechanism, return error |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1787 | logger.Debugw("reconciling - don't notify core about PortStateUpdate", log.Fields{"device-id": dh.deviceID}) |
| 1788 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1789 | } |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | // Disable UniPortState and update core port state accordingly |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1794 | func (dh *deviceHandler) disableUniPortStateUpdate() { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1795 | // compare enableUniPortStateUpdate() above |
| 1796 | // -> use current restriction to operate only on first UNI port as inherited from actual Py code |
| 1797 | for uniNo, uniPort := range dh.uniEntityMap { |
| 1798 | // only if this port is validated for operState transfer |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1799 | if (1<<uniPort.uniID)&activeUniPortStateUpdateMask == (1 << uniPort.uniID) { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1800 | logger.Infow("onuUniPort-forced-OperState-UNKNOWN", log.Fields{"for PortNo": uniNo}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1801 | uniPort.setOperState(vc.OperStatus_UNKNOWN) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1802 | //maybe also use getter functions on uniPort - perhaps later ... |
| 1803 | 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] | 1804 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | // ONU_Active/Inactive announcement on system KAFKA bus |
| 1809 | // tried to re-use procedure of oltUpDownIndication from openolt_eventmgr.go with used values from Py code |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1810 | func (dh *deviceHandler) sendOnuOperStateEvent(aOperState vc.OperStatus_Types, aDeviceID string, raisedTs int64) { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1811 | var de voltha.DeviceEvent |
| 1812 | eventContext := make(map[string]string) |
| 1813 | //Populating event context |
| 1814 | // assume giving ParentId in GetDevice twice really gives the ParentDevice (there is no GetParentDevice()...) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1815 | parentDevice, err := dh.coreProxy.GetDevice(context.TODO(), dh.parentID, dh.parentID) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1816 | if err != nil || parentDevice == nil { |
| 1817 | logger.Errorw("Failed to fetch parent device for OnuEvent", |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1818 | log.Fields{"parentID": dh.parentID, "err": err}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1819 | } |
| 1820 | oltSerialNumber := parentDevice.SerialNumber |
| 1821 | |
| 1822 | eventContext["pon-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.IntfId), 10) |
| 1823 | eventContext["onu-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.OnuId), 10) |
| 1824 | eventContext["serial-number"] = dh.device.SerialNumber |
| 1825 | eventContext["olt_serial_number"] = oltSerialNumber |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1826 | eventContext["device_id"] = aDeviceID |
| 1827 | eventContext["registration_id"] = aDeviceID //py: string(device_id)?? |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1828 | logger.Debugw("prepare ONU_ACTIVATED event", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1829 | log.Fields{"device-id": aDeviceID, "EventContext": eventContext}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1830 | |
| 1831 | /* Populating device event body */ |
| 1832 | de.Context = eventContext |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1833 | de.ResourceId = aDeviceID |
| 1834 | if aOperState == voltha.OperStatus_ACTIVE { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1835 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "RAISE_EVENT") |
| 1836 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 1837 | cEventObjectType, cOnuActivatedEvent, "Raised") |
| 1838 | } else { |
| 1839 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "CLEAR_EVENT") |
| 1840 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 1841 | cEventObjectType, cOnuActivatedEvent, "Cleared") |
| 1842 | } |
| 1843 | /* Send event to KAFKA */ |
| 1844 | if err := dh.EventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil { |
| 1845 | logger.Warnw("could not send ONU_ACTIVATED event", |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1846 | log.Fields{"device-id": aDeviceID, "error": err}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1847 | } |
| 1848 | logger.Debugw("ONU_ACTIVATED event sent to KAFKA", |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1849 | log.Fields{"device-id": aDeviceID, "with-EventName": de.DeviceEventName}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1852 | // createUniLockFsm initializes and runs the UniLock FSM to transfer the OMCI related commands for port lock/unlock |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1853 | func (dh *deviceHandler) createUniLockFsm(aAdminState bool, devEvent OnuDeviceEvent) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1854 | chLSFsm := make(chan Message, 2048) |
| 1855 | var sFsmName string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1856 | if aAdminState { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1857 | logger.Infow("createLockStateFSM", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1858 | sFsmName = "LockStateFSM" |
| 1859 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1860 | logger.Infow("createUnlockStateFSM", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1861 | sFsmName = "UnLockStateFSM" |
| 1862 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1863 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1864 | pDevEntry := dh.getOnuDeviceEntry(true) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1865 | if pDevEntry == nil { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1866 | logger.Errorw("No valid OnuDevice -aborting", log.Fields{"device-id": dh.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1867 | return |
| 1868 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1869 | pLSFsm := newLockStateFsm(pDevEntry.PDevOmciCC, aAdminState, devEvent, |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 1870 | sFsmName, dh, chLSFsm) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1871 | if pLSFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1872 | if aAdminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1873 | dh.pLockStateFsm = pLSFsm |
| 1874 | } else { |
| 1875 | dh.pUnlockStateFsm = pLSFsm |
| 1876 | } |
| 1877 | dh.runUniLockFsm(aAdminState) |
| 1878 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1879 | 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] | 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | // runUniLockFsm starts the UniLock FSM to transfer the OMCI related commands for port lock/unlock |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1884 | func (dh *deviceHandler) runUniLockFsm(aAdminState bool) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1885 | /* Uni Port lock/unlock procedure - |
| 1886 | ***** should run via 'adminDone' state and generate the argument requested event ***** |
| 1887 | */ |
| 1888 | var pLSStatemachine *fsm.FSM |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1889 | if aAdminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1890 | pLSStatemachine = dh.pLockStateFsm.pAdaptFsm.pFsm |
| 1891 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 1892 | if (dh.pUnlockStateFsm != nil) && |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1893 | (dh.pUnlockStateFsm.pAdaptFsm.pFsm.Current() != uniStDisabled) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1894 | _ = dh.pUnlockStateFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1895 | } |
| 1896 | } else { |
| 1897 | pLSStatemachine = dh.pUnlockStateFsm.pAdaptFsm.pFsm |
| 1898 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 1899 | if (dh.pLockStateFsm != nil) && |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1900 | (dh.pLockStateFsm.pAdaptFsm.pFsm.Current() != uniStDisabled) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1901 | _ = dh.pLockStateFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1902 | } |
| 1903 | } |
| 1904 | if pLSStatemachine != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1905 | if pLSStatemachine.Is(uniStDisabled) { |
| 1906 | if err := pLSStatemachine.Event(uniEvStart); err != nil { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1907 | logger.Warnw("LockStateFSM: can't start", log.Fields{"err": err}) |
| 1908 | // maybe try a FSM reset and then again ... - TODO!!! |
| 1909 | } else { |
| 1910 | /***** LockStateFSM started */ |
| 1911 | logger.Debugw("LockStateFSM started", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1912 | "state": pLSStatemachine.Current(), "device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1913 | } |
| 1914 | } else { |
| 1915 | logger.Warnw("wrong state of LockStateFSM - want: disabled", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1916 | "have": pLSStatemachine.Current(), "device-id": dh.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1917 | // maybe try a FSM reset and then again ... - TODO!!! |
| 1918 | } |
| 1919 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1920 | 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] | 1921 | // maybe try a FSM reset and then again ... - TODO!!! |
| 1922 | } |
| 1923 | } |
| 1924 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1925 | //setBackend provides a DB backend for the specified path on the existing KV client |
| 1926 | func (dh *deviceHandler) setBackend(aBasePathKvStore string) *db.Backend { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 1927 | addr := dh.pOpenOnuAc.KVStoreHost + ":" + strconv.Itoa(dh.pOpenOnuAc.KVStorePort) |
| 1928 | logger.Debugw("SetKVStoreBackend", log.Fields{"IpTarget": addr, |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 1929 | "BasePathKvStore": aBasePathKvStore, "device-id": dh.deviceID}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 1930 | kvbackend := &db.Backend{ |
| 1931 | Client: dh.pOpenOnuAc.kvClient, |
| 1932 | StoreType: dh.pOpenOnuAc.KVStoreType, |
| 1933 | /* address config update acc. to [VOL-2736] */ |
| 1934 | Address: addr, |
| 1935 | Timeout: dh.pOpenOnuAc.KVStoreTimeout, |
| 1936 | PathPrefix: aBasePathKvStore} |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 1937 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 1938 | return kvbackend |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1939 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1940 | func (dh *deviceHandler) getFlowOfbFields(apFlowItem *ofp.OfpFlowStats, loMatchVlan *uint16, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1941 | loAddPcp *uint8, loIPProto *uint32) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1942 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1943 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 1944 | switch field.Type { |
| 1945 | case of.OxmOfbFieldTypes_OFPXMT_OFB_ETH_TYPE: |
| 1946 | { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1947 | logger.Debugw("flow type EthType", log.Fields{"device-id": dh.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1948 | "EthType": strconv.FormatInt(int64(field.GetEthType()), 16)}) |
| 1949 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1950 | /* TT related temporary workaround - should not be needed anymore |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1951 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO: |
| 1952 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1953 | *loIPProto = field.GetIpProto() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1954 | logger.Debugw("flow type IpProto", log.Fields{"device-id": dh.deviceID, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1955 | "IpProto": strconv.FormatInt(int64(*loIPProto), 16)}) |
| 1956 | if *loIPProto == 2 { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1957 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 1958 | // avoids installing invalid EVTOCD rule |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1959 | logger.Debugw("flow type IpProto 2: TT workaround: ignore flow", |
| 1960 | log.Fields{"device-id": dh.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1961 | return |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1962 | } |
| 1963 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1964 | */ |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1965 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID: |
| 1966 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1967 | *loMatchVlan = uint16(field.GetVlanVid()) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1968 | loMatchVlanMask := uint16(field.GetVlanVidMask()) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1969 | if !(*loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) && |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1970 | loMatchVlanMask == uint16(of.OfpVlanId_OFPVID_PRESENT)) { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1971 | *loMatchVlan = *loMatchVlan & 0xFFF // not transparent: copy only ID bits |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1972 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1973 | logger.Debugw("flow field type", log.Fields{"device-id": dh.deviceID, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1974 | "VID": strconv.FormatInt(int64(*loMatchVlan), 16)}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1975 | } |
| 1976 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP: |
| 1977 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1978 | *loAddPcp = uint8(field.GetVlanPcp()) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1979 | logger.Debugw("flow field type", log.Fields{"device-id": dh.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1980 | "PCP": loAddPcp}) |
| 1981 | } |
| 1982 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_DST: |
| 1983 | { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1984 | logger.Debugw("flow field type", log.Fields{"device-id": dh.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1985 | "UDP-DST": strconv.FormatInt(int64(field.GetUdpDst()), 16)}) |
| 1986 | } |
| 1987 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_SRC: |
| 1988 | { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1989 | logger.Debugw("flow field type", log.Fields{"device-id": dh.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1990 | "UDP-SRC": strconv.FormatInt(int64(field.GetUdpSrc()), 16)}) |
| 1991 | } |
| 1992 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_DST: |
| 1993 | { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1994 | logger.Debugw("flow field type", log.Fields{"device-id": dh.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1995 | "IPv4-DST": field.GetIpv4Dst()}) |
| 1996 | } |
| 1997 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_SRC: |
| 1998 | { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1999 | logger.Debugw("flow field type", log.Fields{"device-id": dh.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2000 | "IPv4-SRC": field.GetIpv4Src()}) |
| 2001 | } |
| 2002 | case of.OxmOfbFieldTypes_OFPXMT_OFB_METADATA: |
| 2003 | { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2004 | logger.Debugw("flow field type", log.Fields{"device-id": dh.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2005 | "Metadata": field.GetTableMetadata()}) |
| 2006 | } |
| 2007 | /* |
| 2008 | default: |
| 2009 | { |
| 2010 | //all other entires ignored |
| 2011 | } |
| 2012 | */ |
| 2013 | } |
| 2014 | } //for all OfbFields |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2015 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2016 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2017 | func (dh *deviceHandler) getFlowActions(apFlowItem *ofp.OfpFlowStats, loSetPcp *uint8, loSetVlan *uint16) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2018 | for _, action := range flow.GetActions(apFlowItem) { |
| 2019 | switch action.Type { |
| 2020 | /* not used: |
| 2021 | case of.OfpActionType_OFPAT_OUTPUT: |
| 2022 | { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2023 | logger.Debugw("flow action type", log.Fields{"device-id": dh.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2024 | "Output": action.GetOutput()}) |
| 2025 | } |
| 2026 | */ |
| 2027 | case of.OfpActionType_OFPAT_PUSH_VLAN: |
| 2028 | { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2029 | logger.Debugw("flow action type", log.Fields{"device-id": dh.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2030 | "PushEthType": strconv.FormatInt(int64(action.GetPush().Ethertype), 16)}) |
| 2031 | } |
| 2032 | case of.OfpActionType_OFPAT_SET_FIELD: |
| 2033 | { |
| 2034 | pActionSetField := action.GetSetField() |
| 2035 | if pActionSetField.Field.OxmClass != of.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2036 | logger.Warnw("flow action SetField invalid OxmClass (ignored)", log.Fields{"device-id": dh.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2037 | "OxcmClass": pActionSetField.Field.OxmClass}) |
| 2038 | } |
| 2039 | if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2040 | *loSetVlan = uint16(pActionSetField.Field.GetOfbField().GetVlanVid()) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2041 | logger.Debugw("flow Set VLAN from SetField action", log.Fields{"device-id": dh.deviceID, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2042 | "SetVlan": strconv.FormatInt(int64(*loSetVlan), 16)}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2043 | } else if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2044 | *loSetPcp = uint8(pActionSetField.Field.GetOfbField().GetVlanPcp()) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2045 | logger.Debugw("flow Set PCP from SetField action", log.Fields{"device-id": dh.deviceID, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2046 | "SetPcp": *loSetPcp}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2047 | } else { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2048 | logger.Warnw("flow action SetField invalid FieldType", log.Fields{"device-id": dh.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2049 | "Type": pActionSetField.Field.GetOfbField().Type}) |
| 2050 | } |
| 2051 | } |
| 2052 | /* |
| 2053 | default: |
| 2054 | { |
| 2055 | //all other entires ignored |
| 2056 | } |
| 2057 | */ |
| 2058 | } |
| 2059 | } //for all Actions |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | //addFlowItemToUniPort parses the actual flow item to add it to the UniPort |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2063 | func (dh *deviceHandler) addFlowItemToUniPort(apFlowItem *ofp.OfpFlowStats, apUniPort *onuUniPort) error { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2064 | var loSetVlan uint16 = uint16(of.OfpVlanId_OFPVID_NONE) //noValidEntry |
| 2065 | var loMatchVlan uint16 = uint16(of.OfpVlanId_OFPVID_PRESENT) //reserved VLANID entry |
| 2066 | var loAddPcp, loSetPcp uint8 |
| 2067 | var loIPProto uint32 |
| 2068 | /* the TechProfileId is part of the flow Metadata - compare also comment within |
| 2069 | * OLT-Adapter:openolt_flowmgr.go |
| 2070 | * Metadata 8 bytes: |
| 2071 | * Most Significant 2 Bytes = Inner VLAN |
| 2072 | * Next 2 Bytes = Tech Profile ID(TPID) |
| 2073 | * Least Significant 4 Bytes = Port ID |
| 2074 | * Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all |
| 2075 | * subscriber related flows. |
| 2076 | */ |
| 2077 | |
| 2078 | metadata := flow.GetMetadataFromWriteMetadataAction(apFlowItem) |
| 2079 | if metadata == 0 { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2080 | logger.Debugw("flow-add invalid metadata - abort", |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2081 | log.Fields{"device-id": dh.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2082 | return fmt.Errorf("flow-add invalid metadata: %s", dh.deviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2083 | } |
| 2084 | loTpID := flow.GetTechProfileIDFromWriteMetaData(metadata) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2085 | loCookie := apFlowItem.GetCookie() |
| 2086 | loCookieSlice := []uint64{loCookie} |
| 2087 | logger.Debugw("flow-add base indications", log.Fields{"device-id": dh.deviceID, |
| 2088 | "TechProf-Id": loTpID, "cookie": loCookie}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2089 | |
| 2090 | dh.getFlowOfbFields(apFlowItem, &loMatchVlan, &loAddPcp, &loIPProto) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2091 | /* TT related temporary workaround - should not be needed anymore |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2092 | if loIPProto == 2 { |
| 2093 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 2094 | // avoids installing invalid EVTOCD rule |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2095 | logger.Debugw("flow-add type IpProto 2: TT workaround: ignore flow", |
| 2096 | log.Fields{"device-id": dh.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2097 | return nil |
| 2098 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2099 | */ |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2100 | dh.getFlowActions(apFlowItem, &loSetPcp, &loSetVlan) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2101 | |
| 2102 | if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2103 | logger.Errorw("flow-add aborted - SetVlanId undefined, but MatchVid set", log.Fields{ |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2104 | "device-id": dh.deviceID, "UniPort": apUniPort.portNo, |
| 2105 | "set_vid": strconv.FormatInt(int64(loSetVlan), 16), |
| 2106 | "match_vid": strconv.FormatInt(int64(loMatchVlan), 16)}) |
| 2107 | //TODO!!: Use DeviceId within the error response to rwCore |
| 2108 | // likewise also in other error response cases to calling components as requested in [VOL-3458] |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2109 | return fmt.Errorf("flow-add Set/Match VlanId inconsistent: %s", dh.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2110 | } |
| 2111 | if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2112 | logger.Debugw("flow-add vlan-any/copy", log.Fields{"device-id": dh.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2113 | loSetVlan = loMatchVlan //both 'transparent' (copy any) |
| 2114 | } else { |
| 2115 | //looks like OMCI value 4097 (copyFromOuter - for Uni double tagged) is not supported here |
| 2116 | if loSetVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
| 2117 | // not set to transparent |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2118 | loSetVlan &= 0x0FFF //mask VID bits as prerequisite for vlanConfigFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2119 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2120 | logger.Debugw("flow-add vlan-set", log.Fields{"device-id": dh.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2121 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2122 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.uniID]; exist { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2123 | return dh.UniVlanConfigFsmMap[apUniPort.uniID].SetUniFlowParams(loTpID, loCookieSlice, |
| 2124 | loMatchVlan, loSetVlan, loSetPcp) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2125 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2126 | return dh.createVlanFilterFsm(apUniPort, loTpID, loCookieSlice, |
| 2127 | loMatchVlan, loSetVlan, loSetPcp, OmciVlanFilterDone) |
| 2128 | } |
| 2129 | |
| 2130 | //removeFlowItemFromUniPort parses the actual flow item to remove it from the UniPort |
| 2131 | func (dh *deviceHandler) removeFlowItemFromUniPort(apFlowItem *ofp.OfpFlowStats, apUniPort *onuUniPort) error { |
| 2132 | //optimization and assumption: the flow cookie uniquely identifies the flow and with that the internal rule |
| 2133 | //hence only the cookie is used here to find the relevant flow and possibly remove the rule |
| 2134 | //no extra check is done on the rule parameters |
| 2135 | //accordingly the removal is done only once - for the first found flow with that cookie, even though |
| 2136 | // at flow creation is not assured, that the same cookie is not configured for different flows - just assumed |
| 2137 | //additionally it is assumed here, that removal can only be done for one cookie per flow in a sequence (different |
| 2138 | // from addFlow - where at reconcilement multiple cookies per flow ) can be configured in one sequence) |
| 2139 | // - some possible 'delete-all' sequence would have be implemented separately (where the cookies are don't care anyway) |
| 2140 | loCookie := apFlowItem.GetCookie() |
| 2141 | logger.Debugw("flow-remove base indications", log.Fields{"device-id": dh.deviceID, "cookie": loCookie}) |
| 2142 | |
| 2143 | /* TT related temporary workaround - should not be needed anymore |
| 2144 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 2145 | if field.Type == of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO { |
| 2146 | loIPProto := field.GetIpProto() |
| 2147 | logger.Debugw("flow type IpProto", log.Fields{"device-id": dh.deviceID, |
| 2148 | "IpProto": strconv.FormatInt(int64(loIPProto), 16)}) |
| 2149 | if loIPProto == 2 { |
| 2150 | // some workaround for TT workflow on proto == 2 (IGMP trap) -> the flow was not added, no need to remove |
| 2151 | logger.Debugw("flow-remove type IpProto 2: TT workaround: ignore flow", |
| 2152 | log.Fields{"device-id": dh.deviceID}) |
| 2153 | return nil |
| 2154 | } |
| 2155 | } |
| 2156 | } //for all OfbFields |
| 2157 | */ |
| 2158 | |
| 2159 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.uniID]; exist { |
| 2160 | return dh.UniVlanConfigFsmMap[apUniPort.uniID].RemoveUniFlowParams(loCookie) |
| 2161 | } |
| 2162 | logger.Warnw("flow-remove called, but no flow is configured (no VlanConfigFsm)", |
| 2163 | log.Fields{"device-id": dh.deviceID}) |
| 2164 | //but as we regard the flow as not existing = removed we respond just ok |
| 2165 | return nil |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2168 | // createVlanFilterFsm initializes and runs the VlanFilter FSM to transfer OMCI related VLAN config |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2169 | func (dh *deviceHandler) createVlanFilterFsm(apUniPort *onuUniPort, aTpID uint16, aCookieSlice []uint64, |
| 2170 | aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8, aDevEvent OnuDeviceEvent) error { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2171 | chVlanFilterFsm := make(chan Message, 2048) |
| 2172 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2173 | pDevEntry := dh.getOnuDeviceEntry(true) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2174 | if pDevEntry == nil { |
| 2175 | logger.Errorw("No valid OnuDevice -aborting", log.Fields{"device-id": dh.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2176 | return fmt.Errorf("no valid OnuDevice for device-id %x - aborting", dh.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | pVlanFilterFsm := NewUniVlanConfigFsm(dh, pDevEntry.PDevOmciCC, apUniPort, dh.pOnuTP, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2180 | pDevEntry.pOnuDB, aTpID, aDevEvent, "UniVlanConfigFsm", chVlanFilterFsm, |
| 2181 | dh.pOpenOnuAc.AcceptIncrementalEvto, aCookieSlice, aMatchVlan, aSetVlan, aSetPcp) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2182 | if pVlanFilterFsm != nil { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2183 | dh.UniVlanConfigFsmMap[apUniPort.uniID] = pVlanFilterFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2184 | pVlanFilterStatemachine := pVlanFilterFsm.pAdaptFsm.pFsm |
| 2185 | if pVlanFilterStatemachine != nil { |
| 2186 | if pVlanFilterStatemachine.Is(vlanStDisabled) { |
| 2187 | if err := pVlanFilterStatemachine.Event(vlanEvStart); err != nil { |
| 2188 | logger.Warnw("UniVlanConfigFsm: can't start", log.Fields{"err": err}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2189 | return fmt.Errorf("can't start UniVlanConfigFsm for device-id %x", dh.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2190 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2191 | /***** UniVlanConfigFsm started */ |
| 2192 | logger.Debugw("UniVlanConfigFsm started", log.Fields{ |
| 2193 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.deviceID, |
| 2194 | "UniPort": apUniPort.portNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2195 | } else { |
| 2196 | logger.Warnw("wrong state of UniVlanConfigFsm - want: disabled", log.Fields{ |
| 2197 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2198 | return fmt.Errorf("uniVlanConfigFsm not in expected disabled state for device-id %x", dh.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2199 | } |
| 2200 | } else { |
| 2201 | logger.Errorw("UniVlanConfigFsm StateMachine invalid - cannot be executed!!", log.Fields{ |
| 2202 | "device-id": dh.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2203 | return fmt.Errorf("uniVlanConfigFsm invalid for device-id %x", dh.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2204 | } |
| 2205 | } else { |
| 2206 | logger.Errorw("UniVlanConfigFsm could not be created - abort!!", log.Fields{ |
| 2207 | "device-id": dh.deviceID, "UniPort": apUniPort.portNo}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2208 | return fmt.Errorf("uniVlanConfigFsm could not be created for device-id %x", dh.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2209 | } |
| 2210 | return nil |
| 2211 | } |
| 2212 | |
| 2213 | //verifyUniVlanConfigRequest checks on existence of flow configuration and starts it accordingly |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2214 | func (dh *deviceHandler) verifyUniVlanConfigRequest(apUniPort *onuUniPort) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2215 | //TODO!! verify and start pending flow configuration |
| 2216 | //some pending config request my exist in case the UniVlanConfig FSM was already started - with internal data - |
| 2217 | //but execution was set to 'on hold' as first the TechProfile config had to be applied |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2218 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[apUniPort.uniID]; exist { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2219 | //VlanFilterFsm exists and was already started (assumed to wait for TechProfile execution here) |
| 2220 | pVlanFilterStatemachine := pVlanFilterFsm.pAdaptFsm.pFsm |
| 2221 | if pVlanFilterStatemachine != nil { |
| 2222 | if pVlanFilterStatemachine.Is(vlanStWaitingTechProf) { |
| 2223 | if err := pVlanFilterStatemachine.Event(vlanEvContinueConfig); err != nil { |
| 2224 | logger.Warnw("UniVlanConfigFsm: can't continue processing", log.Fields{"err": err}) |
| 2225 | } else { |
| 2226 | /***** UniVlanConfigFsm continued */ |
| 2227 | logger.Debugw("UniVlanConfigFsm continued", log.Fields{ |
| 2228 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.deviceID, |
| 2229 | "UniPort": apUniPort.portNo}) |
| 2230 | } |
| 2231 | } else { |
| 2232 | logger.Debugw("no state of UniVlanConfigFsm to be continued", log.Fields{ |
| 2233 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.deviceID}) |
| 2234 | } |
| 2235 | } else { |
| 2236 | logger.Debugw("UniVlanConfigFsm StateMachine does not exist, no flow processing", log.Fields{ |
| 2237 | "device-id": dh.deviceID}) |
| 2238 | } |
| 2239 | |
| 2240 | } // else: nothing to do |
| 2241 | } |
| 2242 | |
| 2243 | //RemoveVlanFilterFsm deletes the stored pointer to the VlanConfigFsm |
| 2244 | // intention is to provide this method to be called from VlanConfigFsm itself, when resources (and methods!) are cleaned up |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2245 | func (dh *deviceHandler) RemoveVlanFilterFsm(apUniPort *onuUniPort) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2246 | logger.Debugw("remove UniVlanConfigFsm StateMachine", log.Fields{ |
| 2247 | "device-id": dh.deviceID, "uniPort": apUniPort.portNo}) |
| 2248 | //save to do, even if entry dows not exist |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2249 | delete(dh.UniVlanConfigFsmMap, apUniPort.uniID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2250 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2251 | |
| 2252 | //storePersUniFlowConfig updates local storage of OnuUniFlowConfig and writes it into kv-store afterwards to have it |
| 2253 | //available for potential reconcilement |
| 2254 | |
| 2255 | func (dh *deviceHandler) storePersUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]uniVlanFlowParams) error { |
| 2256 | |
| 2257 | if dh.reconciling { |
| 2258 | logger.Debugw("reconciling - don't store persistent UniFlowConfig", log.Fields{"device-id": dh.deviceID}) |
| 2259 | return nil |
| 2260 | } |
| 2261 | logger.Debugw("Store persistent UniFlowConfig", log.Fields{"device-id": dh.deviceID}) |
| 2262 | |
| 2263 | pDevEntry := dh.getOnuDeviceEntry(true) |
| 2264 | if pDevEntry == nil { |
| 2265 | logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": dh.deviceID}) |
| 2266 | return fmt.Errorf("no valid OnuDevice: %s", dh.deviceID) |
| 2267 | } |
| 2268 | pDevEntry.updateOnuUniFlowConfig(aUniID, aUniVlanFlowParams) |
| 2269 | |
| 2270 | pDevEntry.lockOnuKVStoreMutex() |
| 2271 | defer pDevEntry.unlockOnuKVStoreMutex() |
| 2272 | |
| 2273 | // deadline context to ensure completion of background routines waited for |
| 2274 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 2275 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2276 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 2277 | |
| 2278 | pDevEntry.resetKvProcessingErrorIndication() |
| 2279 | var wg sync.WaitGroup |
| 2280 | wg.Add(1) // for the 1 go routine to finish |
| 2281 | |
| 2282 | go pDevEntry.updateOnuKvStore(dctx, &wg) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2283 | dh.waitForCompletion(cancel, &wg, "UpdateKvStore") //wait for background process to finish |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2284 | |
| 2285 | return pDevEntry.getKvProcessingErrorIndication() |
| 2286 | } |
| 2287 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2288 | func (dh *deviceHandler) waitForCompletion(cancel context.CancelFunc, wg *sync.WaitGroup, aCallerIdent string) { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2289 | defer cancel() //ensure termination of context (may be pro forma) |
| 2290 | wg.Wait() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2291 | logger.Debugw("WaitGroup processing completed", log.Fields{ |
| 2292 | "device-id": dh.deviceID, "called from": aCallerIdent}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | func (dh *deviceHandler) combineErrorStrings(errS ...error) error { |
| 2296 | var errStr string = "" |
| 2297 | for _, err := range errS { |
| 2298 | if err != nil { |
| 2299 | errStr = errStr + err.Error() + " " |
| 2300 | } |
| 2301 | } |
| 2302 | if errStr != "" { |
| 2303 | return fmt.Errorf("%s: %s", errStr, dh.deviceID) |
| 2304 | } |
| 2305 | return nil |
| 2306 | } |