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