mpagenko | af80163 | 2020-07-03 10:00:42 +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/json" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 23 | "errors" |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 24 | "fmt" |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 25 | "strconv" |
| 26 | "strings" |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 27 | "sync" |
| 28 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 29 | "github.com/looplab/fsm" |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 30 | "github.com/opencord/voltha-lib-go/v3/pkg/db" |
| 31 | "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore" |
| 32 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 33 | tp "github.com/opencord/voltha-lib-go/v3/pkg/techprofile" |
| 34 | ) |
| 35 | |
| 36 | const cBasePathTechProfileKVStore = "service/voltha/technology_profiles" |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 37 | const cBasePathOnuKVStore = "service/voltha/openonu" |
| 38 | |
| 39 | //definitions for TechProfileProcessing - copied from OltAdapter:openolt_flowmgr.go |
| 40 | // could perhaps be defined more globally |
| 41 | const ( |
| 42 | // BinaryStringPrefix is binary string prefix |
| 43 | BinaryStringPrefix = "0b" |
| 44 | // BinaryBit1 is binary bit 1 expressed as a character |
| 45 | BinaryBit1 = '1' |
| 46 | ) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 47 | |
| 48 | type resourceEntry int |
| 49 | |
| 50 | const ( |
| 51 | cResourceGemPort resourceEntry = 1 |
| 52 | cResourceTcont resourceEntry = 2 |
| 53 | ) |
| 54 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 55 | type uniPersData struct { |
| 56 | PersUniId uint32 `json:"uni_id"` |
| 57 | PersTpPath string `json:"tp_path"` |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | type onuPersistentData struct { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 61 | PersOnuID uint32 `json:"onu_id"` |
| 62 | PersIntfID uint32 `json:"intf_id"` |
| 63 | PersSnr string `json:"serial_number"` |
| 64 | PersAdminState string `json:"admin_state"` |
| 65 | PersOperState string `json:"oper_state"` |
| 66 | PersUniTpPath []uniPersData `json:"uni_config"` |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 67 | } |
| 68 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 69 | type tTechProfileIndication struct { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 70 | techProfileType string |
| 71 | techProfileID uint16 |
| 72 | techProfileConfigDone bool |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | type tcontParamStruct struct { |
| 76 | allocID uint16 |
| 77 | schedPolicy uint8 |
| 78 | } |
| 79 | type gemPortParamStruct struct { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 80 | ponOmciCC bool |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 81 | gemPortID uint16 |
| 82 | direction uint8 |
| 83 | gemPortEncState uint8 |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 84 | prioQueueIndex uint8 |
| 85 | pbitString string |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 86 | discardPolicy string |
| 87 | //could also be a queue specific paramter, not used that way here |
| 88 | maxQueueSize uint16 |
| 89 | queueSchedPolicy string |
| 90 | queueWeight uint8 |
| 91 | } |
| 92 | |
| 93 | //refers to one tcont and its properties and all assigned GemPorts and their properties |
| 94 | type tcontGemList struct { |
| 95 | tcontParams tcontParamStruct |
| 96 | mapGemPortParams map[uint16]*gemPortParamStruct |
| 97 | } |
| 98 | |
| 99 | //refers to all tcont and their Tcont/GemPort Parameters |
| 100 | type tMapPonAniConfig map[uint16]*tcontGemList |
| 101 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 102 | //OnuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU |
| 103 | type OnuUniTechProf struct { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 104 | deviceID string |
| 105 | baseDeviceHandler *DeviceHandler |
| 106 | tpProcMutex sync.RWMutex |
| 107 | mapUniTpPath map[uint32]string |
| 108 | sOnuPersistentData onuPersistentData |
| 109 | techProfileKVStore *db.Backend |
| 110 | onuKVStore *db.Backend |
| 111 | onuKVStorePath string |
| 112 | chTpConfigProcessingStep chan uint8 |
| 113 | chTpKvProcessingStep chan uint8 |
| 114 | mapUniTpIndication map[uint8]*tTechProfileIndication //use pointer values to ease assignments to the map |
| 115 | mapPonAniConfig map[uint8]*tMapPonAniConfig //per UNI: use pointer values to ease assignments to the map |
| 116 | pAniConfigFsm *UniPonAniConfigFsm |
| 117 | procResult error //error indication of processing |
| 118 | mutexTPState sync.Mutex |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | //NewOnuUniTechProf returns the instance of a OnuUniTechProf |
| 122 | //(one instance per ONU/deviceHandler for all possible UNI's) |
| 123 | func NewOnuUniTechProf(ctx context.Context, aDeviceID string, aDeviceHandler *DeviceHandler) *OnuUniTechProf { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 124 | logger.Infow("init-OnuUniTechProf", log.Fields{"device-id": aDeviceID}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 125 | var onuTP OnuUniTechProf |
| 126 | onuTP.deviceID = aDeviceID |
| 127 | onuTP.baseDeviceHandler = aDeviceHandler |
| 128 | onuTP.tpProcMutex = sync.RWMutex{} |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 129 | onuTP.mapUniTpPath = make(map[uint32]string) |
| 130 | onuTP.sOnuPersistentData.PersUniTpPath = make([]uniPersData, 1) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 131 | onuTP.chTpConfigProcessingStep = make(chan uint8) |
| 132 | onuTP.chTpKvProcessingStep = make(chan uint8) |
| 133 | onuTP.mapUniTpIndication = make(map[uint8]*tTechProfileIndication) |
| 134 | onuTP.mapPonAniConfig = make(map[uint8]*tMapPonAniConfig) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 135 | onuTP.procResult = nil //default assumption processing done with success |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 136 | |
| 137 | onuTP.techProfileKVStore = aDeviceHandler.SetBackend(cBasePathTechProfileKVStore) |
| 138 | if onuTP.techProfileKVStore == nil { |
| 139 | logger.Errorw("Can't access techProfileKVStore - no backend connection to service", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 140 | log.Fields{"device-id": aDeviceID, "service": cBasePathTechProfileKVStore}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 141 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 142 | |
| 143 | onuTP.onuKVStorePath = onuTP.deviceID |
| 144 | onuTP.onuKVStore = aDeviceHandler.SetBackend(cBasePathOnuKVStore) |
| 145 | if onuTP.onuKVStore == nil { |
| 146 | logger.Errorw("Can't access onuKVStore - no backend connection to service", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 147 | log.Fields{"device-id": aDeviceID, "service": cBasePathOnuKVStore}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 148 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 149 | return &onuTP |
| 150 | } |
| 151 | |
| 152 | // lockTpProcMutex locks OnuUniTechProf processing mutex |
| 153 | func (onuTP *OnuUniTechProf) lockTpProcMutex() { |
| 154 | onuTP.tpProcMutex.Lock() |
| 155 | } |
| 156 | |
| 157 | // unlockTpProcMutex unlocks OnuUniTechProf processing mutex |
| 158 | func (onuTP *OnuUniTechProf) unlockTpProcMutex() { |
| 159 | onuTP.tpProcMutex.Unlock() |
| 160 | } |
| 161 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 162 | // resetProcessingErrorIndication resets the internal error indication |
| 163 | // need to be called before evaluation of any subsequent processing (given by waitForTpCompletion()) |
| 164 | func (onuTP *OnuUniTechProf) resetProcessingErrorIndication() { |
| 165 | onuTP.procResult = nil |
| 166 | } |
| 167 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 168 | // updateOnuUniTpPath verifies and updates changes in the kvStore onuUniTpPath |
| 169 | func (onuTP *OnuUniTechProf) updateOnuUniTpPath(aUniID uint32, aPathString string) bool { |
| 170 | /* within some specific InterAdapter processing request write/read access to data is ensured to be sequentially, |
| 171 | as also the complete sequence is ensured to 'run to completion' before some new request is accepted |
| 172 | no specific concurrency protection to sOnuPersistentData is required here |
| 173 | */ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 174 | if existingPath, present := onuTP.mapUniTpPath[aUniID]; present { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 175 | // uni entry already exists |
| 176 | //logger.Debugw(" already exists", log.Fields{"for InstanceId": a_uniInstNo}) |
| 177 | if existingPath != aPathString { |
| 178 | if aPathString == "" { |
| 179 | //existing entry to be deleted |
| 180 | logger.Debugw("UniTp path delete", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 181 | "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 182 | delete(onuTP.mapUniTpPath, aUniID) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 183 | } else { |
| 184 | //existing entry to be modified |
| 185 | logger.Debugw("UniTp path modify", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 186 | "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 187 | onuTP.mapUniTpPath[aUniID] = aPathString |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 188 | } |
| 189 | return true |
| 190 | } |
| 191 | //entry already exists |
| 192 | logger.Debugw("UniTp path already exists", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 193 | "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 194 | return false |
| 195 | } |
| 196 | //uni entry does not exist |
| 197 | if aPathString == "" { |
| 198 | //delete request in non-existing state , accept as no change |
| 199 | logger.Debugw("UniTp path already removed", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 200 | "device-id": onuTP.deviceID, "uniID": aUniID}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 201 | return false |
| 202 | } |
| 203 | //new entry to be set |
| 204 | logger.Debugw("New UniTp path set", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 205 | "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 206 | onuTP.mapUniTpPath[aUniID] = aPathString |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 207 | return true |
| 208 | } |
| 209 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 210 | func (onuTP *OnuUniTechProf) waitForTpCompletion(cancel context.CancelFunc, wg *sync.WaitGroup) error { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 211 | defer cancel() //ensure termination of context (may be pro forma) |
| 212 | wg.Wait() |
| 213 | logger.Debug("some TechProfile Processing completed") |
| 214 | onuTP.tpProcMutex.Unlock() //allow further TP related processing |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 215 | return onuTP.procResult |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | // configureUniTp checks existing tp resources to delete and starts the corresponding OMCI configuation of the UNI port |
| 219 | // all possibly blocking processing must be run in background to allow for deadline supervision! |
| 220 | // but take care on sequential background processing when needed (logical dependencies) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 221 | // use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronisation |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 222 | func (onuTP *OnuUniTechProf) configureUniTp(ctx context.Context, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 223 | aUniID uint8, aPathString string, wg *sync.WaitGroup) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 224 | defer wg.Done() //always decrement the waitGroup on return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 225 | logger.Debugw("configure the Uni according to TpPath", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 226 | "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 227 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 228 | if onuTP.techProfileKVStore == nil { |
| 229 | logger.Debug("techProfileKVStore not set - abort") |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 230 | onuTP.procResult = errors.New("TechProfile config aborted: techProfileKVStore not set") |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 231 | return |
| 232 | } |
| 233 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 234 | //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities) |
| 235 | var pCurrentUniPort *OnuUniPort |
| 236 | for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap { |
| 237 | // only if this port is validated for operState transfer |
| 238 | if uniPort.uniId == uint8(aUniID) { |
| 239 | pCurrentUniPort = uniPort |
| 240 | break //found - end search loop |
| 241 | } |
| 242 | } |
| 243 | if pCurrentUniPort == nil { |
| 244 | logger.Errorw("TechProfile configuration aborted: requested uniID not found in PortDB", |
| 245 | log.Fields{"device-id": onuTP.deviceID, "uniID": aUniID}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 246 | onuTP.procResult = errors.New("TechProfile config aborted: requested uniID not found") |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 247 | return |
| 248 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 249 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 250 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 251 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 252 | //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called |
| 253 | // in case the KVPath has changed for the given UNI, |
| 254 | // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing |
| 255 | // (ANI) configuration of this port has to be removed first |
| 256 | // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well) |
| 257 | // existence of configuration can be detected based on tp stored TCONT's |
| 258 | //TODO!!!: |
| 259 | /* if tcontMap not empty { |
| 260 | go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 261 | if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 262 | //timeout or error detected |
| 263 | return |
| 264 | } |
| 265 | clear tcontMap |
| 266 | } |
| 267 | |
| 268 | processingStep++ |
| 269 | */ |
| 270 | go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, aPathString, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 271 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 272 | //timeout or error detected |
| 273 | logger.Debugw("tech-profile related configuration aborted on read", |
| 274 | log.Fields{"device-id": onuTP.deviceID, "UniId": aUniID}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 275 | onuTP.procResult = errors.New("TechProfile config aborted: tech-profile read issue") |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 276 | return |
| 277 | } |
| 278 | |
| 279 | processingStep++ |
| 280 | if valuePA, existPA := onuTP.mapPonAniConfig[aUniID]; existPA { |
| 281 | if _, existTG := (*valuePA)[0]; existTG { |
| 282 | //Config data for this uni and and at least TCont Index 0 exist |
| 283 | go onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, pCurrentUniPort, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 284 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 285 | //timeout or error detected |
| 286 | logger.Debugw("tech-profile related configuration aborted on set", |
| 287 | log.Fields{"device-id": onuTP.deviceID, "UniId": aUniID}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 288 | onuTP.procResult = errors.New("TechProfile config aborted: Omci AniSideConfig failed") |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 289 | //this issue here means that the AniConfigFsm has not finished succesfully |
| 290 | //which requires to reset it to allow for new usage, e.g. also on a different UNI |
| 291 | //(without that it would be reset on device down indication latest) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 292 | onuTP.pAniConfigFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 293 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 294 | } |
| 295 | } else { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 296 | // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed) |
| 297 | logger.Debugw("no Tcont/Gem data for this UNI found - abort", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 298 | "device-id": onuTP.deviceID, "uniID": aUniID}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 299 | onuTP.procResult = errors.New("TechProfile config aborted: no Tcont/Gem data found for this UNI") |
| 300 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 301 | } |
| 302 | } else { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 303 | logger.Debugw("no PonAni data for this UNI found - abort", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 304 | "device-id": onuTP.deviceID, "uniID": aUniID}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 305 | onuTP.procResult = errors.New("TechProfile config aborted: no AniSide data found for this UNI") |
| 306 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 310 | func (onuTP *OnuUniTechProf) updateOnuTpPathKvStore(ctx context.Context, wg *sync.WaitGroup) { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 311 | defer wg.Done() |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 312 | |
| 313 | if onuTP.onuKVStore == nil { |
| 314 | logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": onuTP.deviceID}) |
| 315 | onuTP.procResult = errors.New("ONU/TP-data update aborted: onuKVStore not set") |
| 316 | return |
| 317 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 318 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpKvProcessingStep |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 319 | go onuTP.storePersistentData(ctx, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 320 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpKvProcessingStep, processingStep) { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 321 | //timeout or error detected |
| 322 | logger.Debugw("ONU/TP-data not written - abort", log.Fields{"device-id": onuTP.deviceID}) |
| 323 | onuTP.procResult = errors.New("ONU/TP-data update aborted: during writing process") |
| 324 | return |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | func (onuTP *OnuUniTechProf) restoreFromOnuTpPathKvStore(ctx context.Context) error { |
| 329 | if onuTP.onuKVStore == nil { |
| 330 | logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": onuTP.deviceID}) |
| 331 | return fmt.Errorf(fmt.Sprintf("onuKVStore-not-set-abort-%s", onuTP.deviceID)) |
| 332 | } |
| 333 | if err := onuTP.restorePersistentData(ctx); err != nil { |
| 334 | logger.Debugw("ONU/TP-data not read - abort", log.Fields{"device-id": onuTP.deviceID}) |
| 335 | return err |
| 336 | } |
| 337 | return nil |
| 338 | } |
| 339 | |
| 340 | func (onuTP *OnuUniTechProf) deleteOnuTpPathKvStore(ctx context.Context) error { |
| 341 | if onuTP.onuKVStore == nil { |
| 342 | logger.Debugw("onuKVStore not set - abort", log.Fields{"device-id": onuTP.deviceID}) |
| 343 | return fmt.Errorf(fmt.Sprintf("onuKVStore-not-set-abort-%s", onuTP.deviceID)) |
| 344 | } |
| 345 | if err := onuTP.deletePersistentData(ctx); err != nil { |
| 346 | logger.Debugw("ONU/TP-data not read - abort", log.Fields{"device-id": onuTP.deviceID}) |
| 347 | return err |
| 348 | } |
| 349 | return nil |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 350 | } |
| 351 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 352 | // deleteTpResource removes Resources from the ONU's specified Uni |
| 353 | func (onuTP *OnuUniTechProf) deleteTpResource(ctx context.Context, |
| 354 | aUniID uint32, aPathString string, aResource resourceEntry, aEntryID uint32, |
| 355 | wg *sync.WaitGroup) { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 356 | defer wg.Done() |
| 357 | logger.Debugw("this would remove TP resources from ONU's UNI", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 358 | "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "Resource": aResource}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 359 | //TODO!!! |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 360 | //delete the given resource from ONU OMCI config and data base - as background routine |
| 361 | /* |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 362 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 363 | go onuTp.deleteAniResource(ctx, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 364 | if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 365 | //timeout or error detected |
| 366 | return |
| 367 | } |
| 368 | */ |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 369 | } |
| 370 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 371 | /* internal methods *********************/ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 372 | |
| 373 | func (onuTP *OnuUniTechProf) storePersistentData(ctx context.Context, aProcessingStep uint8) { |
| 374 | |
| 375 | onuTP.sOnuPersistentData.PersOnuID = onuTP.baseDeviceHandler.pOnuIndication.OnuId |
| 376 | onuTP.sOnuPersistentData.PersIntfID = onuTP.baseDeviceHandler.pOnuIndication.IntfId |
| 377 | onuTP.sOnuPersistentData.PersSnr = onuTP.baseDeviceHandler.pOnuOmciDevice.serialNumber |
| 378 | //TODO: verify usage of these values during restart UC |
| 379 | onuTP.sOnuPersistentData.PersAdminState = "up" |
| 380 | onuTP.sOnuPersistentData.PersOperState = "active" |
| 381 | |
| 382 | onuTP.sOnuPersistentData.PersUniTpPath = onuTP.sOnuPersistentData.PersUniTpPath[:0] |
| 383 | |
| 384 | for k, v := range onuTP.mapUniTpPath { |
| 385 | onuTP.sOnuPersistentData.PersUniTpPath = |
| 386 | append(onuTP.sOnuPersistentData.PersUniTpPath, uniPersData{PersUniId: k, PersTpPath: v}) |
| 387 | } |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 388 | logger.Debugw("Update ONU/TP-data in KVStore", log.Fields{"device-id": onuTP.deviceID, "onuTP.sOnuPersistentData": onuTP.sOnuPersistentData}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 389 | |
| 390 | Value, err := json.Marshal(onuTP.sOnuPersistentData) |
| 391 | if err != nil { |
| 392 | logger.Errorw("unable to marshal ONU/TP-data", log.Fields{"onuTP.sOnuPersistentData": onuTP.sOnuPersistentData, |
| 393 | "device-id": onuTP.deviceID, "err": err}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 394 | onuTP.chTpKvProcessingStep <- 0 //error indication |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 395 | return |
| 396 | } |
| 397 | err = onuTP.onuKVStore.Put(ctx, onuTP.onuKVStorePath, Value) |
| 398 | if err != nil { |
| 399 | logger.Errorw("unable to write ONU/TP-data into KVstore", log.Fields{"device-id": onuTP.deviceID, "err": err}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 400 | onuTP.chTpKvProcessingStep <- 0 //error indication |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 401 | return |
| 402 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 403 | onuTP.chTpKvProcessingStep <- aProcessingStep //done |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | func (onuTP *OnuUniTechProf) restorePersistentData(ctx context.Context) error { |
| 407 | |
| 408 | onuTP.mapUniTpPath = make(map[uint32]string) |
| 409 | onuTP.sOnuPersistentData = onuPersistentData{0, 0, "", "", "", make([]uniPersData, 0)} |
| 410 | |
| 411 | Value, err := onuTP.onuKVStore.Get(ctx, onuTP.onuKVStorePath) |
| 412 | if err == nil { |
| 413 | if Value != nil { |
| 414 | logger.Debugw("ONU/TP-data read", |
| 415 | log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID}) |
| 416 | tpTmpBytes, _ := kvstore.ToByte(Value.Value) |
| 417 | |
| 418 | if err = json.Unmarshal(tpTmpBytes, &onuTP.sOnuPersistentData); err != nil { |
| 419 | logger.Errorw("unable to unmarshal ONU/TP-data", log.Fields{"error": err, "device-id": onuTP.deviceID}) |
| 420 | return fmt.Errorf(fmt.Sprintf("unable-to-unmarshal-ONU/TP-data-%s", onuTP.deviceID)) |
| 421 | } |
| 422 | logger.Debugw("ONU/TP-data", log.Fields{"onuTP.sOnuPersistentData": onuTP.sOnuPersistentData, |
| 423 | "device-id": onuTP.deviceID}) |
| 424 | |
| 425 | for _, uniData := range onuTP.sOnuPersistentData.PersUniTpPath { |
| 426 | onuTP.mapUniTpPath[uniData.PersUniId] = uniData.PersTpPath |
| 427 | } |
| 428 | logger.Debugw("TpPath map", log.Fields{"onuTP.mapUniTpPath": onuTP.mapUniTpPath, |
| 429 | "device-id": onuTP.deviceID}) |
| 430 | } else { |
| 431 | logger.Errorw("no ONU/TP-data found", log.Fields{"path": onuTP.onuKVStorePath, "device-id": onuTP.deviceID}) |
| 432 | return fmt.Errorf(fmt.Sprintf("no-ONU/TP-data-found-%s", onuTP.deviceID)) |
| 433 | } |
| 434 | } else { |
| 435 | logger.Errorw("unable to read from KVstore", log.Fields{"device-id": onuTP.deviceID}) |
| 436 | return fmt.Errorf(fmt.Sprintf("unable-to-read-from-KVstore-%s", onuTP.deviceID)) |
| 437 | } |
| 438 | return nil |
| 439 | } |
| 440 | |
| 441 | func (onuTP *OnuUniTechProf) deletePersistentData(ctx context.Context) error { |
| 442 | |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 443 | logger.Debugw("delete ONU/TP-data in KVStore", log.Fields{"device-id": onuTP.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 444 | err := onuTP.onuKVStore.Delete(ctx, onuTP.onuKVStorePath) |
| 445 | if err != nil { |
| 446 | logger.Errorw("unable to delete in KVstore", log.Fields{"device-id": onuTP.deviceID, "err": err}) |
| 447 | return fmt.Errorf(fmt.Sprintf("unable-delete-in-KVstore-%s", onuTP.deviceID)) |
| 448 | } |
| 449 | return nil |
| 450 | } |
| 451 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 452 | func (onuTP *OnuUniTechProf) readAniSideConfigFromTechProfile( |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 453 | ctx context.Context, aUniID uint8, aPathString string, aProcessingStep uint8) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 454 | var tpInst tp.TechProfile |
| 455 | |
| 456 | //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup |
| 457 | //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier> |
| 458 | subStringSlice := strings.Split(aPathString, "/") |
| 459 | if len(subStringSlice) <= 2 { |
| 460 | logger.Errorw("invalid path name format", |
| 461 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 462 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 463 | return |
| 464 | } |
| 465 | |
| 466 | //just some logical check to avoid unexpected behavior |
| 467 | //at this point it is assumed that a new TechProfile is assigned to the UNI |
| 468 | //expectation is that no TPIndication entry exists here, if yes, |
| 469 | // then we throw a warning and remove it (and the possible ANIConfig) simply |
| 470 | // note that the ONU config state may be ambivalent in such a case |
| 471 | // also note, that the PonAniConfig map is not checked additionally |
| 472 | // consistency to TPIndication is assumed |
| 473 | if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP { |
| 474 | logger.Warnw("Some active profile entry at reading new TechProfile", |
| 475 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID, |
| 476 | "UniId": aUniID, "wrongProfile": onuTP.mapUniTpIndication[aUniID].techProfileID}) |
| 477 | //delete on the mapUniTpIndication map not needed, just overwritten later |
| 478 | //delete on the PonAniConfig map should be safe, even if not existing |
| 479 | delete(onuTP.mapPonAniConfig, aUniID) |
| 480 | } else { |
| 481 | // this is normal processing |
| 482 | onuTP.mapUniTpIndication[aUniID] = &tTechProfileIndication{} //need to assign some (empty) struct memory first! |
| 483 | } |
| 484 | |
| 485 | onuTP.mapUniTpIndication[aUniID].techProfileType = subStringSlice[0] |
| 486 | profID, err := strconv.ParseUint(subStringSlice[1], 10, 32) |
| 487 | if err != nil { |
| 488 | logger.Errorw("invalid ProfileId from path", |
| 489 | log.Fields{"ParseErr": err}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 490 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 491 | return |
| 492 | } |
| 493 | |
| 494 | //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID |
| 495 | onuTP.mapUniTpIndication[aUniID].techProfileID = uint16(profID) |
| 496 | logger.Debugw("tech-profile path indications", |
| 497 | log.Fields{"device-id": onuTP.deviceID, "UniId": aUniID, |
| 498 | "profType": onuTP.mapUniTpIndication[aUniID].techProfileType, |
| 499 | "profID": onuTP.mapUniTpIndication[aUniID].techProfileID}) |
| 500 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 501 | Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 502 | if err == nil { |
| 503 | if Value != nil { |
| 504 | logger.Debugw("tech-profile read", |
| 505 | log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID}) |
| 506 | tpTmpBytes, _ := kvstore.ToByte(Value.Value) |
| 507 | |
| 508 | if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil { |
| 509 | logger.Errorw("TechProf - Failed to unmarshal tech-profile into tpInst", |
| 510 | log.Fields{"error": err, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 511 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 512 | return |
| 513 | } |
| 514 | logger.Debugw("TechProf - tpInst", log.Fields{"tpInst": tpInst}) |
| 515 | // access examples |
| 516 | logger.Debugw("TechProf content", log.Fields{"Name": tpInst.Name, |
| 517 | "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize, |
| 518 | "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold}) |
| 519 | } else { |
| 520 | logger.Errorw("No tech-profile found", |
| 521 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 522 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 523 | return |
| 524 | } |
| 525 | } else { |
| 526 | logger.Errorw("kvstore-get failed for path", |
| 527 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 528 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 529 | return |
| 530 | } |
| 531 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 532 | //default start with 1Tcont1Gem profile, later extend for multi GemPerTcont and perhaps even MultiTcontMultiGem |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 533 | localMapGemPortParams := make(map[uint16]*gemPortParamStruct) |
| 534 | localMapGemPortParams[0] = &gemPortParamStruct{} |
| 535 | localMapPonAniConfig := make(map[uint16]*tcontGemList) |
| 536 | localMapPonAniConfig[0] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams} |
| 537 | onuTP.mapPonAniConfig[aUniID] = (*tMapPonAniConfig)(&localMapPonAniConfig) |
| 538 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 539 | //note: the code is currently restricted to one TCcont per Onu (index [0]) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 540 | //get the relevant values from the profile and store to mapPonAniConfig |
| 541 | (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID) |
| 542 | //maybe tCont scheduling not (yet) needed - just to basicaly have it for future |
| 543 | // (would only be relevant in case of ONU-2G QOS configuration flexibility) |
| 544 | if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" { |
| 545 | (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines! |
| 546 | } else { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 547 | //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 548 | (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.schedPolicy = 2 //for G.988 WRR |
| 549 | } |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 550 | loNumGemPorts := tpInst.NumGemPorts |
| 551 | loGemPortRead := false |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 552 | for pos, content := range tpInst.UpstreamGemPortAttributeList { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 553 | if uint32(pos) == loNumGemPorts { |
| 554 | logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts", |
| 555 | log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 556 | break |
| 557 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 558 | if pos == 0 { |
| 559 | //at least one upstream GemPort should always exist (else traffic profile makes no sense) |
| 560 | loGemPortRead = true |
| 561 | } else { |
| 562 | //for all further GemPorts we need to extend the mapGemPortParams |
| 563 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)] = &gemPortParamStruct{} |
| 564 | } |
| 565 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortID = |
| 566 | uint16(content.GemportID) |
| 567 | //direction can be correlated later with Downstream list, |
| 568 | // for now just assume bidirectional (upstream never exists alone) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 569 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].direction = 3 //as defined in G.988 |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 570 | // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7 |
| 571 | if 7 < content.PriorityQueue { |
| 572 | logger.Errorw("PonAniConfig reject on GemPortList - PrioQueue value invalid", |
| 573 | log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue}) |
| 574 | //remove PonAniConfig as done so far, delete map should be safe, even if not existing |
| 575 | delete(onuTP.mapPonAniConfig, aUniID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 576 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 577 | return |
| 578 | } |
| 579 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].prioQueueIndex = |
| 580 | uint8(content.PriorityQueue) |
| 581 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].pbitString = |
| 582 | strings.TrimPrefix(content.PbitMap, BinaryStringPrefix) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 583 | if content.AesEncryption == "True" { |
| 584 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortEncState = 1 |
| 585 | } else { |
| 586 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortEncState = 0 |
| 587 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 588 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].discardPolicy = |
| 589 | content.DiscardPolicy |
| 590 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].queueSchedPolicy = |
| 591 | content.SchedulingPolicy |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 592 | //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 593 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].queueWeight = |
| 594 | uint8(content.Weight) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 595 | } |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 596 | if loGemPortRead == false { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 597 | logger.Errorw("PonAniConfig reject - no GemPort could be read from TechProfile", |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 598 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 599 | //remove PonAniConfig as done so far, delete map should be safe, even if not existing |
| 600 | delete(onuTP.mapPonAniConfig, aUniID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 601 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 602 | return |
| 603 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 604 | //TODO!! MC (downstream) GemPorts can be set using DownstreamGemPortAttributeList seperately |
| 605 | |
| 606 | //logger does not simply output the given structures, just give some example debug values |
| 607 | logger.Debugw("PonAniConfig read from TechProfile", log.Fields{ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 608 | "device-id": onuTP.deviceID, |
| 609 | "AllocId": (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.allocID}) |
| 610 | for gemIndex, gemEntry := range (*(onuTP.mapPonAniConfig[0]))[0].mapGemPortParams { |
| 611 | logger.Debugw("PonAniConfig read from TechProfile", log.Fields{ |
| 612 | "GemIndex": gemIndex, |
| 613 | "GemPort": gemEntry.gemPortID, |
| 614 | "QueueScheduling": gemEntry.queueSchedPolicy}) |
| 615 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 616 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 617 | onuTP.chTpConfigProcessingStep <- aProcessingStep //done |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | func (onuTP *OnuUniTechProf) setAniSideConfigFromTechProfile( |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 621 | ctx context.Context, aUniID uint8, apCurrentUniPort *OnuUniPort, aProcessingStep uint8) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 622 | |
| 623 | //OMCI transfer of ANI data acc. to mapPonAniConfig |
| 624 | // also the FSM's are running in background, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 625 | // hence we have to make sure they indicate 'success' success on chTpConfigProcessingStep with aProcessingStep |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 626 | if onuTP.pAniConfigFsm == nil { |
| 627 | onuTP.createAniConfigFsm(aUniID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep) |
| 628 | } else { //AniConfigFsm already init |
| 629 | onuTP.runAniConfigFsm(aProcessingStep) |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | func (onuTP *OnuUniTechProf) waitForTimeoutOrCompletion( |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 634 | ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 635 | select { |
| 636 | case <-ctx.Done(): |
| 637 | logger.Warnw("processing not completed in-time: force release of TpProcMutex!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 638 | log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 639 | return false |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 640 | case rxStep := <-aChTpProcessingStep: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 641 | if rxStep == aProcessingStep { |
| 642 | return true |
| 643 | } |
| 644 | //all other values are not accepted - including 0 for error indication |
| 645 | logger.Warnw("Invalid processing step received: abort and force release of TpProcMutex!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 646 | log.Fields{"device-id": onuTP.deviceID, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 647 | "wantedStep": aProcessingStep, "haveStep": rxStep}) |
| 648 | return false |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | // createUniLockFsm initialises and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 653 | func (onuTP *OnuUniTechProf) createAniConfigFsm(aUniID uint8, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 654 | apCurrentUniPort *OnuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 655 | logger.Debugw("createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 656 | chAniConfigFsm := make(chan Message, 2048) |
| 657 | pDevEntry := onuTP.baseDeviceHandler.GetOnuDeviceEntry(true) |
| 658 | if pDevEntry == nil { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 659 | logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 660 | return |
| 661 | } |
| 662 | pAniCfgFsm := NewUniPonAniConfigFsm(pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP, |
| 663 | pDevEntry.pOnuDB, onuTP.mapUniTpIndication[aUniID].techProfileID, devEvent, |
| 664 | "AniConfigFsm", onuTP.deviceID, chAniConfigFsm) |
| 665 | if pAniCfgFsm != nil { |
| 666 | onuTP.pAniConfigFsm = pAniCfgFsm |
| 667 | onuTP.runAniConfigFsm(aProcessingStep) |
| 668 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 669 | logger.Errorw("AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
| 673 | // runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration |
| 674 | func (onuTP *OnuUniTechProf) runAniConfigFsm(aProcessingStep uint8) { |
| 675 | /* Uni related ANI config procedure - |
| 676 | ***** should run via 'aniConfigDone' state and generate the argument requested event ***** |
| 677 | */ |
| 678 | var pACStatemachine *fsm.FSM |
| 679 | pACStatemachine = onuTP.pAniConfigFsm.pAdaptFsm.pFsm |
| 680 | if pACStatemachine != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 681 | if pACStatemachine.Is(aniStDisabled) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 682 | //FSM init requirement to get informed abou FSM completion! (otherwise timeout of the TechProf config) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 683 | onuTP.pAniConfigFsm.SetFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 684 | if err := pACStatemachine.Event(aniEvStart); err != nil { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 685 | logger.Warnw("AniConfigFSM: can't start", log.Fields{"err": err}) |
| 686 | // maybe try a FSM reset and then again ... - TODO!!! |
| 687 | } else { |
| 688 | /***** AniConfigFSM started */ |
| 689 | logger.Debugw("AniConfigFSM started", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 690 | "state": pACStatemachine.Current(), "device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 691 | } |
| 692 | } else { |
| 693 | logger.Warnw("wrong state of AniConfigFSM - want: disabled", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 694 | "have": pACStatemachine.Current(), "device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 695 | // maybe try a FSM reset and then again ... - TODO!!! |
| 696 | } |
| 697 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 698 | logger.Errorw("AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 699 | // maybe try a FSM reset and then again ... - TODO!!! |
| 700 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 701 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame^] | 702 | |
| 703 | // setConfigDone sets the requested techProfile config state (if possible) |
| 704 | func (onuTP *OnuUniTechProf) setConfigDone(aUniID uint8, aState bool) { |
| 705 | if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP { |
| 706 | onuTP.mutexTPState.Lock() |
| 707 | onuTP.mapUniTpIndication[aUniID].techProfileConfigDone = aState |
| 708 | onuTP.mutexTPState.Unlock() |
| 709 | } //else: the state is just ignored (does not exist) |
| 710 | } |
| 711 | |
| 712 | // getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done |
| 713 | func (onuTP *OnuUniTechProf) getTechProfileDone(aUniID uint8, aTpID uint16) bool { |
| 714 | if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP { |
| 715 | if onuTP.mapUniTpIndication[aUniID].techProfileID == aTpID { |
| 716 | onuTP.mutexTPState.Lock() |
| 717 | defer onuTP.mutexTPState.Unlock() |
| 718 | return onuTP.mapUniTpIndication[aUniID].techProfileConfigDone |
| 719 | } |
| 720 | } |
| 721 | //for all other constellations indicate false = Config not done |
| 722 | return false |
| 723 | } |