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