blob: e7a1843cb7196d0824ecbde60317f4ce40dba25c [file] [log] [blame]
mpagenkoaf801632020-07-03 10:00:42 +00001/*
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
18package adaptercoreonu
19
20import (
21 "context"
22 "encoding/json"
mpagenko1cc3cb42020-07-27 15:24:38 +000023 "errors"
Andrea Campanella6515c582020-10-05 11:25:00 +020024 "fmt"
mpagenko3dbcdd22020-07-22 07:38:45 +000025 "strings"
mpagenkoaf801632020-07-03 10:00:42 +000026 "sync"
27
28 "github.com/opencord/voltha-lib-go/v3/pkg/db"
29 "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore"
30 "github.com/opencord/voltha-lib-go/v3/pkg/log"
31 tp "github.com/opencord/voltha-lib-go/v3/pkg/techprofile"
32)
33
34const cBasePathTechProfileKVStore = "service/voltha/technology_profiles"
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000035
36//definitions for TechProfileProcessing - copied from OltAdapter:openolt_flowmgr.go
37// could perhaps be defined more globally
38const (
Himani Chawla6d2ae152020-09-02 13:11:20 +053039 // binaryStringPrefix is binary string prefix
40 binaryStringPrefix = "0b"
41 // binaryBit1 is binary bit 1 expressed as a character
42 //binaryBit1 = '1'
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000043)
mpagenkoaf801632020-07-03 10:00:42 +000044
45type resourceEntry int
46
47const (
48 cResourceGemPort resourceEntry = 1
49 cResourceTcont resourceEntry = 2
50)
51
mpagenko3dbcdd22020-07-22 07:38:45 +000052type tTechProfileIndication struct {
mpagenkodff5dda2020-08-28 11:52:01 +000053 techProfileType string
Girish Gowdra041dcb32020-11-16 16:54:30 -080054 techProfileID uint8
mpagenkodff5dda2020-08-28 11:52:01 +000055 techProfileConfigDone bool
mpagenko2418ab02020-11-12 12:58:06 +000056 techProfileToDelete bool
mpagenko3dbcdd22020-07-22 07:38:45 +000057}
58
59type tcontParamStruct struct {
60 allocID uint16
61 schedPolicy uint8
62}
63type gemPortParamStruct struct {
Himani Chawla4d908332020-08-31 12:30:20 +053064 //ponOmciCC bool
mpagenko3dbcdd22020-07-22 07:38:45 +000065 gemPortID uint16
66 direction uint8
67 gemPortEncState uint8
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000068 prioQueueIndex uint8
69 pbitString string
mpagenko3dbcdd22020-07-22 07:38:45 +000070 discardPolicy string
Himani Chawla4d908332020-08-31 12:30:20 +053071 //could also be a queue specific parameter, not used that way here
72 //maxQueueSize uint16
mpagenko3dbcdd22020-07-22 07:38:45 +000073 queueSchedPolicy string
74 queueWeight uint8
75}
76
77//refers to one tcont and its properties and all assigned GemPorts and their properties
78type tcontGemList struct {
79 tcontParams tcontParamStruct
80 mapGemPortParams map[uint16]*gemPortParamStruct
81}
82
Girish Gowdra041dcb32020-11-16 16:54:30 -080083// refers a unique combination of uniID and tpID for a given ONU.
84type uniTP struct {
85 uniID uint8
86 tpID uint8
87}
mpagenko3dbcdd22020-07-22 07:38:45 +000088
Himani Chawla6d2ae152020-09-02 13:11:20 +053089//onuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU
90type onuUniTechProf struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053091 baseDeviceHandler *deviceHandler
mpagenko01e726e2020-10-23 09:45:29 +000092 deviceID string
mpagenkodff5dda2020-08-28 11:52:01 +000093 tpProcMutex sync.RWMutex
mpagenkodff5dda2020-08-28 11:52:01 +000094 techProfileKVStore *db.Backend
mpagenkodff5dda2020-08-28 11:52:01 +000095 chTpConfigProcessingStep chan uint8
Girish Gowdra041dcb32020-11-16 16:54:30 -080096 mapUniTpIndication map[uniTP]*tTechProfileIndication //use pointer values to ease assignments to the map
97 mapPonAniConfig map[uniTP]*tcontGemList //per UNI: use pointer values to ease assignments to the map
98 pAniConfigFsm map[uniTP]*uniPonAniConfigFsm
99 procResult map[uniTP]error //error indication of processing
mpagenkodff5dda2020-08-28 11:52:01 +0000100 mutexTPState sync.Mutex
Girish Gowdra041dcb32020-11-16 16:54:30 -0800101 tpProfileExists map[uniTP]bool
mpagenkoaf801632020-07-03 10:00:42 +0000102}
103
Himani Chawla6d2ae152020-09-02 13:11:20 +0530104//newOnuUniTechProf returns the instance of a OnuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000105//(one instance per ONU/deviceHandler for all possible UNI's)
mpagenko01e726e2020-10-23 09:45:29 +0000106func newOnuUniTechProf(ctx context.Context, aDeviceHandler *deviceHandler) *onuUniTechProf {
107 logger.Infow("init-OnuUniTechProf", log.Fields{"device-id": aDeviceHandler.deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530108 var onuTP onuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000109 onuTP.baseDeviceHandler = aDeviceHandler
mpagenko01e726e2020-10-23 09:45:29 +0000110 onuTP.deviceID = aDeviceHandler.deviceID
mpagenkoaf801632020-07-03 10:00:42 +0000111 onuTP.tpProcMutex = sync.RWMutex{}
mpagenkodff5dda2020-08-28 11:52:01 +0000112 onuTP.chTpConfigProcessingStep = make(chan uint8)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800113 onuTP.mapUniTpIndication = make(map[uniTP]*tTechProfileIndication)
114 onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList)
115 onuTP.procResult = make(map[uniTP]error)
116 onuTP.tpProfileExists = make(map[uniTP]bool)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530117 onuTP.techProfileKVStore = aDeviceHandler.setBackend(cBasePathTechProfileKVStore)
mpagenkoaf801632020-07-03 10:00:42 +0000118 if onuTP.techProfileKVStore == nil {
119 logger.Errorw("Can't access techProfileKVStore - no backend connection to service",
mpagenko01e726e2020-10-23 09:45:29 +0000120 log.Fields{"device-id": aDeviceHandler.deviceID, "service": cBasePathTechProfileKVStore})
mpagenkoaf801632020-07-03 10:00:42 +0000121 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000122
mpagenkoaf801632020-07-03 10:00:42 +0000123 return &onuTP
124}
125
126// lockTpProcMutex locks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530127func (onuTP *onuUniTechProf) lockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000128 onuTP.tpProcMutex.Lock()
129}
130
131// unlockTpProcMutex unlocks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530132func (onuTP *onuUniTechProf) unlockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000133 onuTP.tpProcMutex.Unlock()
134}
135
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000136// resetTpProcessingErrorIndication resets the internal error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000137// need to be called before evaluation of any subsequent processing (given by waitForTpCompletion())
Girish Gowdra041dcb32020-11-16 16:54:30 -0800138func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) {
139 onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000140}
141
Girish Gowdra041dcb32020-11-16 16:54:30 -0800142func (onuTP *onuUniTechProf) getTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error {
143 return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}]
mpagenko3dbcdd22020-07-22 07:38:45 +0000144}
145
146// configureUniTp checks existing tp resources to delete and starts the corresponding OMCI configuation of the UNI port
147// all possibly blocking processing must be run in background to allow for deadline supervision!
148// but take care on sequential background processing when needed (logical dependencies)
Himani Chawla4d908332020-08-31 12:30:20 +0530149// use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization
Himani Chawla6d2ae152020-09-02 13:11:20 +0530150func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context,
mpagenkodff5dda2020-08-28 11:52:01 +0000151 aUniID uint8, aPathString string, wg *sync.WaitGroup) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000152 defer wg.Done() //always decrement the waitGroup on return
mpagenkoaf801632020-07-03 10:00:42 +0000153 logger.Debugw("configure the Uni according to TpPath", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000154 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800155 tpID, err := GetTpIDFromTpPath(aPathString)
156 uniTpKey := uniTP{uniID: aUniID, tpID: tpID}
157 if err != nil {
158 logger.Errorw("error-extracting-tp-id-from-tp-path", log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
159 return
160 }
mpagenkoaf801632020-07-03 10:00:42 +0000161 if onuTP.techProfileKVStore == nil {
162 logger.Debug("techProfileKVStore not set - abort")
Girish Gowdra041dcb32020-11-16 16:54:30 -0800163 onuTP.procResult[uniTpKey] = errors.New("techProfile config aborted: techProfileKVStore not set")
mpagenkoaf801632020-07-03 10:00:42 +0000164 return
165 }
166
mpagenko3dbcdd22020-07-22 07:38:45 +0000167 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530168 var pCurrentUniPort *onuUniPort
mpagenko3dbcdd22020-07-22 07:38:45 +0000169 for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap {
170 // only if this port is validated for operState transfer
Girish Gowdra041dcb32020-11-16 16:54:30 -0800171 if uniPort.uniID == aUniID {
mpagenko3dbcdd22020-07-22 07:38:45 +0000172 pCurrentUniPort = uniPort
173 break //found - end search loop
174 }
175 }
176 if pCurrentUniPort == nil {
177 logger.Errorw("TechProfile configuration aborted: requested uniID not found in PortDB",
mpagenko01e726e2020-10-23 09:45:29 +0000178 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800179 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200180 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000181 return
182 }
mpagenkoaf801632020-07-03 10:00:42 +0000183
mpagenkodff5dda2020-08-28 11:52:01 +0000184 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
mpagenkoaf801632020-07-03 10:00:42 +0000185
mpagenko3dbcdd22020-07-22 07:38:45 +0000186 //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called
187 // in case the KVPath has changed for the given UNI,
188 // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
189 // (ANI) configuration of this port has to be removed first
190 // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
191 // existence of configuration can be detected based on tp stored TCONT's
Andrea Campanella6515c582020-10-05 11:25:00 +0200192 //TODO:
mpagenko3dbcdd22020-07-22 07:38:45 +0000193 /* if tcontMap not empty {
194 go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000195 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000196 //timeout or error detected
197 return
198 }
199 clear tcontMap
200 }
201
202 processingStep++
203 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800204 go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000205 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000206 //timeout or error detected
Girish Gowdra041dcb32020-11-16 16:54:30 -0800207 if onuTP.tpProfileExists[uniTpKey] {
mpagenko01e726e2020-10-23 09:45:29 +0000208 //ignore the internal error in case the new profile is already configured
209 // and abort the processing here
210 return
211 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000212 logger.Debugw("tech-profile related configuration aborted on read",
mpagenko01e726e2020-10-23 09:45:29 +0000213 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800214 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200215 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000216 return
217 }
218
219 processingStep++
Girish Gowdra041dcb32020-11-16 16:54:30 -0800220
221 valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey]
222
223 if existPA {
224 if valuePA != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000225 //Config data for this uni and and at least TCont Index 0 exist
Girish Gowdra041dcb32020-11-16 16:54:30 -0800226 go onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000227 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000228 //timeout or error detected
229 logger.Debugw("tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000230 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800231
232 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200233 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530234 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000235 //which requires to reset it to allow for new usage, e.g. also on a different UNI
236 //(without that it would be reset on device down indication latest)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800237 _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +0000238 return
mpagenkoaf801632020-07-03 10:00:42 +0000239 }
240 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000241 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
242 logger.Debugw("no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000243 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800244
245 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: no Tcont/Gem data found for this UNI %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200246 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000247 return
mpagenkoaf801632020-07-03 10:00:42 +0000248 }
249 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000250 logger.Debugw("no PonAni data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000251 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800252
253 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: no AniSide data found for this UNI %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200254 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000255 return
mpagenkoaf801632020-07-03 10:00:42 +0000256 }
257}
258
mpagenko3dbcdd22020-07-22 07:38:45 +0000259/* internal methods *********************/
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000260
Himani Chawla6d2ae152020-09-02 13:11:20 +0530261func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile(
Girish Gowdra041dcb32020-11-16 16:54:30 -0800262 ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000263 var tpInst tp.TechProfile
264
Girish Gowdra041dcb32020-11-16 16:54:30 -0800265 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
266
267 onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false
268
mpagenko3dbcdd22020-07-22 07:38:45 +0000269 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
270 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
271 subStringSlice := strings.Split(aPathString, "/")
272 if len(subStringSlice) <= 2 {
273 logger.Errorw("invalid path name format",
274 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000275 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000276 return
277 }
278
mpagenko3dbcdd22020-07-22 07:38:45 +0000279 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000280 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
281 // then we throw a warning, set an internal error and abort with error,
282 // which is later re-defined to success response to OLT adapter
283 // if TPId has changed, current data is removed (note that the ONU config state may be
284 // ambivalent in such a case)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800285 if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP {
mpagenko3dbcdd22020-07-22 07:38:45 +0000286 logger.Warnw("Some active profile entry at reading new TechProfile",
287 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800288 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
289 if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID {
mpagenko01e726e2020-10-23 09:45:29 +0000290 // ProfId not changed - assume profile to be still the same
291 // anyway this should not appear after full support of profile (Gem/TCont) removal
292 logger.Warnw("New TechProfile already exists - aborting configuration",
293 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800294 onuTP.tpProfileExists[uniTPKey] = true
mpagenko01e726e2020-10-23 09:45:29 +0000295 onuTP.chTpConfigProcessingStep <- 0 //error indication
296 return
297 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000298 //delete on the mapUniTpIndication map not needed, just overwritten later
299 //delete on the PonAniConfig map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800300 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenko3dbcdd22020-07-22 07:38:45 +0000301 } else {
302 // this is normal processing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800303 onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
mpagenko3dbcdd22020-07-22 07:38:45 +0000304 }
305
Girish Gowdra041dcb32020-11-16 16:54:30 -0800306 onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000307 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
Girish Gowdra041dcb32020-11-16 16:54:30 -0800308 onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID
309 onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false
310 onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false
mpagenko3dbcdd22020-07-22 07:38:45 +0000311 logger.Debugw("tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000312 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800313 "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType,
314 "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000315
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000316 Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString)
mpagenko3dbcdd22020-07-22 07:38:45 +0000317 if err == nil {
318 if Value != nil {
319 logger.Debugw("tech-profile read",
320 log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID})
321 tpTmpBytes, _ := kvstore.ToByte(Value.Value)
322
323 if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil {
324 logger.Errorw("TechProf - Failed to unmarshal tech-profile into tpInst",
325 log.Fields{"error": err, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000326 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000327 return
328 }
329 logger.Debugw("TechProf - tpInst", log.Fields{"tpInst": tpInst})
330 // access examples
331 logger.Debugw("TechProf content", log.Fields{"Name": tpInst.Name,
332 "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize,
333 "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
334 } else {
335 logger.Errorw("No tech-profile found",
336 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000337 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000338 return
339 }
340 } else {
341 logger.Errorw("kvstore-get failed for path",
342 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000343 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000344 return
345 }
346
mpagenko01e726e2020-10-23 09:45:29 +0000347 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000348 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
349 localMapGemPortParams[0] = &gemPortParamStruct{}
Girish Gowdra041dcb32020-11-16 16:54:30 -0800350 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000351
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000352 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000353 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra041dcb32020-11-16 16:54:30 -0800354 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID)
Himani Chawla4d908332020-08-31 12:30:20 +0530355 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000356 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
357 if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800358 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000359 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000360 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800361 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000362 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000363 loNumGemPorts := tpInst.NumGemPorts
364 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000365 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000366 if uint32(pos) == loNumGemPorts {
367 logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
368 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000369 break
370 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000371 if pos == 0 {
372 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
373 loGemPortRead = true
374 } else {
375 //for all further GemPorts we need to extend the mapGemPortParams
Girish Gowdra041dcb32020-11-16 16:54:30 -0800376 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)] = &gemPortParamStruct{}
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000377 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800378 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortID =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000379 uint16(content.GemportID)
380 //direction can be correlated later with Downstream list,
381 // for now just assume bidirectional (upstream never exists alone)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800382 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000383 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
384 if 7 < content.PriorityQueue {
385 logger.Errorw("PonAniConfig reject on GemPortList - PrioQueue value invalid",
386 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue})
387 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800388 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000389 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000390 return
391 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800392 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].prioQueueIndex =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000393 uint8(content.PriorityQueue)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800394 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530395 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000396 if content.AesEncryption == "True" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800397 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000398 } else {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800399 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000400 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800401 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].discardPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000402 content.DiscardPolicy
Girish Gowdra041dcb32020-11-16 16:54:30 -0800403 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].queueSchedPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000404 content.SchedulingPolicy
mpagenko3dbcdd22020-07-22 07:38:45 +0000405 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Girish Gowdra041dcb32020-11-16 16:54:30 -0800406 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000407 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000408 }
Himani Chawla4d908332020-08-31 12:30:20 +0530409 if !loGemPortRead {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000410 logger.Errorw("PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000411 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000412 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800413 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000414 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000415 return
416 }
Himani Chawla4d908332020-08-31 12:30:20 +0530417 //TODO!! MC (downstream) GemPorts can be set using DownstreamGemPortAttributeList separately
mpagenko3dbcdd22020-07-22 07:38:45 +0000418
419 //logger does not simply output the given structures, just give some example debug values
420 logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000421 "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800422 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
423 for gemIndex, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000424 logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
425 "GemIndex": gemIndex,
426 "GemPort": gemEntry.gemPortID,
427 "QueueScheduling": gemEntry.queueSchedPolicy})
428 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000429
mpagenkodff5dda2020-08-28 11:52:01 +0000430 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000431}
432
Himani Chawla6d2ae152020-09-02 13:11:20 +0530433func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
Girish Gowdra041dcb32020-11-16 16:54:30 -0800434 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000435
436 //OMCI transfer of ANI data acc. to mapPonAniConfig
437 // also the FSM's are running in background,
mpagenkodff5dda2020-08-28 11:52:01 +0000438 // hence we have to make sure they indicate 'success' success on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800439 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko3dbcdd22020-07-22 07:38:45 +0000440 if onuTP.pAniConfigFsm == nil {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800441 onuTP.createAniConfigFsm(aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
442 } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
443 onuTP.createAniConfigFsm(aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000444 } else { //AniConfigFsm already init
Girish Gowdra041dcb32020-11-16 16:54:30 -0800445 onuTP.runAniConfigFsm(aProcessingStep, aUniID, aTpID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000446 }
447}
448
Himani Chawla6d2ae152020-09-02 13:11:20 +0530449func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000450 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000451 select {
452 case <-ctx.Done():
453 logger.Warnw("processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000454 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000455 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000456 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000457 if rxStep == aProcessingStep {
458 return true
459 }
460 //all other values are not accepted - including 0 for error indication
461 logger.Warnw("Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000462 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000463 "wantedStep": aProcessingStep, "haveStep": rxStep})
464 return false
465 }
466}
467
Himani Chawla4d908332020-08-31 12:30:20 +0530468// createUniLockFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Girish Gowdra041dcb32020-11-16 16:54:30 -0800469func (onuTP *onuUniTechProf) createAniConfigFsm(aUniID uint8, aTpID uint8,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530470 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) {
divyadesai4d299552020-08-18 07:13:49 +0000471 logger.Debugw("createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000472 chAniConfigFsm := make(chan Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800473 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530474 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000475 if pDevEntry == nil {
divyadesai4d299552020-08-18 07:13:49 +0000476 logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000477 return
478 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530479 pAniCfgFsm := newUniPonAniConfigFsm(pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800480 pDevEntry.pOnuDB, aTpID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000481 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko3dbcdd22020-07-22 07:38:45 +0000482 if pAniCfgFsm != nil {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800483 if onuTP.pAniConfigFsm == nil {
484 onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm)
485 }
486 onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm
487 onuTP.runAniConfigFsm(aProcessingStep, aUniID, aTpID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000488 } else {
divyadesai4d299552020-08-18 07:13:49 +0000489 logger.Errorw("AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000490 }
491}
492
mpagenkofc4f56e2020-11-04 17:17:49 +0000493// deleteTpResource removes Resources from the ONU's specified Uni
494func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context,
495 aUniID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
496 wg *sync.WaitGroup) {
497 defer wg.Done()
498 logger.Debugw("this would remove TP resources from ONU's UNI", log.Fields{
499 "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "Resource": aResource})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800500 tpID, err := GetTpIDFromTpPath(aPathString)
501 if err != nil {
502 logger.Errorw("error-extracting-tp-id-from-tp-path", log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
503 return
504 }
505 uniTpKey := uniTP{uniID: aUniID, tpID: tpID}
mpagenkoa40e99a2020-11-17 13:50:39 +0000506 if cResourceGemPort == aResource {
507 logger.Debugw("remove GemPort from the list of existing ones of the TP", log.Fields{
508 "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "entry": aEntryID})
509 // check if the requested GemPort exists in the DB
510 // check that the TpConfigRequest was done
511 // initiate OMCI GemPort related removal
512 // remove GemPort from config DB
513 // dev reason update? (for the moment not yet done here!)
514 } else { //if cResourceTcont == aResource {
mpagenkofc4f56e2020-11-04 17:17:49 +0000515 //the TechProfile indicated by path is considered for removal
516 // by now we do not clear the OMCI related configuration (to be done later)
517 // so we use this position here just to remove the internal stored profile data
518 // (needed for checking the existence of the TechProfile after some profile delete)
519 // at the oment we only admit 1 TechProfile (T-Cont), so by now we can just remove the only existing TechProfile
520 // TODO: To be updated with multi-T-Cont implementation
521 logger.Debugw("DeleteTcont clears the existing internal profile", log.Fields{
522 "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "Resource": aResource})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800523
524 onuTP.clearAniSideConfig(aUniID, tpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000525 // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created
526 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
527 if onuTP.pAniConfigFsm != nil {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800528 _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset)
mpagenkofc4f56e2020-11-04 17:17:49 +0000529 }
530
531 //TODO!!! - the real processing could look like that (for starting the removal, where the clearAniSideConfig is done implicitly):
532 //delete the given resource from ONU OMCI config and data base - as background routine
533 /*
534 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
535 go onuTp.deleteAniResource(ctx, processingStep)
536 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
537 //timeout or error detected
538 return
539 }
540 */
541 }
542 //if implemented, the called FSM would generate an adequate event if config has been done,
543 // by now we just stimulate this event here as 'done' - TODO!!: to be removed after full implementation
544 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(OmciAniResourceRemoved)
545}
546
mpagenko3dbcdd22020-07-22 07:38:45 +0000547// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Girish Gowdra041dcb32020-11-16 16:54:30 -0800548func (onuTP *onuUniTechProf) runAniConfigFsm(aProcessingStep uint8, aUniID uint8, aTpID uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000549 /* Uni related ANI config procedure -
550 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
551 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800552 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
553
554 pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000555 if pACStatemachine != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000556 if pACStatemachine.Is(aniStDisabled) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000557 //FSM init requirement to get informed abou FSM completion! (otherwise timeout of the TechProf config)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800558 onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
mpagenko1cc3cb42020-07-27 15:24:38 +0000559 if err := pACStatemachine.Event(aniEvStart); err != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000560 logger.Warnw("AniConfigFSM: can't start", log.Fields{"err": err})
561 // maybe try a FSM reset and then again ... - TODO!!!
562 } else {
563 /***** AniConfigFSM started */
564 logger.Debugw("AniConfigFSM started", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000565 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000566 }
567 } else {
568 logger.Warnw("wrong state of AniConfigFSM - want: disabled", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000569 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000570 // maybe try a FSM reset and then again ... - TODO!!!
571 }
572 } else {
divyadesai4d299552020-08-18 07:13:49 +0000573 logger.Errorw("AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000574 // maybe try a FSM reset and then again ... - TODO!!!
575 }
mpagenkoaf801632020-07-03 10:00:42 +0000576}
mpagenkodff5dda2020-08-28 11:52:01 +0000577
Girish Gowdra041dcb32020-11-16 16:54:30 -0800578// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
579func (onuTP *onuUniTechProf) clearAniSideConfig(aUniID uint8, aTpID uint8) {
mpagenko01e726e2020-10-23 09:45:29 +0000580 logger.Debugw("removing TpIndication and PonAniConfig data", log.Fields{
581 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800582 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
583
584 onuTP.mutexTPState.Lock()
585 defer onuTP.mutexTPState.Unlock()
586 delete(onuTP.mapUniTpIndication, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000587 //delete on the PonAniConfig map of this UNI should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800588 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000589}
590
mpagenkodff5dda2020-08-28 11:52:01 +0000591// setConfigDone sets the requested techProfile config state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800592func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
593 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
594 onuTP.mutexTPState.Lock()
595 defer onuTP.mutexTPState.Unlock()
596 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
597 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000598 } //else: the state is just ignored (does not exist)
599}
600
601// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
Girish Gowdra041dcb32020-11-16 16:54:30 -0800602func (onuTP *onuUniTechProf) getTechProfileDone(aUniID uint8, aTpID uint8) bool {
603 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
604 onuTP.mutexTPState.Lock()
605 defer onuTP.mutexTPState.Unlock()
606 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
607 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
608 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
mpagenko2418ab02020-11-12 12:58:06 +0000609 logger.Debugw("TechProfile not relevant for requested flow config - waiting on delete",
610 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
611 return false //still waiting for removal of this techProfile first
612 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800613 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000614 }
615 }
616 //for all other constellations indicate false = Config not done
617 return false
618}
mpagenko2418ab02020-11-12 12:58:06 +0000619
620// setProfileToDelete sets the requested techProfile toDelete state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800621func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
622 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
623 onuTP.mutexTPState.Lock()
624 defer onuTP.mutexTPState.Unlock()
625 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
626 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000627 } //else: the state is just ignored (does not exist)
628}