Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +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 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 17 | //Package adaptercoreonu provides the utility for onu devices, flows and statistics |
| 18 | package adaptercoreonu |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 22 | "encoding/json" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 23 | "errors" |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 24 | "fmt" |
| 25 | "sync" |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 26 | "time" |
| 27 | |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 28 | "github.com/opencord/omci-lib-go" |
| 29 | me "github.com/opencord/omci-lib-go/generated" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 30 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 31 | //"sync" |
| 32 | //"time" |
| 33 | |
| 34 | "github.com/looplab/fsm" |
| 35 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 36 | "github.com/opencord/voltha-lib-go/v3/pkg/db" |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 37 | "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 38 | |
| 39 | //"github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 40 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 41 | //ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 42 | //"github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 43 | //"github.com/opencord/voltha-protos/v3/go/voltha" |
| 44 | ) |
| 45 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 46 | const ( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 47 | // events of MibUpload FSM |
| 48 | ulEvStart = "ulEvStart" |
| 49 | ulEvResetMib = "ulEvResetMib" |
| 50 | ulEvGetVendorAndSerial = "ulEvGetVendorAndSerial" |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 51 | ulEvGetEquipmentID = "ulEvGetEquipmentId" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 52 | ulEvGetFirstSwVersion = "ulEvGetFirstSwVersion" |
| 53 | ulEvGetSecondSwVersion = "ulEvGetSecondSwVersion" |
| 54 | ulEvGetMacAddress = "ulEvGetMacAddress" |
| 55 | ulEvGetMibTemplate = "ulEvGetMibTemplate" |
| 56 | ulEvUploadMib = "ulEvUploadMib" |
| 57 | ulEvExamineMds = "ulEvExamineMds" |
| 58 | ulEvSuccess = "ulEvSuccess" |
| 59 | ulEvMismatch = "ulEvMismatch" |
| 60 | ulEvAuditMib = "ulEvAuditMib" |
| 61 | ulEvForceResync = "ulEvForceResync" |
| 62 | ulEvDiffsFound = "ulEvDiffsFound" |
| 63 | ulEvTimeout = "ulEvTimeout" |
| 64 | ulEvStop = "ulEvStop" |
| 65 | ) |
| 66 | const ( |
| 67 | // states of MibUpload FSM |
| 68 | ulStDisabled = "ulStDisabled" |
| 69 | ulStStarting = "ulStStarting" |
| 70 | ulStResettingMib = "ulStResettingMib" |
| 71 | ulStGettingVendorAndSerial = "ulStGettingVendorAndSerial" |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 72 | ulStGettingEquipmentID = "ulStGettingEquipmentID" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 73 | ulStGettingFirstSwVersion = "ulStGettingFirstSwVersion" |
| 74 | ulStGettingSecondSwVersion = "ulStGettingSecondSwVersion" |
| 75 | ulStGettingMacAddress = "ulStGettingMacAddress" |
| 76 | ulStGettingMibTemplate = "ulStGettingMibTemplate" |
| 77 | ulStUploading = "ulStUploading" |
| 78 | ulStInSync = "ulStInSync" |
| 79 | ulStExaminingMds = "ulStExaminingMds" |
| 80 | ulStResynchronizing = "ulStResynchronizing" |
| 81 | ulStAuditing = "ulStAuditing" |
| 82 | ulStOutOfSync = "ulStOutOfSync" |
| 83 | ) |
| 84 | |
| 85 | const ( |
| 86 | // events of MibDownload FSM |
| 87 | dlEvStart = "dlEvStart" |
| 88 | dlEvCreateGal = "dlEvCreateGal" |
| 89 | dlEvRxGalResp = "dlEvRxGalResp" |
| 90 | dlEvRxOnu2gResp = "dlEvRxOnu2gResp" |
| 91 | dlEvRxBridgeResp = "dlEvRxBridgeResp" |
| 92 | dlEvTimeoutSimple = "dlEvTimeoutSimple" |
| 93 | dlEvTimeoutBridge = "dlEvTimeoutBridge" |
| 94 | dlEvReset = "dlEvReset" |
| 95 | dlEvRestart = "dlEvRestart" |
| 96 | ) |
| 97 | const ( |
| 98 | // states of MibDownload FSM |
| 99 | dlStDisabled = "dlStDisabled" |
| 100 | dlStStarting = "dlStStarting" |
| 101 | dlStCreatingGal = "dlStCreatingGal" |
| 102 | dlStSettingOnu2g = "dlStSettingOnu2g" |
| 103 | dlStBridgeInit = "dlStBridgeInit" |
| 104 | dlStDownloaded = "dlStDownloaded" |
| 105 | dlStResetting = "dlStResetting" |
| 106 | ) |
| 107 | |
| 108 | const ( |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 109 | cBasePathMibTemplateKvStore = "service/voltha/omci_mibs/go_templates" |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 110 | cSuffixMibTemplateKvStore = "%s/%s/%s" |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 111 | cBasePathOnuKVStore = "service/voltha/openonu" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 112 | ) |
| 113 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 114 | // OnuDeviceEvent - event of interest to Device Adapters and OpenOMCI State Machines |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 115 | type OnuDeviceEvent int |
| 116 | |
| 117 | const ( |
| 118 | // Events of interest to Device Adapters and OpenOMCI State Machines |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 119 | |
| 120 | // DeviceStatusInit - default start state |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 121 | DeviceStatusInit OnuDeviceEvent = iota |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 122 | // MibDatabaseSync - MIB database sync (upload done) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 123 | MibDatabaseSync |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 124 | // OmciCapabilitiesDone - OMCI ME and message type capabilities known |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 125 | OmciCapabilitiesDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 126 | // MibDownloadDone - // MIB download done |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 127 | MibDownloadDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 128 | // UniLockStateDone - Uni ports admin set to lock |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 129 | UniLockStateDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 130 | // UniUnlockStateDone - Uni ports admin set to unlock |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 131 | UniUnlockStateDone |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 132 | // UniDisableStateDone - Uni ports admin set to lock based on device disable |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 133 | UniDisableStateDone |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 134 | // UniEnableStateDone - Uni ports admin set to unlock based on device re-enable |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 135 | UniEnableStateDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 136 | // PortLinkUp - Port link state change |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 137 | PortLinkUp |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 138 | // PortLinkDw - Port link state change |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 139 | PortLinkDw |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 140 | // OmciAniConfigDone - AniSide config according to TechProfile done |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 141 | OmciAniConfigDone |
| 142 | // OmciAniResourceRemoved - AniSide TechProfile related resource (Gem/TCont) removed |
| 143 | OmciAniResourceRemoved // needs to be the successor of OmciAniConfigDone! |
| 144 | // OmciVlanFilterAddDone - Omci Vlan config done according to flow-add |
| 145 | OmciVlanFilterAddDone |
| 146 | // OmciVlanFilterRemDone - Omci Vlan config done according to flow-remove |
| 147 | OmciVlanFilterRemDone // needs to be the successor of OmciVlanFilterAddDone! |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 148 | // Add other events here as needed (alarms separate???) |
| 149 | ) |
| 150 | |
| 151 | type activityDescr struct { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 152 | databaseClass func() error |
| 153 | //advertiseEvents bool |
| 154 | auditDelay uint16 |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 155 | //tasks map[string]func() error |
| 156 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 157 | |
| 158 | // OmciDeviceFsms - FSM event mapping to database class and time to wait between audits |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 159 | type OmciDeviceFsms map[string]activityDescr |
| 160 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 161 | // AdapterFsm - Adapter FSM details including channel, event and device |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 162 | type AdapterFsm struct { |
| 163 | fsmName string |
| 164 | deviceID string |
| 165 | commChan chan Message |
| 166 | pFsm *fsm.FSM |
| 167 | } |
| 168 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 169 | //NewAdapterFsm - FSM details including event, device and channel. |
| 170 | func NewAdapterFsm(aName string, aDeviceID string, aCommChannel chan Message) *AdapterFsm { |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 171 | aFsm := &AdapterFsm{ |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 172 | fsmName: aName, |
| 173 | deviceID: aDeviceID, |
| 174 | commChan: aCommChannel, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 175 | } |
| 176 | return aFsm |
| 177 | } |
| 178 | |
| 179 | //Start starts (logs) the omci agent |
| 180 | func (oo *AdapterFsm) logFsmStateChange(e *fsm.Event) { |
| 181 | logger.Debugw("FSM state change", log.Fields{"device-id": oo.deviceID, "FSM name": oo.fsmName, |
| 182 | "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)}) |
| 183 | } |
| 184 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 185 | //OntDeviceEntry structure holds information about the attached FSM'as and their communication |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 186 | |
| 187 | const ( |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 188 | firstSwImageMeID = 0 |
| 189 | secondSwImageMeID = 1 |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 190 | ) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 191 | const onugMeID = 0 |
| 192 | const onu2gMeID = 0 |
| 193 | const ipHostConfigDataMeID = 1 |
| 194 | const onugSerialNumberLen = 8 |
| 195 | const omciMacAddressLen = 6 |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 196 | |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 197 | const cEmptyMacAddrString = "000000000000" |
| 198 | const cEmptySerialNumberString = "0000000000000000" |
| 199 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 200 | type swImages struct { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 201 | version string |
| 202 | isActive uint8 |
| 203 | } |
| 204 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 205 | type uniPersConfig struct { |
| 206 | PersUniID uint8 `json:"uni_id"` |
| 207 | PersTpPath string `json:"tp_path"` |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 208 | PersFlowParams []uniVlanFlowParams `json:"flow_params"` //as defined in omci_ani_config.go |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | type onuPersistentData struct { |
| 212 | PersOnuID uint32 `json:"onu_id"` |
| 213 | PersIntfID uint32 `json:"intf_id"` |
| 214 | PersSnr string `json:"serial_number"` |
| 215 | PersAdminState string `json:"admin_state"` |
| 216 | PersOperState string `json:"oper_state"` |
| 217 | PersUniConfig []uniPersConfig `json:"uni_config"` |
| 218 | } |
| 219 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 220 | // OnuDeviceEntry - ONU device info and FSM events. |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 221 | type OnuDeviceEntry struct { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 222 | deviceID string |
| 223 | baseDeviceHandler *deviceHandler |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame^] | 224 | pOpenOnuAc *OpenONUAC |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 225 | coreProxy adapterif.CoreProxy |
| 226 | adapterProxy adapterif.AdapterProxy |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 227 | PDevOmciCC *omciCC |
| 228 | pOnuDB *onuDeviceDB |
| 229 | mibTemplateKVStore *db.Backend |
| 230 | sOnuPersistentData onuPersistentData |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame^] | 231 | mibTemplatePath string |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 232 | onuKVStoreMutex sync.RWMutex |
| 233 | onuKVStore *db.Backend |
| 234 | onuKVStorePath string |
| 235 | onuKVStoreprocResult error //error indication of processing |
| 236 | chOnuKvProcessingStep chan uint8 |
| 237 | vendorID string |
| 238 | serialNumber string |
| 239 | equipmentID string |
| 240 | swImages [secondSwImageMeID + 1]swImages |
| 241 | activeSwVersion string |
| 242 | macAddress string |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 243 | //lockDeviceEntries sync.RWMutex |
| 244 | mibDbClass func() error |
| 245 | supportedFsms OmciDeviceFsms |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 246 | devState OnuDeviceEvent |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 247 | // for mibUpload |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 248 | mibAuditDelay uint16 |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 249 | |
| 250 | // for mibUpload |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 251 | pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later |
| 252 | // for mibDownload |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 253 | pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later |
| 254 | //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting |
| 255 | // within the FSM event procedures |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 256 | omciMessageReceived chan bool //seperate channel needed by DownloadFsm |
| 257 | omciRebootMessageReceivedChannel chan Message // channel needed by Reboot request |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 260 | //newOnuDeviceEntry returns a new instance of a OnuDeviceEntry |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 261 | //mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame^] | 262 | func newOnuDeviceEntry(ctx context.Context, dh *deviceHandler) *OnuDeviceEntry { |
| 263 | logger.Infow("init-onuDeviceEntry", log.Fields{"device-id": dh.deviceID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 264 | var onuDeviceEntry OnuDeviceEntry |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame^] | 265 | onuDeviceEntry.deviceID = dh.deviceID |
| 266 | onuDeviceEntry.baseDeviceHandler = dh |
| 267 | onuDeviceEntry.pOpenOnuAc = dh.pOpenOnuAc |
| 268 | onuDeviceEntry.coreProxy = dh.coreProxy |
| 269 | onuDeviceEntry.adapterProxy = dh.AdapterProxy |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 270 | onuDeviceEntry.devState = DeviceStatusInit |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 271 | onuDeviceEntry.sOnuPersistentData.PersUniConfig = make([]uniPersConfig, 0) |
| 272 | onuDeviceEntry.chOnuKvProcessingStep = make(chan uint8) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 273 | onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan Message, 2048) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 274 | //openomciagent.lockDeviceHandlersMap = sync.RWMutex{} |
| 275 | //OMCI related databases are on a per-agent basis. State machines and tasks |
| 276 | //are per ONU Vendor |
| 277 | // |
| 278 | // MIB Synchronization Database - possible overloading from arguments |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame^] | 279 | if dh.pOpenOnuAc.pSupportedFsms != nil { |
| 280 | onuDeviceEntry.supportedFsms = *dh.pOpenOnuAc.pSupportedFsms |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 281 | } else { |
| 282 | //var mibSyncFsm = NewMibSynchronizer() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 283 | // use some internaö defaults, if not defined from outside |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 284 | onuDeviceEntry.supportedFsms = OmciDeviceFsms{ |
| 285 | "mib-synchronizer": { |
| 286 | //mibSyncFsm, // Implements the MIB synchronization state machine |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 287 | onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 288 | //true, // Advertise events on OpenOMCI event bus |
| 289 | 60, // Time to wait between MIB audits. 0 to disable audits. |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 290 | // map[string]func() error{ |
| 291 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 292 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 293 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 294 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 295 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 296 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 297 | // }, |
| 298 | }, |
| 299 | } |
| 300 | } |
| 301 | onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 302 | logger.Debug("access2mibDbClass") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 303 | go onuDeviceEntry.mibDbClass() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 304 | onuDeviceEntry.mibAuditDelay = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditDelay |
| 305 | logger.Debugw("MibAudit is set to", log.Fields{"Delay": onuDeviceEntry.mibAuditDelay}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 306 | |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 307 | // Omci related Mib upload sync state machine |
| 308 | mibUploadChan := make(chan Message, 2048) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame^] | 309 | onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", dh.deviceID, mibUploadChan) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 310 | onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 311 | ulStDisabled, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 312 | fsm.Events{ |
| 313 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 314 | {Name: ulEvStart, Src: []string{ulStDisabled}, Dst: ulStStarting}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 315 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 316 | {Name: ulEvResetMib, Src: []string{ulStStarting}, Dst: ulStResettingMib}, |
| 317 | {Name: ulEvGetVendorAndSerial, Src: []string{ulStResettingMib}, Dst: ulStGettingVendorAndSerial}, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 318 | {Name: ulEvGetEquipmentID, Src: []string{ulStGettingVendorAndSerial}, Dst: ulStGettingEquipmentID}, |
| 319 | {Name: ulEvGetFirstSwVersion, Src: []string{ulStGettingEquipmentID}, Dst: ulStGettingFirstSwVersion}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 320 | {Name: ulEvGetSecondSwVersion, Src: []string{ulStGettingFirstSwVersion}, Dst: ulStGettingSecondSwVersion}, |
| 321 | {Name: ulEvGetMacAddress, Src: []string{ulStGettingSecondSwVersion}, Dst: ulStGettingMacAddress}, |
| 322 | {Name: ulEvGetMibTemplate, Src: []string{ulStGettingMacAddress}, Dst: ulStGettingMibTemplate}, |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 323 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 324 | {Name: ulEvUploadMib, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploading}, |
| 325 | {Name: ulEvExamineMds, Src: []string{ulStStarting}, Dst: ulStExaminingMds}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 326 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 327 | {Name: ulEvSuccess, Src: []string{ulStGettingMibTemplate}, Dst: ulStInSync}, |
| 328 | {Name: ulEvSuccess, Src: []string{ulStUploading}, Dst: ulStInSync}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 329 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 330 | {Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStInSync}, |
| 331 | {Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResynchronizing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 332 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 333 | {Name: ulEvAuditMib, Src: []string{ulStInSync}, Dst: ulStAuditing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 334 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 335 | {Name: ulEvSuccess, Src: []string{ulStOutOfSync}, Dst: ulStInSync}, |
| 336 | {Name: ulEvAuditMib, Src: []string{ulStOutOfSync}, Dst: ulStAuditing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 337 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 338 | {Name: ulEvSuccess, Src: []string{ulStAuditing}, Dst: ulStInSync}, |
| 339 | {Name: ulEvMismatch, Src: []string{ulStAuditing}, Dst: ulStResynchronizing}, |
| 340 | {Name: ulEvForceResync, Src: []string{ulStAuditing}, Dst: ulStResynchronizing}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 341 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 342 | {Name: ulEvSuccess, Src: []string{ulStResynchronizing}, Dst: ulStInSync}, |
| 343 | {Name: ulEvDiffsFound, Src: []string{ulStResynchronizing}, Dst: ulStOutOfSync}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 344 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 345 | {Name: ulEvTimeout, Src: []string{ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 346 | ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds, |
| 347 | ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStStarting}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 348 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 349 | {Name: ulEvStop, Src: []string{ulStStarting, ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 350 | ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds, |
| 351 | ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStDisabled}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 352 | }, |
| 353 | |
| 354 | fsm.Callbacks{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 355 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibUploadFsm.logFsmStateChange(e) }, |
| 356 | ("enter_" + ulStStarting): func(e *fsm.Event) { onuDeviceEntry.enterStartingState(e) }, |
| 357 | ("enter_" + ulStResettingMib): func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(e) }, |
| 358 | ("enter_" + ulStGettingVendorAndSerial): func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(e) }, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 359 | ("enter_" + ulStGettingEquipmentID): func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipmentIDState(e) }, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 360 | ("enter_" + ulStGettingFirstSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(e) }, |
| 361 | ("enter_" + ulStGettingSecondSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(e) }, |
| 362 | ("enter_" + ulStGettingMacAddress): func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(e) }, |
| 363 | ("enter_" + ulStGettingMibTemplate): func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplate(e) }, |
| 364 | ("enter_" + ulStUploading): func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(e) }, |
| 365 | ("enter_" + ulStExaminingMds): func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(e) }, |
| 366 | ("enter_" + ulStResynchronizing): func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(e) }, |
| 367 | ("enter_" + ulStAuditing): func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(e) }, |
| 368 | ("enter_" + ulStOutOfSync): func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(e) }, |
| 369 | ("enter_" + ulStInSync): func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(e) }, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 370 | }, |
| 371 | ) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 372 | // Omci related Mib download state machine |
| 373 | mibDownloadChan := make(chan Message, 2048) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame^] | 374 | onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", dh.deviceID, mibDownloadChan) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 375 | onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 376 | dlStDisabled, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 377 | fsm.Events{ |
| 378 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 379 | {Name: dlEvStart, Src: []string{dlStDisabled}, Dst: dlStStarting}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 380 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 381 | {Name: dlEvCreateGal, Src: []string{dlStStarting}, Dst: dlStCreatingGal}, |
| 382 | {Name: dlEvRxGalResp, Src: []string{dlStCreatingGal}, Dst: dlStSettingOnu2g}, |
| 383 | {Name: dlEvRxOnu2gResp, Src: []string{dlStSettingOnu2g}, Dst: dlStBridgeInit}, |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 384 | // the bridge state is used for multi ME config for alle UNI related ports |
| 385 | // maybe such could be reflected in the state machine as well (port number parametrized) |
| 386 | // but that looks not straightforward here - so we keep it simple here for the beginning(?) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 387 | {Name: dlEvRxBridgeResp, Src: []string{dlStBridgeInit}, Dst: dlStDownloaded}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 388 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 389 | {Name: dlEvTimeoutSimple, Src: []string{dlStCreatingGal, dlStSettingOnu2g}, Dst: dlStStarting}, |
| 390 | {Name: dlEvTimeoutBridge, Src: []string{dlStBridgeInit}, Dst: dlStStarting}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 391 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 392 | {Name: dlEvReset, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g, |
| 393 | dlStBridgeInit, dlStDownloaded}, Dst: dlStResetting}, |
| 394 | // exceptional treatment for all states except dlStResetting |
| 395 | {Name: dlEvRestart, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g, |
| 396 | dlStBridgeInit, dlStDownloaded, dlStResetting}, Dst: dlStDisabled}, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 397 | }, |
| 398 | |
| 399 | fsm.Callbacks{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 400 | "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(e) }, |
| 401 | ("enter_" + dlStStarting): func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(e) }, |
| 402 | ("enter_" + dlStCreatingGal): func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(e) }, |
| 403 | ("enter_" + dlStSettingOnu2g): func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(e) }, |
| 404 | ("enter_" + dlStBridgeInit): func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(e) }, |
| 405 | ("enter_" + dlStDownloaded): func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(e) }, |
| 406 | ("enter_" + dlStResetting): func(e *fsm.Event) { onuDeviceEntry.enterResettingState(e) }, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 407 | }, |
| 408 | ) |
| 409 | if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil { |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame^] | 410 | logger.Errorw("MibDownloadFsm could not be instantiated", log.Fields{"device-id": dh.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 411 | // TODO some specifc error treatment - or waiting for crash ? |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 412 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 413 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 414 | onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(cBasePathMibTemplateKvStore) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 415 | if onuDeviceEntry.mibTemplateKVStore == nil { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 416 | logger.Errorw("Can't access mibTemplateKVStore - no backend connection to service", |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame^] | 417 | log.Fields{"device-id": dh.deviceID, "service": cBasePathMibTemplateKvStore}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID |
| 421 | onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(cBasePathOnuKVStore) |
| 422 | if onuDeviceEntry.onuKVStore == nil { |
| 423 | logger.Errorw("Can't access onuKVStore - no backend connection to service", |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame^] | 424 | log.Fields{"device-id": dh.deviceID, "service": cBasePathOnuKVStore}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 427 | // Alarm Synchronization Database |
| 428 | //self._alarm_db = None |
| 429 | //self._alarm_database_cls = support_classes['alarm-synchronizer']['database'] |
| 430 | return &onuDeviceEntry |
| 431 | } |
| 432 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 433 | //start starts (logs) the omci agent |
| 434 | func (oo *OnuDeviceEntry) start(ctx context.Context) error { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 435 | logger.Infow("OnuDeviceEntry-starting", log.Fields{"for device-id": oo.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 436 | if oo.PDevOmciCC == nil { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 437 | oo.PDevOmciCC = newOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler, |
| 438 | oo.coreProxy, oo.adapterProxy) |
| 439 | if oo.PDevOmciCC == nil { |
| 440 | logger.Errorw("Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID}) |
| 441 | return fmt.Errorf("could not create devOmciCc %s", oo.deviceID) |
| 442 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 443 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 444 | return nil |
| 445 | } |
| 446 | |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 447 | //stop stops/resets the omciCC |
| 448 | func (oo *OnuDeviceEntry) stop(ctx context.Context, abResetOmciCC bool) error { |
| 449 | logger.Debugw("OnuDeviceEntry-stopping", log.Fields{"for device-id": oo.deviceID}) |
| 450 | if abResetOmciCC && (oo.PDevOmciCC != nil) { |
| 451 | _ = oo.PDevOmciCC.stop(ctx) |
| 452 | } |
| 453 | //to allow for all event notifications again when re-using the device and omciCC |
| 454 | oo.devState = DeviceStatusInit |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 455 | return nil |
| 456 | } |
| 457 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 458 | func (oo *OnuDeviceEntry) reboot(ctx context.Context) error { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 459 | logger.Debugw("OnuDeviceEntry-rebooting", log.Fields{"for device-id": oo.deviceID}) |
| 460 | if oo.PDevOmciCC != nil { |
| 461 | if err := oo.PDevOmciCC.sendReboot(ctx, ConstDefaultOmciTimeout, true, oo.omciRebootMessageReceivedChannel); err != nil { |
| 462 | logger.Errorw("onu didn't reboot", log.Fields{"for device-id": oo.deviceID}) |
| 463 | return err |
| 464 | } |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 465 | } |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 466 | return nil |
| 467 | } |
| 468 | |
| 469 | func (oo *OnuDeviceEntry) waitForRebootResponse(responseChannel chan Message) error { |
| 470 | select { |
| 471 | case <-time.After(3 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug |
| 472 | logger.Warnw("Reboot timeout", log.Fields{"for device-id": oo.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 473 | return fmt.Errorf("rebootTimeout") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 474 | case data := <-responseChannel: |
| 475 | switch data.Data.(OmciMessage).OmciMsg.MessageType { |
| 476 | case omci.RebootResponseType: |
| 477 | { |
| 478 | msgLayer := (*data.Data.(OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse) |
| 479 | if msgLayer == nil { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 480 | return fmt.Errorf("omci Msg layer could not be detected for RebootResponseType") |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 481 | } |
Andrea Campanella | bef4e54 | 2020-10-22 11:01:28 +0200 | [diff] [blame] | 482 | msgObj, msgOk := msgLayer.(*omci.RebootResponse) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 483 | if !msgOk { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 484 | return fmt.Errorf("omci Msg layer could not be assigned for RebootResponseType %s", oo.deviceID) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 485 | } |
Andrea Campanella | bef4e54 | 2020-10-22 11:01:28 +0200 | [diff] [blame] | 486 | logger.Debugw("RebootResponse data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 487 | if msgObj.Result != me.Success { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 488 | logger.Errorw("Omci RebootResponse result error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 489 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
Andrea Campanella | bef4e54 | 2020-10-22 11:01:28 +0200 | [diff] [blame] | 490 | return fmt.Errorf("omci RebootResponse result error indication %s for device %s", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 491 | msgObj.Result, oo.deviceID) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 492 | } |
| 493 | return nil |
| 494 | } |
| 495 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 496 | logger.Warnw("Reboot response message type error", log.Fields{"for device-id": oo.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 497 | return fmt.Errorf("unexpected OmciResponse type received %s", oo.deviceID) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 501 | //Relay the InSync message via Handler to Rw core - Status update |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 502 | func (oo *OnuDeviceEntry) transferSystemEvent(devEvent OnuDeviceEvent) { |
| 503 | logger.Debugw("relaying system-event", log.Fields{"Event": devEvent}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 504 | // decouple the handler transfer from further processing here |
| 505 | // TODO!!! check if really no synch is required within the system e.g. to ensure following steps .. |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 506 | if devEvent == MibDatabaseSync { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 507 | if oo.devState < MibDatabaseSync { //devState has not been synced yet |
| 508 | oo.devState = MibDatabaseSync |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 509 | go oo.baseDeviceHandler.deviceProcStatusUpdate(devEvent) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 510 | //TODO!!! device control: next step: start MIB capability verification from here ?!!! |
| 511 | } else { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 512 | logger.Debugw("mibinsync-event in some already synced state - ignored", log.Fields{"state": oo.devState}) |
| 513 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 514 | } else if devEvent == MibDownloadDone { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 515 | if oo.devState < MibDownloadDone { //devState has not been synced yet |
| 516 | oo.devState = MibDownloadDone |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 517 | go oo.baseDeviceHandler.deviceProcStatusUpdate(devEvent) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 518 | } else { |
| 519 | logger.Debugw("mibdownloaddone-event was already seen - ignored", log.Fields{"state": oo.devState}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 520 | } |
| 521 | } else { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 522 | logger.Warnw("device-event not yet handled", log.Fields{"state": devEvent}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 523 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 524 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 525 | |
| 526 | func (oo *OnuDeviceEntry) restoreDataFromOnuKvStore(ctx context.Context) error { |
| 527 | if oo.onuKVStore == nil { |
| 528 | logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
| 529 | return fmt.Errorf(fmt.Sprintf("onuKVStore-not-set-abort-%s", oo.deviceID)) |
| 530 | } |
| 531 | oo.sOnuPersistentData = onuPersistentData{0, 0, "", "", "", make([]uniPersConfig, 0)} |
| 532 | Value, err := oo.onuKVStore.Get(ctx, oo.onuKVStorePath) |
| 533 | if err == nil { |
| 534 | if Value != nil { |
| 535 | logger.Debugw("ONU-data read", |
| 536 | log.Fields{"Key": Value.Key, "device-id": oo.deviceID}) |
| 537 | tmpBytes, _ := kvstore.ToByte(Value.Value) |
| 538 | |
| 539 | if err = json.Unmarshal(tmpBytes, &oo.sOnuPersistentData); err != nil { |
| 540 | logger.Errorw("unable to unmarshal ONU-data", log.Fields{"error": err, "device-id": oo.deviceID}) |
| 541 | return fmt.Errorf(fmt.Sprintf("unable-to-unmarshal-ONU-data-%s", oo.deviceID)) |
| 542 | } |
| 543 | logger.Debugw("ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData, |
| 544 | "device-id": oo.deviceID}) |
| 545 | } else { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 546 | logger.Debugw("no ONU-data found", log.Fields{"path": oo.onuKVStorePath, "device-id": oo.deviceID}) |
| 547 | return fmt.Errorf("no-ONU-data-found") |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 548 | } |
| 549 | } else { |
| 550 | logger.Errorw("unable to read from KVstore", log.Fields{"device-id": oo.deviceID}) |
| 551 | return fmt.Errorf(fmt.Sprintf("unable-to-read-from-KVstore-%s", oo.deviceID)) |
| 552 | } |
| 553 | return nil |
| 554 | } |
| 555 | |
| 556 | func (oo *OnuDeviceEntry) deleteDataFromOnuKvStore(ctx context.Context, wg *sync.WaitGroup) { |
| 557 | defer wg.Done() |
| 558 | |
| 559 | if oo.onuKVStore == nil { |
| 560 | logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
| 561 | oo.onuKVStoreprocResult = errors.New("onu-data delete aborted: onuKVStore not set") |
| 562 | return |
| 563 | } |
| 564 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep |
| 565 | go oo.deletePersistentData(ctx, processingStep) |
| 566 | if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) { |
| 567 | //timeout or error detected |
| 568 | logger.Debugw("ONU-data not deleted - abort", log.Fields{"device-id": oo.deviceID}) |
| 569 | oo.onuKVStoreprocResult = errors.New("onu-data delete aborted: during kv-access") |
| 570 | return |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | func (oo *OnuDeviceEntry) deletePersistentData(ctx context.Context, aProcessingStep uint8) { |
| 575 | |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 576 | logger.Debugw("delete and clear internal persistency data", log.Fields{"device-id": oo.deviceID}) |
| 577 | oo.sOnuPersistentData.PersUniConfig = nil //releasing all UniConfig entries to garbage collector |
| 578 | oo.sOnuPersistentData = onuPersistentData{0, 0, "", "", "", make([]uniPersConfig, 0)} //default entry |
| 579 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 580 | logger.Debugw("delete ONU-data from KVStore", log.Fields{"device-id": oo.deviceID}) |
| 581 | err := oo.onuKVStore.Delete(ctx, oo.onuKVStorePath) |
| 582 | if err != nil { |
| 583 | logger.Errorw("unable to delete in KVstore", log.Fields{"device-id": oo.deviceID, "err": err}) |
| 584 | oo.chOnuKvProcessingStep <- 0 //error indication |
| 585 | return |
| 586 | } |
| 587 | oo.chOnuKvProcessingStep <- aProcessingStep //done |
| 588 | } |
| 589 | |
| 590 | func (oo *OnuDeviceEntry) updateOnuKvStore(ctx context.Context, wg *sync.WaitGroup) { |
| 591 | defer wg.Done() |
| 592 | |
| 593 | if oo.onuKVStore == nil { |
| 594 | logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": oo.deviceID}) |
| 595 | oo.onuKVStoreprocResult = errors.New("onu-data update aborted: onuKVStore not set") |
| 596 | return |
| 597 | } |
| 598 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chOnuKvProcessingStep |
| 599 | go oo.storeDataInOnuKvStore(ctx, processingStep) |
| 600 | if !oo.waitForTimeoutOrCompletion(ctx, oo.chOnuKvProcessingStep, processingStep) { |
| 601 | //timeout or error detected |
| 602 | logger.Debugw("ONU-data not written - abort", log.Fields{"device-id": oo.deviceID}) |
| 603 | oo.onuKVStoreprocResult = errors.New("onu-data update aborted: during writing process") |
| 604 | return |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | func (oo *OnuDeviceEntry) storeDataInOnuKvStore(ctx context.Context, aProcessingStep uint8) { |
| 609 | |
| 610 | //assign values which are not already present when newOnuDeviceEntry() is called |
| 611 | oo.sOnuPersistentData.PersOnuID = oo.baseDeviceHandler.pOnuIndication.OnuId |
| 612 | oo.sOnuPersistentData.PersIntfID = oo.baseDeviceHandler.pOnuIndication.IntfId |
| 613 | oo.sOnuPersistentData.PersSnr = oo.baseDeviceHandler.pOnuOmciDevice.serialNumber |
| 614 | //TODO: verify usage of these values during restart UC |
| 615 | oo.sOnuPersistentData.PersAdminState = "up" |
| 616 | oo.sOnuPersistentData.PersOperState = "active" |
| 617 | |
| 618 | logger.Debugw("Update ONU-data in KVStore", log.Fields{"device-id": oo.deviceID, "sOnuPersistentData": oo.sOnuPersistentData}) |
| 619 | |
| 620 | Value, err := json.Marshal(oo.sOnuPersistentData) |
| 621 | if err != nil { |
| 622 | logger.Errorw("unable to marshal ONU-data", log.Fields{"sOnuPersistentData": oo.sOnuPersistentData, |
| 623 | "device-id": oo.deviceID, "err": err}) |
| 624 | oo.chOnuKvProcessingStep <- 0 //error indication |
| 625 | return |
| 626 | } |
| 627 | err = oo.onuKVStore.Put(ctx, oo.onuKVStorePath, Value) |
| 628 | if err != nil { |
| 629 | logger.Errorw("unable to write ONU-data into KVstore", log.Fields{"device-id": oo.deviceID, "err": err}) |
| 630 | oo.chOnuKvProcessingStep <- 0 //error indication |
| 631 | return |
| 632 | } |
| 633 | oo.chOnuKvProcessingStep <- aProcessingStep //done |
| 634 | } |
| 635 | |
| 636 | func (oo *OnuDeviceEntry) updateOnuUniTpPath(aUniID uint8, aPathString string) bool { |
| 637 | /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially, |
| 638 | as also the complete sequence is ensured to 'run to completion' before some new request is accepted |
| 639 | no specific concurrency protection to sOnuPersistentData is required here |
| 640 | */ |
| 641 | for k, v := range oo.sOnuPersistentData.PersUniConfig { |
| 642 | if v.PersUniID == aUniID { |
| 643 | logger.Debugw("PersUniConfig-entry already exists", log.Fields{"device-id": oo.deviceID, "uniID": aUniID}) |
| 644 | existingPath := oo.sOnuPersistentData.PersUniConfig[k].PersTpPath |
| 645 | if existingPath != aPathString { |
| 646 | if aPathString == "" { |
| 647 | //existing entry to be deleted |
| 648 | logger.Debugw("UniTp delete path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 649 | oo.sOnuPersistentData.PersUniConfig[k].PersTpPath = "" |
| 650 | } else { |
| 651 | //existing entry to be modified |
| 652 | logger.Debugw("UniTp modify path value", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 653 | oo.sOnuPersistentData.PersUniConfig[k].PersTpPath = aPathString |
| 654 | } |
| 655 | return true |
| 656 | } |
| 657 | //entry already exists |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 658 | if aPathString == "" { |
| 659 | //no active TechProfile |
| 660 | logger.Debugw("UniTp path has already been removed - no AniSide config to be removed", log.Fields{ |
| 661 | "device-id": oo.deviceID, "uniID": aUniID}) |
| 662 | // attention 201105: this block is at the moment entered for each of subsequent GemPortDeletes and TContDelete |
| 663 | // as the path is already cleared with the first GemPort - this will probably change with the upcoming real |
| 664 | // TechProfile removal (still TODO), but anyway the reasonUpdate initiated here should not harm overall behavior |
| 665 | go oo.baseDeviceHandler.deviceProcStatusUpdate(OmciAniResourceRemoved) |
| 666 | // no flow config pending on 'remove' so far |
| 667 | } else { |
| 668 | //the given TechProfile already exists and is assumed to be active - update devReason as if the config has been done here |
| 669 | //was needed e.g. in voltha POD Tests:Validate authentication on a disabled ONU |
| 670 | // (as here the TechProfile has not been removed with the disable-device before the new enable-device) |
| 671 | logger.Debugw("UniTp path already exists - TechProfile supposed to be active", log.Fields{ |
| 672 | "device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 673 | //no deviceReason update (deviceProcStatusUpdate) here to ensure 'omci_flows_pushed' state within disable/enable procedure of ATT scenario |
| 674 | // (during which the flows are removed/re-assigned but the techProf is left active) |
| 675 | //and as the TechProfile is regarded as active we have to verify, if some flow configuration still waits on it |
| 676 | // (should not be the case, but should not harm or be more robust ...) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 677 | // and to be sure, that for some reason the corresponding TpDelete was lost somewhere in history |
| 678 | // we also reset a possibly outstanding delete request - repeated TpConfig is regarded as valid for waiting flow config |
| 679 | if oo.baseDeviceHandler.pOnuTP != nil { |
| 680 | oo.baseDeviceHandler.pOnuTP.setProfileToDelete(aUniID, false) |
| 681 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 682 | go oo.baseDeviceHandler.VerifyVlanConfigRequest(aUniID) |
| 683 | } |
| 684 | return false //indicate 'no change' - nothing more to do, TechProf inter-adapter message is return with success anyway here |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | //no entry exists for uniId |
| 688 | |
| 689 | if aPathString == "" { |
| 690 | //delete request in non-existing state , accept as no change |
| 691 | logger.Debugw("UniTp path already removed", log.Fields{"device-id": oo.deviceID, "uniID": aUniID}) |
| 692 | return false |
| 693 | } |
| 694 | //new entry to be created |
| 695 | logger.Debugw("New UniTp path set", log.Fields{"device-id": oo.deviceID, "uniID": aUniID, "path": aPathString}) |
| 696 | oo.sOnuPersistentData.PersUniConfig = |
| 697 | append(oo.sOnuPersistentData.PersUniConfig, uniPersConfig{PersUniID: aUniID, PersTpPath: aPathString, PersFlowParams: make([]uniVlanFlowParams, 0)}) |
| 698 | return true |
| 699 | } |
| 700 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 701 | func (oo *OnuDeviceEntry) updateOnuUniFlowConfig(aUniID uint8, aUniVlanFlowParams *[]uniVlanFlowParams) { |
| 702 | |
| 703 | for k, v := range oo.sOnuPersistentData.PersUniConfig { |
| 704 | if v.PersUniID == aUniID { |
| 705 | oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams = make([]uniVlanFlowParams, len(*aUniVlanFlowParams)) |
| 706 | copy(oo.sOnuPersistentData.PersUniConfig[k].PersFlowParams, *aUniVlanFlowParams) |
| 707 | return |
| 708 | } |
| 709 | } |
| 710 | //flow update was faster than tp-config - create PersUniConfig-entry |
| 711 | tmpConfig := uniPersConfig{PersUniID: aUniID, PersTpPath: "", PersFlowParams: make([]uniVlanFlowParams, len(*aUniVlanFlowParams))} |
| 712 | copy(tmpConfig.PersFlowParams, *aUniVlanFlowParams) |
| 713 | oo.sOnuPersistentData.PersUniConfig = append(oo.sOnuPersistentData.PersUniConfig, tmpConfig) |
| 714 | } |
| 715 | |
| 716 | func (oo *OnuDeviceEntry) waitForTimeoutOrCompletion( |
| 717 | ctx context.Context, aChOnuProcessingStep <-chan uint8, aProcessingStep uint8) bool { |
| 718 | select { |
| 719 | case <-ctx.Done(): |
| 720 | logger.Warnw("processing not completed in-time!", |
| 721 | log.Fields{"device-id": oo.deviceID, "error": ctx.Err()}) |
| 722 | return false |
| 723 | case rxStep := <-aChOnuProcessingStep: |
| 724 | if rxStep == aProcessingStep { |
| 725 | return true |
| 726 | } |
| 727 | //all other values are not accepted - including 0 for error indication |
| 728 | logger.Warnw("Invalid processing step received: abort!", |
| 729 | log.Fields{"device-id": oo.deviceID, |
| 730 | "wantedStep": aProcessingStep, "haveStep": rxStep}) |
| 731 | return false |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | func (oo *OnuDeviceEntry) resetKvProcessingErrorIndication() { |
| 736 | oo.onuKVStoreprocResult = nil |
| 737 | } |
| 738 | func (oo *OnuDeviceEntry) getKvProcessingErrorIndication() error { |
| 739 | return oo.onuKVStoreprocResult |
| 740 | } |
| 741 | |
| 742 | func (oo *OnuDeviceEntry) lockOnuKVStoreMutex() { |
| 743 | oo.onuKVStoreMutex.Lock() |
| 744 | } |
| 745 | |
| 746 | func (oo *OnuDeviceEntry) unlockOnuKVStoreMutex() { |
| 747 | oo.onuKVStoreMutex.Unlock() |
| 748 | } |