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 | "errors" |
| 23 | |
| 24 | "github.com/looplab/fsm" |
| 25 | |
| 26 | //"sync" |
| 27 | //"time" |
| 28 | |
| 29 | //"github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 30 | "github.com/opencord/omci-lib-go" |
| 31 | me "github.com/opencord/omci-lib-go/generated" |
| 32 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 33 | //ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 34 | //"github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 35 | //"github.com/opencord/voltha-protos/v3/go/voltha" |
| 36 | ) |
| 37 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 38 | func (onuDeviceEntry *OnuDeviceEntry) enterStartingState(e *fsm.Event) { |
| 39 | logger.Debugw("MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 40 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 41 | onuDeviceEntry.pOnuDB = NewOnuDeviceDB(context.TODO(), onuDeviceEntry) |
| 42 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 43 | go onuDeviceEntry.ProcessMibSyncMessages() |
| 44 | } |
| 45 | |
| 46 | func (onuDeviceEntry *OnuDeviceEntry) enterLoadingMibTemplateState(e *fsm.Event) { |
| 47 | logger.Debugw("MibSync FSM", log.Fields{"Start MibTemplate processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 48 | logger.Debug("function not implemented yet") |
| 49 | } |
| 50 | |
| 51 | func (onuDeviceEntry *OnuDeviceEntry) enterUploadingState(e *fsm.Event) { |
| 52 | logger.Debugw("MibSync FSM", log.Fields{"send mibReset in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 53 | onuDeviceEntry.PDevOmciCC.sendMibReset(context.TODO(), ConstDefaultOmciTimeout, true) |
| 54 | } |
| 55 | |
| 56 | func (onuDeviceEntry *OnuDeviceEntry) enterInSyncState(e *fsm.Event) { |
| 57 | logger.Debugw("MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 58 | onuDeviceEntry.transferSystemEvent(MibDatabaseSync) |
| 59 | } |
| 60 | |
| 61 | func (onuDeviceEntry *OnuDeviceEntry) enterExaminingMdsState(e *fsm.Event) { |
| 62 | logger.Debugw("MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 63 | logger.Debug("function not implemented yet") |
| 64 | } |
| 65 | |
| 66 | func (onuDeviceEntry *OnuDeviceEntry) enterResynchronizingState(e *fsm.Event) { |
| 67 | logger.Debugw("MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 68 | logger.Debug("function not implemented yet") |
| 69 | } |
| 70 | |
| 71 | func (onuDeviceEntry *OnuDeviceEntry) enterAuditingState(e *fsm.Event) { |
| 72 | logger.Debugw("MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 73 | logger.Debug("function not implemented yet") |
| 74 | } |
| 75 | |
| 76 | func (onuDeviceEntry *OnuDeviceEntry) enterOutOfSyncState(e *fsm.Event) { |
| 77 | logger.Debugw("MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 78 | logger.Debug("function not implemented yet") |
| 79 | } |
| 80 | |
| 81 | func (onuDeviceEntry *OnuDeviceEntry) ProcessMibSyncMessages( /*ctx context.Context*/ ) { |
| 82 | logger.Debugw("MibSync Msg", log.Fields{"Start routine to process OMCI-messages for device-id": onuDeviceEntry.deviceID}) |
| 83 | loop: |
| 84 | for { |
| 85 | select { |
| 86 | // case <-ctx.Done(): |
| 87 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID}) |
| 88 | // break loop |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 89 | case message, ok := <-onuDeviceEntry.pMibUploadFsm.commChan: |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 90 | if !ok { |
| 91 | logger.Info("MibSync Msg", log.Fields{"Message couldn't be read from channel for device-id": onuDeviceEntry.deviceID}) |
| 92 | break loop |
| 93 | } |
| 94 | logger.Debugw("MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": onuDeviceEntry.deviceID}) |
| 95 | |
| 96 | switch message.Type { |
| 97 | case TestMsg: |
| 98 | msg, _ := message.Data.(TestMessage) |
| 99 | onuDeviceEntry.handleTestMsg(msg) |
| 100 | case OMCI: |
| 101 | msg, _ := message.Data.(OmciMessage) |
| 102 | onuDeviceEntry.handleOmciMessage(msg) |
| 103 | default: |
| 104 | logger.Warn("MibSync Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID, "message.Type": message.Type}) |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | logger.Info("MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": onuDeviceEntry.deviceID}) |
| 109 | // TODO: only this action? |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 110 | onuDeviceEntry.pMibUploadFsm.pFsm.Event("stop") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | func (onuDeviceEntry *OnuDeviceEntry) handleTestMsg(msg TestMessage) { |
| 114 | |
| 115 | logger.Debugw("MibSync Msg", log.Fields{"TestMessage received for device-id": onuDeviceEntry.deviceID, "msg.TestMessageVal": msg.TestMessageVal}) |
| 116 | |
| 117 | switch msg.TestMessageVal { |
| 118 | case AnyTriggerForMibSyncUploadMib: |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 119 | onuDeviceEntry.pMibUploadFsm.pFsm.Event("upload_mib") |
| 120 | logger.Debugw("MibSync Msg", log.Fields{"state": string(onuDeviceEntry.pMibUploadFsm.pFsm.Current())}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 121 | default: |
| 122 | logger.Warn("MibSync Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID, "msg.TestMessageVal": msg.TestMessageVal}) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | func (onuDeviceEntry *OnuDeviceEntry) handleOmciMessage(msg OmciMessage) { |
| 127 | |
| 128 | logger.Debugw("MibSync Msg", log.Fields{"OmciMessage received for device-id": onuDeviceEntry.deviceID, |
| 129 | "msgType": msg.OmciMsg.MessageType}) |
| 130 | |
| 131 | //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ... |
| 132 | switch msg.OmciMsg.MessageType { |
| 133 | case omci.MibResetResponseType: |
| 134 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse) |
| 135 | if msgLayer == nil { |
| 136 | logger.Error("Omci Msg layer could not be detected") |
| 137 | return |
| 138 | } |
| 139 | msgObj, msgOk := msgLayer.(*omci.MibResetResponse) |
| 140 | if !msgOk { |
| 141 | logger.Error("Omci Msg layer could not be assigned") |
| 142 | return |
| 143 | } |
| 144 | logger.Debugw("MibResetResponse Data", log.Fields{"data-fields": msgObj}) |
| 145 | if msgObj.Result != me.Success { |
| 146 | logger.Errorw("Omci MibResetResponse Error - strange - what to do?", log.Fields{"Error": msgObj.Result}) |
| 147 | return |
| 148 | } |
| 149 | onuDeviceEntry.PDevOmciCC.sendMibUpload(context.TODO(), ConstDefaultOmciTimeout, true) |
| 150 | case omci.MibUploadResponseType: |
| 151 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse) |
| 152 | if msgLayer == nil { |
| 153 | logger.Error("Omci Msg layer could not be detected") |
| 154 | return |
| 155 | } |
| 156 | msgObj, msgOk := msgLayer.(*omci.MibUploadResponse) |
| 157 | if !msgOk { |
| 158 | logger.Error("Omci Msg layer could not be assigned") |
| 159 | return |
| 160 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 161 | logger.Debugw("MibUploadResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 162 | /* to be verified / reworked !!! */ |
| 163 | onuDeviceEntry.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands |
| 164 | if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds { |
| 165 | onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true) |
| 166 | } else { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 167 | logger.Error("Invalid number of commands received for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "uploadNoOfCmds": onuDeviceEntry.PDevOmciCC.uploadNoOfCmds}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 168 | //TODO right action? |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 169 | onuDeviceEntry.pMibUploadFsm.pFsm.Event("timeout") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 170 | } |
| 171 | case omci.MibUploadNextResponseType: |
| 172 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse) |
| 173 | if msgLayer == nil { |
| 174 | logger.Error("Omci Msg layer could not be detected") |
| 175 | return |
| 176 | } |
| 177 | msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse) |
| 178 | if !msgOk { |
| 179 | logger.Error("Omci Msg layer could not be assigned") |
| 180 | return |
| 181 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 182 | logger.Debugw("MibUploadNextResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
| 183 | |
| 184 | onuDeviceEntry.pOnuDB.StoreMe(msgObj) |
| 185 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 186 | if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds { |
| 187 | onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true) |
| 188 | } else { |
| 189 | //TODO |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 190 | onuDeviceEntry.pOnuDB.LogMeDb() |
| 191 | onuDeviceEntry.pMibUploadFsm.pFsm.Event("success") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | func (onuDeviceEntry *OnuDeviceEntry) MibDbVolatileDict() error { |
| 197 | logger.Debug("MibVolatileDict- running from default Entry code") |
| 198 | return errors.New("not_implemented") |
| 199 | } |
| 200 | |
| 201 | // func (onuDeviceEntry *OnuDeviceEntry) MibTemplateTask() error { |
| 202 | // return errors.New("not_implemented") |
| 203 | // } |
| 204 | // func (onuDeviceEntry *OnuDeviceEntry) MibUploadTask() error { |
| 205 | // return errors.New("not_implemented") |
| 206 | // } |
| 207 | // func (onuDeviceEntry *OnuDeviceEntry) GetMdsTask() error { |
| 208 | // return errors.New("not_implemented") |
| 209 | // } |
| 210 | // func (onuDeviceEntry *OnuDeviceEntry) MibResyncTask() error { |
| 211 | // return errors.New("not_implemented") |
| 212 | // } |
| 213 | // func (onuDeviceEntry *OnuDeviceEntry) MibReconcileTask() error { |
| 214 | // return errors.New("not_implemented") |
| 215 | // } |