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" |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [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 | |
| 29 | "github.com/opencord/voltha-lib-go/v3/pkg/db" |
| 30 | "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore" |
| 31 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 32 | tp "github.com/opencord/voltha-lib-go/v3/pkg/techprofile" |
| 33 | ) |
| 34 | |
| 35 | const cBasePathTechProfileKVStore = "service/voltha/technology_profiles" |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 36 | |
| 37 | //definitions for TechProfileProcessing - copied from OltAdapter:openolt_flowmgr.go |
| 38 | // could perhaps be defined more globally |
| 39 | const ( |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 40 | // binaryStringPrefix is binary string prefix |
| 41 | binaryStringPrefix = "0b" |
| 42 | // binaryBit1 is binary bit 1 expressed as a character |
| 43 | //binaryBit1 = '1' |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 44 | ) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 45 | |
| 46 | type resourceEntry int |
| 47 | |
| 48 | const ( |
| 49 | cResourceGemPort resourceEntry = 1 |
| 50 | cResourceTcont resourceEntry = 2 |
| 51 | ) |
| 52 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 53 | type tTechProfileIndication struct { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 54 | techProfileType string |
| 55 | techProfileID uint16 |
| 56 | techProfileConfigDone bool |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | type tcontParamStruct struct { |
| 60 | allocID uint16 |
| 61 | schedPolicy uint8 |
| 62 | } |
| 63 | type gemPortParamStruct struct { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 64 | //ponOmciCC bool |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 65 | gemPortID uint16 |
| 66 | direction uint8 |
| 67 | gemPortEncState uint8 |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 68 | prioQueueIndex uint8 |
| 69 | pbitString string |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 70 | discardPolicy string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 71 | //could also be a queue specific parameter, not used that way here |
| 72 | //maxQueueSize uint16 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 73 | queueSchedPolicy string |
| 74 | queueWeight uint8 |
| 75 | } |
| 76 | |
| 77 | //refers to one tcont and its properties and all assigned GemPorts and their properties |
| 78 | type tcontGemList struct { |
| 79 | tcontParams tcontParamStruct |
| 80 | mapGemPortParams map[uint16]*gemPortParamStruct |
| 81 | } |
| 82 | |
| 83 | //refers to all tcont and their Tcont/GemPort Parameters |
| 84 | type tMapPonAniConfig map[uint16]*tcontGemList |
| 85 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 86 | //onuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU |
| 87 | type onuUniTechProf struct { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 88 | baseDeviceHandler *deviceHandler |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 89 | deviceID string |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 90 | tpProcMutex sync.RWMutex |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 91 | techProfileKVStore *db.Backend |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 92 | chTpConfigProcessingStep chan uint8 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 93 | mapUniTpIndication map[uint8]*tTechProfileIndication //use pointer values to ease assignments to the map |
| 94 | mapPonAniConfig map[uint8]*tMapPonAniConfig //per UNI: use pointer values to ease assignments to the map |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 95 | pAniConfigFsm *uniPonAniConfigFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 96 | procResult error //error indication of processing |
| 97 | mutexTPState sync.Mutex |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 98 | tpProfileExists bool |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 101 | //newOnuUniTechProf returns the instance of a OnuUniTechProf |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 102 | //(one instance per ONU/deviceHandler for all possible UNI's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 103 | func newOnuUniTechProf(ctx context.Context, aDeviceHandler *deviceHandler) *onuUniTechProf { |
| 104 | logger.Infow("init-OnuUniTechProf", log.Fields{"device-id": aDeviceHandler.deviceID}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 105 | var onuTP onuUniTechProf |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 106 | onuTP.baseDeviceHandler = aDeviceHandler |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 107 | onuTP.deviceID = aDeviceHandler.deviceID |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 108 | onuTP.tpProcMutex = sync.RWMutex{} |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 109 | onuTP.chTpConfigProcessingStep = make(chan uint8) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 110 | onuTP.mapUniTpIndication = make(map[uint8]*tTechProfileIndication) |
| 111 | onuTP.mapPonAniConfig = make(map[uint8]*tMapPonAniConfig) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 112 | onuTP.procResult = nil //default assumption processing done with success |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 113 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 114 | onuTP.techProfileKVStore = aDeviceHandler.setBackend(cBasePathTechProfileKVStore) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 115 | if onuTP.techProfileKVStore == nil { |
| 116 | logger.Errorw("Can't access techProfileKVStore - no backend connection to service", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 117 | log.Fields{"device-id": aDeviceHandler.deviceID, "service": cBasePathTechProfileKVStore}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 118 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 119 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 120 | return &onuTP |
| 121 | } |
| 122 | |
| 123 | // lockTpProcMutex locks OnuUniTechProf processing mutex |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 124 | func (onuTP *onuUniTechProf) lockTpProcMutex() { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 125 | onuTP.tpProcMutex.Lock() |
| 126 | } |
| 127 | |
| 128 | // unlockTpProcMutex unlocks OnuUniTechProf processing mutex |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 129 | func (onuTP *onuUniTechProf) unlockTpProcMutex() { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 130 | onuTP.tpProcMutex.Unlock() |
| 131 | } |
| 132 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 133 | // resetTpProcessingErrorIndication resets the internal error indication |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 134 | // need to be called before evaluation of any subsequent processing (given by waitForTpCompletion()) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 135 | func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication() { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 136 | onuTP.procResult = nil |
| 137 | } |
| 138 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 139 | func (onuTP *onuUniTechProf) getTpProcessingErrorIndication() error { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 140 | return onuTP.procResult |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | // configureUniTp checks existing tp resources to delete and starts the corresponding OMCI configuation of the UNI port |
| 144 | // all possibly blocking processing must be run in background to allow for deadline supervision! |
| 145 | // but take care on sequential background processing when needed (logical dependencies) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 146 | // use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 147 | func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 148 | aUniID uint8, aPathString string, wg *sync.WaitGroup) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 149 | defer wg.Done() //always decrement the waitGroup on return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 150 | logger.Debugw("configure the Uni according to TpPath", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 151 | "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 152 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 153 | if onuTP.techProfileKVStore == nil { |
| 154 | logger.Debug("techProfileKVStore not set - abort") |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 155 | onuTP.procResult = errors.New("techProfile config aborted: techProfileKVStore not set") |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 156 | return |
| 157 | } |
| 158 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 159 | //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 160 | var pCurrentUniPort *onuUniPort |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 161 | for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap { |
| 162 | // only if this port is validated for operState transfer |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 163 | if uniPort.uniID == uint8(aUniID) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 164 | pCurrentUniPort = uniPort |
| 165 | break //found - end search loop |
| 166 | } |
| 167 | } |
| 168 | if pCurrentUniPort == nil { |
| 169 | logger.Errorw("TechProfile configuration aborted: requested uniID not found in PortDB", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 170 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 171 | onuTP.procResult = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s", |
| 172 | aUniID, onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 173 | return |
| 174 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 175 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 176 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 177 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 178 | //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called |
| 179 | // in case the KVPath has changed for the given UNI, |
| 180 | // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing |
| 181 | // (ANI) configuration of this port has to be removed first |
| 182 | // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well) |
| 183 | // existence of configuration can be detected based on tp stored TCONT's |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 184 | //TODO: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 185 | /* if tcontMap not empty { |
| 186 | go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 187 | if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 188 | //timeout or error detected |
| 189 | return |
| 190 | } |
| 191 | clear tcontMap |
| 192 | } |
| 193 | |
| 194 | processingStep++ |
| 195 | */ |
| 196 | go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, aPathString, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 197 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 198 | //timeout or error detected |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 199 | if onuTP.tpProfileExists { |
| 200 | //ignore the internal error in case the new profile is already configured |
| 201 | // and abort the processing here |
| 202 | return |
| 203 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 204 | logger.Debugw("tech-profile related configuration aborted on read", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 205 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 206 | onuTP.procResult = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s", |
| 207 | aUniID, onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 208 | return |
| 209 | } |
| 210 | |
| 211 | processingStep++ |
| 212 | if valuePA, existPA := onuTP.mapPonAniConfig[aUniID]; existPA { |
| 213 | if _, existTG := (*valuePA)[0]; existTG { |
| 214 | //Config data for this uni and and at least TCont Index 0 exist |
| 215 | go onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, pCurrentUniPort, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 216 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 217 | //timeout or error detected |
| 218 | logger.Debugw("tech-profile related configuration aborted on set", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 219 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 220 | onuTP.procResult = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s", |
| 221 | aUniID, onuTP.deviceID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 222 | //this issue here means that the AniConfigFsm has not finished successfully |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 223 | //which requires to reset it to allow for new usage, e.g. also on a different UNI |
| 224 | //(without that it would be reset on device down indication latest) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 225 | _ = onuTP.pAniConfigFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 226 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 227 | } |
| 228 | } else { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 229 | // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed) |
| 230 | logger.Debugw("no Tcont/Gem data for this UNI found - abort", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 231 | "device-id": onuTP.deviceID, "uni-id": aUniID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 232 | onuTP.procResult = fmt.Errorf("techProfile config aborted: no Tcont/Gem data found for this UNI %d on %s", |
| 233 | aUniID, onuTP.deviceID) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 234 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 235 | } |
| 236 | } else { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 237 | logger.Debugw("no PonAni data for this UNI found - abort", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 238 | "device-id": onuTP.deviceID, "uni-id": aUniID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 239 | onuTP.procResult = fmt.Errorf("techProfile config aborted: no AniSide data found for this UNI %d on %s", |
| 240 | aUniID, onuTP.deviceID) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 241 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 245 | /* internal methods *********************/ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 246 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 247 | func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile( |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 248 | ctx context.Context, aUniID uint8, aPathString string, aProcessingStep uint8) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 249 | var tpInst tp.TechProfile |
| 250 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 251 | onuTP.tpProfileExists = false |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 252 | //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup |
| 253 | //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier> |
| 254 | subStringSlice := strings.Split(aPathString, "/") |
| 255 | if len(subStringSlice) <= 2 { |
| 256 | logger.Errorw("invalid path name format", |
| 257 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 258 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 259 | return |
| 260 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 261 | profID, err := strconv.ParseUint(subStringSlice[1], 10, 32) |
| 262 | if err != nil { |
| 263 | logger.Errorw("invalid ProfileId from path", |
| 264 | log.Fields{"ParseErr": err}) |
| 265 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
| 266 | return |
| 267 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 268 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 269 | //at this point it is assumed that a new TechProfile is assigned to the UNI |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 270 | //expectation is that no TPIndication entry exists here, if exists and with the same TPId |
| 271 | // then we throw a warning, set an internal error and abort with error, |
| 272 | // which is later re-defined to success response to OLT adapter |
| 273 | // if TPId has changed, current data is removed (note that the ONU config state may be |
| 274 | // ambivalent in such a case) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 275 | if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP { |
| 276 | logger.Warnw("Some active profile entry at reading new TechProfile", |
| 277 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 278 | "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[aUniID].techProfileID}) |
| 279 | if uint16(profID) == onuTP.mapUniTpIndication[aUniID].techProfileID { |
| 280 | // ProfId not changed - assume profile to be still the same |
| 281 | // anyway this should not appear after full support of profile (Gem/TCont) removal |
| 282 | logger.Warnw("New TechProfile already exists - aborting configuration", |
| 283 | log.Fields{"device-id": onuTP.deviceID}) |
| 284 | onuTP.tpProfileExists = true |
| 285 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
| 286 | return |
| 287 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 288 | //delete on the mapUniTpIndication map not needed, just overwritten later |
| 289 | //delete on the PonAniConfig map should be safe, even if not existing |
| 290 | delete(onuTP.mapPonAniConfig, aUniID) |
| 291 | } else { |
| 292 | // this is normal processing |
| 293 | onuTP.mapUniTpIndication[aUniID] = &tTechProfileIndication{} //need to assign some (empty) struct memory first! |
| 294 | } |
| 295 | |
| 296 | onuTP.mapUniTpIndication[aUniID].techProfileType = subStringSlice[0] |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 297 | //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID |
| 298 | onuTP.mapUniTpIndication[aUniID].techProfileID = uint16(profID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 299 | onuTP.mapUniTpIndication[aUniID].techProfileConfigDone = false |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 300 | logger.Debugw("tech-profile path indications", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 301 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 302 | "profType": onuTP.mapUniTpIndication[aUniID].techProfileType, |
| 303 | "profID": onuTP.mapUniTpIndication[aUniID].techProfileID}) |
| 304 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 305 | Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 306 | if err == nil { |
| 307 | if Value != nil { |
| 308 | logger.Debugw("tech-profile read", |
| 309 | log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID}) |
| 310 | tpTmpBytes, _ := kvstore.ToByte(Value.Value) |
| 311 | |
| 312 | if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil { |
| 313 | logger.Errorw("TechProf - Failed to unmarshal tech-profile into tpInst", |
| 314 | log.Fields{"error": err, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 315 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 316 | return |
| 317 | } |
| 318 | logger.Debugw("TechProf - tpInst", log.Fields{"tpInst": tpInst}) |
| 319 | // access examples |
| 320 | logger.Debugw("TechProf content", log.Fields{"Name": tpInst.Name, |
| 321 | "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize, |
| 322 | "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold}) |
| 323 | } else { |
| 324 | logger.Errorw("No tech-profile found", |
| 325 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 326 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 327 | return |
| 328 | } |
| 329 | } else { |
| 330 | logger.Errorw("kvstore-get failed for path", |
| 331 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 332 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 333 | return |
| 334 | } |
| 335 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 336 | //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 337 | localMapGemPortParams := make(map[uint16]*gemPortParamStruct) |
| 338 | localMapGemPortParams[0] = &gemPortParamStruct{} |
| 339 | localMapPonAniConfig := make(map[uint16]*tcontGemList) |
| 340 | localMapPonAniConfig[0] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams} |
| 341 | onuTP.mapPonAniConfig[aUniID] = (*tMapPonAniConfig)(&localMapPonAniConfig) |
| 342 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 343 | //note: the code is currently restricted to one TCcont per Onu (index [0]) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 344 | //get the relevant values from the profile and store to mapPonAniConfig |
| 345 | (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 346 | //maybe tCont scheduling not (yet) needed - just to basically have it for future |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 347 | // (would only be relevant in case of ONU-2G QOS configuration flexibility) |
| 348 | if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" { |
| 349 | (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines! |
| 350 | } else { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 351 | //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] | 352 | (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.schedPolicy = 2 //for G.988 WRR |
| 353 | } |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 354 | loNumGemPorts := tpInst.NumGemPorts |
| 355 | loGemPortRead := false |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 356 | for pos, content := range tpInst.UpstreamGemPortAttributeList { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 357 | if uint32(pos) == loNumGemPorts { |
| 358 | logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts", |
| 359 | log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 360 | break |
| 361 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 362 | if pos == 0 { |
| 363 | //at least one upstream GemPort should always exist (else traffic profile makes no sense) |
| 364 | loGemPortRead = true |
| 365 | } else { |
| 366 | //for all further GemPorts we need to extend the mapGemPortParams |
| 367 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)] = &gemPortParamStruct{} |
| 368 | } |
| 369 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortID = |
| 370 | uint16(content.GemportID) |
| 371 | //direction can be correlated later with Downstream list, |
| 372 | // for now just assume bidirectional (upstream never exists alone) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 373 | (*(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] | 374 | // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7 |
| 375 | if 7 < content.PriorityQueue { |
| 376 | logger.Errorw("PonAniConfig reject on GemPortList - PrioQueue value invalid", |
| 377 | log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue}) |
| 378 | //remove PonAniConfig as done so far, delete map should be safe, even if not existing |
| 379 | delete(onuTP.mapPonAniConfig, aUniID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 380 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 381 | return |
| 382 | } |
| 383 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].prioQueueIndex = |
| 384 | uint8(content.PriorityQueue) |
| 385 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].pbitString = |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 386 | strings.TrimPrefix(content.PbitMap, binaryStringPrefix) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 387 | if content.AesEncryption == "True" { |
| 388 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortEncState = 1 |
| 389 | } else { |
| 390 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortEncState = 0 |
| 391 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 392 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].discardPolicy = |
| 393 | content.DiscardPolicy |
| 394 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].queueSchedPolicy = |
| 395 | content.SchedulingPolicy |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 396 | //'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] | 397 | (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].queueWeight = |
| 398 | uint8(content.Weight) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 399 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 400 | if !loGemPortRead { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 401 | logger.Errorw("PonAniConfig reject - no GemPort could be read from TechProfile", |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 402 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 403 | //remove PonAniConfig as done so far, delete map should be safe, even if not existing |
| 404 | delete(onuTP.mapPonAniConfig, aUniID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 405 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 406 | return |
| 407 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 408 | //TODO!! MC (downstream) GemPorts can be set using DownstreamGemPortAttributeList separately |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 409 | |
| 410 | //logger does not simply output the given structures, just give some example debug values |
| 411 | logger.Debugw("PonAniConfig read from TechProfile", log.Fields{ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 412 | "device-id": onuTP.deviceID, |
| 413 | "AllocId": (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.allocID}) |
| 414 | for gemIndex, gemEntry := range (*(onuTP.mapPonAniConfig[0]))[0].mapGemPortParams { |
| 415 | logger.Debugw("PonAniConfig read from TechProfile", log.Fields{ |
| 416 | "GemIndex": gemIndex, |
| 417 | "GemPort": gemEntry.gemPortID, |
| 418 | "QueueScheduling": gemEntry.queueSchedPolicy}) |
| 419 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 420 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 421 | onuTP.chTpConfigProcessingStep <- aProcessingStep //done |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 424 | func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile( |
| 425 | ctx context.Context, aUniID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 426 | |
| 427 | //OMCI transfer of ANI data acc. to mapPonAniConfig |
| 428 | // also the FSM's are running in background, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 429 | // 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] | 430 | if onuTP.pAniConfigFsm == nil { |
| 431 | onuTP.createAniConfigFsm(aUniID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep) |
| 432 | } else { //AniConfigFsm already init |
| 433 | onuTP.runAniConfigFsm(aProcessingStep) |
| 434 | } |
| 435 | } |
| 436 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 437 | func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion( |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 438 | ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 439 | select { |
| 440 | case <-ctx.Done(): |
| 441 | logger.Warnw("processing not completed in-time: force release of TpProcMutex!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 442 | log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 443 | return false |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 444 | case rxStep := <-aChTpProcessingStep: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 445 | if rxStep == aProcessingStep { |
| 446 | return true |
| 447 | } |
| 448 | //all other values are not accepted - including 0 for error indication |
| 449 | logger.Warnw("Invalid processing step received: abort and force release of TpProcMutex!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 450 | log.Fields{"device-id": onuTP.deviceID, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 451 | "wantedStep": aProcessingStep, "haveStep": rxStep}) |
| 452 | return false |
| 453 | } |
| 454 | } |
| 455 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 456 | // createUniLockFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 457 | func (onuTP *onuUniTechProf) createAniConfigFsm(aUniID uint8, |
| 458 | apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 459 | logger.Debugw("createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 460 | chAniConfigFsm := make(chan Message, 2048) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 461 | pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(true) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 462 | if pDevEntry == nil { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 463 | logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 464 | return |
| 465 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 466 | pAniCfgFsm := newUniPonAniConfigFsm(pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 467 | pDevEntry.pOnuDB, onuTP.mapUniTpIndication[aUniID].techProfileID, devEvent, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 468 | "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 469 | if pAniCfgFsm != nil { |
| 470 | onuTP.pAniConfigFsm = pAniCfgFsm |
| 471 | onuTP.runAniConfigFsm(aProcessingStep) |
| 472 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 473 | 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] | 474 | } |
| 475 | } |
| 476 | |
| 477 | // runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 478 | func (onuTP *onuUniTechProf) runAniConfigFsm(aProcessingStep uint8) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 479 | /* Uni related ANI config procedure - |
| 480 | ***** should run via 'aniConfigDone' state and generate the argument requested event ***** |
| 481 | */ |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 482 | pACStatemachine := onuTP.pAniConfigFsm.pAdaptFsm.pFsm |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 483 | if pACStatemachine != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 484 | if pACStatemachine.Is(aniStDisabled) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 485 | //FSM init requirement to get informed abou FSM completion! (otherwise timeout of the TechProf config) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 486 | onuTP.pAniConfigFsm.setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 487 | if err := pACStatemachine.Event(aniEvStart); err != nil { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 488 | logger.Warnw("AniConfigFSM: can't start", log.Fields{"err": err}) |
| 489 | // maybe try a FSM reset and then again ... - TODO!!! |
| 490 | } else { |
| 491 | /***** AniConfigFSM started */ |
| 492 | logger.Debugw("AniConfigFSM started", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 493 | "state": pACStatemachine.Current(), "device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 494 | } |
| 495 | } else { |
| 496 | logger.Warnw("wrong state of AniConfigFSM - want: disabled", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 497 | "have": pACStatemachine.Current(), "device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 498 | // maybe try a FSM reset and then again ... - TODO!!! |
| 499 | } |
| 500 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 501 | 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] | 502 | // maybe try a FSM reset and then again ... - TODO!!! |
| 503 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 504 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 505 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 506 | // clearAniSideConfig deletes all internal TechProfile related data connected to the requested UniPort |
| 507 | func (onuTP *onuUniTechProf) clearAniSideConfig(aUniID uint8) { |
| 508 | logger.Debugw("removing TpIndication and PonAniConfig data", log.Fields{ |
| 509 | "device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 510 | //a mutex protection on the concerned data should not be needed here, as the config/write action should not |
| 511 | // interfere with any read action or the initial write/config activity at start |
| 512 | //remove the TechProfile indications of this UNI, should be safe even if not existing |
| 513 | delete(onuTP.mapUniTpIndication, aUniID) |
| 514 | //delete on the PonAniConfig map of this UNI should be safe, even if not existing |
| 515 | delete(onuTP.mapPonAniConfig, aUniID) |
| 516 | } |
| 517 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 518 | // setConfigDone sets the requested techProfile config state (if possible) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 519 | func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aState bool) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 520 | if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP { |
| 521 | onuTP.mutexTPState.Lock() |
| 522 | onuTP.mapUniTpIndication[aUniID].techProfileConfigDone = aState |
| 523 | onuTP.mutexTPState.Unlock() |
| 524 | } //else: the state is just ignored (does not exist) |
| 525 | } |
| 526 | |
| 527 | // getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 528 | func (onuTP *onuUniTechProf) getTechProfileDone(aUniID uint8, aTpID uint16) bool { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 529 | if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP { |
| 530 | if onuTP.mapUniTpIndication[aUniID].techProfileID == aTpID { |
| 531 | onuTP.mutexTPState.Lock() |
| 532 | defer onuTP.mutexTPState.Unlock() |
| 533 | return onuTP.mapUniTpIndication[aUniID].techProfileConfigDone |
| 534 | } |
| 535 | } |
| 536 | //for all other constellations indicate false = Config not done |
| 537 | return false |
| 538 | } |