blob: ee52b13a231065d4d012a2b2a7979bb5fc204f01 [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
Matteo Scandolof1f39a72020-11-24 12:08:11 -080034const cBasePathTechProfileKVStore = "%s/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 {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000107 logger.Debugw("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)
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800117 baseKvStorePath := fmt.Sprintf(cBasePathTechProfileKVStore, aDeviceHandler.pOpenOnuAc.cm.Backend.PathPrefix)
118 onuTP.techProfileKVStore = aDeviceHandler.setBackend(baseKvStorePath)
mpagenkoaf801632020-07-03 10:00:42 +0000119 if onuTP.techProfileKVStore == nil {
120 logger.Errorw("Can't access techProfileKVStore - no backend connection to service",
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800121 log.Fields{"device-id": aDeviceHandler.deviceID, "service": baseKvStorePath})
mpagenkoaf801632020-07-03 10:00:42 +0000122 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000123
mpagenkoaf801632020-07-03 10:00:42 +0000124 return &onuTP
125}
126
127// lockTpProcMutex locks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530128func (onuTP *onuUniTechProf) lockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000129 onuTP.tpProcMutex.Lock()
130}
131
132// unlockTpProcMutex unlocks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530133func (onuTP *onuUniTechProf) unlockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000134 onuTP.tpProcMutex.Unlock()
135}
136
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000137// resetTpProcessingErrorIndication resets the internal error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000138// need to be called before evaluation of any subsequent processing (given by waitForTpCompletion())
Girish Gowdra041dcb32020-11-16 16:54:30 -0800139func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) {
140 onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000141}
142
Girish Gowdra041dcb32020-11-16 16:54:30 -0800143func (onuTP *onuUniTechProf) getTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error {
144 return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}]
mpagenko3dbcdd22020-07-22 07:38:45 +0000145}
146
147// configureUniTp checks existing tp resources to delete and starts the corresponding OMCI configuation of the UNI port
148// all possibly blocking processing must be run in background to allow for deadline supervision!
149// but take care on sequential background processing when needed (logical dependencies)
Himani Chawla4d908332020-08-31 12:30:20 +0530150// use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization
Himani Chawla6d2ae152020-09-02 13:11:20 +0530151func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context,
mpagenkodff5dda2020-08-28 11:52:01 +0000152 aUniID uint8, aPathString string, wg *sync.WaitGroup) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000153 defer wg.Done() //always decrement the waitGroup on return
mpagenkoaf801632020-07-03 10:00:42 +0000154 logger.Debugw("configure the Uni according to TpPath", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000155 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800156 tpID, err := GetTpIDFromTpPath(aPathString)
157 uniTpKey := uniTP{uniID: aUniID, tpID: tpID}
158 if err != nil {
159 logger.Errorw("error-extracting-tp-id-from-tp-path", log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
160 return
161 }
mpagenkoaf801632020-07-03 10:00:42 +0000162 if onuTP.techProfileKVStore == nil {
163 logger.Debug("techProfileKVStore not set - abort")
Girish Gowdra041dcb32020-11-16 16:54:30 -0800164 onuTP.procResult[uniTpKey] = errors.New("techProfile config aborted: techProfileKVStore not set")
mpagenkoaf801632020-07-03 10:00:42 +0000165 return
166 }
167
mpagenko3dbcdd22020-07-22 07:38:45 +0000168 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530169 var pCurrentUniPort *onuUniPort
mpagenko3dbcdd22020-07-22 07:38:45 +0000170 for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap {
171 // only if this port is validated for operState transfer
Girish Gowdra041dcb32020-11-16 16:54:30 -0800172 if uniPort.uniID == aUniID {
mpagenko3dbcdd22020-07-22 07:38:45 +0000173 pCurrentUniPort = uniPort
174 break //found - end search loop
175 }
176 }
177 if pCurrentUniPort == nil {
178 logger.Errorw("TechProfile configuration aborted: requested uniID not found in PortDB",
mpagenko01e726e2020-10-23 09:45:29 +0000179 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800180 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200181 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000182 return
183 }
mpagenkoaf801632020-07-03 10:00:42 +0000184
mpagenkodff5dda2020-08-28 11:52:01 +0000185 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
mpagenkoaf801632020-07-03 10:00:42 +0000186
mpagenko3dbcdd22020-07-22 07:38:45 +0000187 //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called
188 // in case the KVPath has changed for the given UNI,
189 // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
190 // (ANI) configuration of this port has to be removed first
191 // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
192 // existence of configuration can be detected based on tp stored TCONT's
Andrea Campanella6515c582020-10-05 11:25:00 +0200193 //TODO:
mpagenko3dbcdd22020-07-22 07:38:45 +0000194 /* if tcontMap not empty {
195 go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000196 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000197 //timeout or error detected
198 return
199 }
200 clear tcontMap
201 }
202
203 processingStep++
204 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800205 go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000206 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000207 //timeout or error detected
Girish Gowdra041dcb32020-11-16 16:54:30 -0800208 if onuTP.tpProfileExists[uniTpKey] {
mpagenko01e726e2020-10-23 09:45:29 +0000209 //ignore the internal error in case the new profile is already configured
210 // and abort the processing here
211 return
212 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000213 logger.Debugw("tech-profile related configuration aborted on read",
mpagenko01e726e2020-10-23 09:45:29 +0000214 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800215 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200216 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000217 return
218 }
219
220 processingStep++
Girish Gowdra041dcb32020-11-16 16:54:30 -0800221
222 valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey]
223
224 if existPA {
225 if valuePA != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000226 //Config data for this uni and and at least TCont Index 0 exist
Girish Gowdra041dcb32020-11-16 16:54:30 -0800227 go onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000228 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000229 //timeout or error detected
230 logger.Debugw("tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000231 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800232
233 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200234 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530235 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000236 //which requires to reset it to allow for new usage, e.g. also on a different UNI
237 //(without that it would be reset on device down indication latest)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800238 _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +0000239 return
mpagenkoaf801632020-07-03 10:00:42 +0000240 }
241 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000242 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
243 logger.Debugw("no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000244 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800245
246 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 +0200247 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000248 return
mpagenkoaf801632020-07-03 10:00:42 +0000249 }
250 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000251 logger.Debugw("no PonAni data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000252 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800253
254 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 +0200255 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000256 return
mpagenkoaf801632020-07-03 10:00:42 +0000257 }
258}
259
mpagenko3dbcdd22020-07-22 07:38:45 +0000260/* internal methods *********************/
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000261
Himani Chawla6d2ae152020-09-02 13:11:20 +0530262func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile(
Girish Gowdra041dcb32020-11-16 16:54:30 -0800263 ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000264 var tpInst tp.TechProfile
265
Girish Gowdra041dcb32020-11-16 16:54:30 -0800266 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
267
268 onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false
269
mpagenko3dbcdd22020-07-22 07:38:45 +0000270 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
271 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
272 subStringSlice := strings.Split(aPathString, "/")
273 if len(subStringSlice) <= 2 {
274 logger.Errorw("invalid path name format",
275 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000276 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000277 return
278 }
279
mpagenko3dbcdd22020-07-22 07:38:45 +0000280 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000281 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
282 // then we throw a warning, set an internal error and abort with error,
283 // which is later re-defined to success response to OLT adapter
284 // if TPId has changed, current data is removed (note that the ONU config state may be
285 // ambivalent in such a case)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800286 if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP {
mpagenko3dbcdd22020-07-22 07:38:45 +0000287 logger.Warnw("Some active profile entry at reading new TechProfile",
288 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800289 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
290 if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID {
mpagenko01e726e2020-10-23 09:45:29 +0000291 // ProfId not changed - assume profile to be still the same
292 // anyway this should not appear after full support of profile (Gem/TCont) removal
293 logger.Warnw("New TechProfile already exists - aborting configuration",
294 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800295 onuTP.tpProfileExists[uniTPKey] = true
mpagenko01e726e2020-10-23 09:45:29 +0000296 onuTP.chTpConfigProcessingStep <- 0 //error indication
297 return
298 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000299 //delete on the mapUniTpIndication map not needed, just overwritten later
300 //delete on the PonAniConfig map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800301 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenko3dbcdd22020-07-22 07:38:45 +0000302 } else {
303 // this is normal processing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800304 onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
mpagenko3dbcdd22020-07-22 07:38:45 +0000305 }
306
Girish Gowdra041dcb32020-11-16 16:54:30 -0800307 onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000308 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
Girish Gowdra041dcb32020-11-16 16:54:30 -0800309 onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID
310 onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false
311 onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false
mpagenko3dbcdd22020-07-22 07:38:45 +0000312 logger.Debugw("tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000313 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800314 "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType,
315 "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000316
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000317 Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString)
mpagenko3dbcdd22020-07-22 07:38:45 +0000318 if err == nil {
319 if Value != nil {
320 logger.Debugw("tech-profile read",
321 log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID})
322 tpTmpBytes, _ := kvstore.ToByte(Value.Value)
323
324 if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil {
325 logger.Errorw("TechProf - Failed to unmarshal tech-profile into tpInst",
326 log.Fields{"error": err, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000327 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000328 return
329 }
330 logger.Debugw("TechProf - tpInst", log.Fields{"tpInst": tpInst})
331 // access examples
332 logger.Debugw("TechProf content", log.Fields{"Name": tpInst.Name,
333 "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize,
334 "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
335 } else {
336 logger.Errorw("No tech-profile found",
337 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000338 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000339 return
340 }
341 } else {
342 logger.Errorw("kvstore-get failed for path",
343 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000344 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000345 return
346 }
347
mpagenko01e726e2020-10-23 09:45:29 +0000348 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000349 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
350 localMapGemPortParams[0] = &gemPortParamStruct{}
Girish Gowdra041dcb32020-11-16 16:54:30 -0800351 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000352
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000353 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000354 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra041dcb32020-11-16 16:54:30 -0800355 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID)
Himani Chawla4d908332020-08-31 12:30:20 +0530356 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000357 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
358 if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800359 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000360 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000361 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800362 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000363 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000364 loNumGemPorts := tpInst.NumGemPorts
365 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000366 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000367 if uint32(pos) == loNumGemPorts {
368 logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
369 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000370 break
371 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000372 if pos == 0 {
373 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
374 loGemPortRead = true
375 } else {
376 //for all further GemPorts we need to extend the mapGemPortParams
Girish Gowdra041dcb32020-11-16 16:54:30 -0800377 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)] = &gemPortParamStruct{}
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000378 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800379 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortID =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000380 uint16(content.GemportID)
381 //direction can be correlated later with Downstream list,
382 // for now just assume bidirectional (upstream never exists alone)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800383 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000384 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
385 if 7 < content.PriorityQueue {
386 logger.Errorw("PonAniConfig reject on GemPortList - PrioQueue value invalid",
387 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue})
388 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800389 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000390 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000391 return
392 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800393 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].prioQueueIndex =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000394 uint8(content.PriorityQueue)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800395 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530396 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000397 if content.AesEncryption == "True" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800398 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000399 } else {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800400 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000401 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800402 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].discardPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000403 content.DiscardPolicy
Girish Gowdra041dcb32020-11-16 16:54:30 -0800404 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].queueSchedPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000405 content.SchedulingPolicy
mpagenko3dbcdd22020-07-22 07:38:45 +0000406 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Girish Gowdra041dcb32020-11-16 16:54:30 -0800407 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000408 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000409 }
Himani Chawla4d908332020-08-31 12:30:20 +0530410 if !loGemPortRead {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000411 logger.Errorw("PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000412 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000413 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800414 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000415 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000416 return
417 }
Himani Chawla4d908332020-08-31 12:30:20 +0530418 //TODO!! MC (downstream) GemPorts can be set using DownstreamGemPortAttributeList separately
mpagenko3dbcdd22020-07-22 07:38:45 +0000419
420 //logger does not simply output the given structures, just give some example debug values
421 logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000422 "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800423 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
424 for gemIndex, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000425 logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
426 "GemIndex": gemIndex,
427 "GemPort": gemEntry.gemPortID,
428 "QueueScheduling": gemEntry.queueSchedPolicy})
429 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000430
mpagenkodff5dda2020-08-28 11:52:01 +0000431 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000432}
433
Himani Chawla6d2ae152020-09-02 13:11:20 +0530434func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
Girish Gowdra041dcb32020-11-16 16:54:30 -0800435 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000436
437 //OMCI transfer of ANI data acc. to mapPonAniConfig
438 // also the FSM's are running in background,
mpagenkodff5dda2020-08-28 11:52:01 +0000439 // hence we have to make sure they indicate 'success' success on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800440 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko3dbcdd22020-07-22 07:38:45 +0000441 if onuTP.pAniConfigFsm == nil {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800442 onuTP.createAniConfigFsm(aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
443 } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
444 onuTP.createAniConfigFsm(aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000445 } else { //AniConfigFsm already init
Girish Gowdra041dcb32020-11-16 16:54:30 -0800446 onuTP.runAniConfigFsm(aProcessingStep, aUniID, aTpID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000447 }
448}
449
Himani Chawla6d2ae152020-09-02 13:11:20 +0530450func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000451 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000452 select {
453 case <-ctx.Done():
454 logger.Warnw("processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000455 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000456 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000457 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000458 if rxStep == aProcessingStep {
459 return true
460 }
461 //all other values are not accepted - including 0 for error indication
462 logger.Warnw("Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000463 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000464 "wantedStep": aProcessingStep, "haveStep": rxStep})
465 return false
466 }
467}
468
Himani Chawla4d908332020-08-31 12:30:20 +0530469// createUniLockFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Girish Gowdra041dcb32020-11-16 16:54:30 -0800470func (onuTP *onuUniTechProf) createAniConfigFsm(aUniID uint8, aTpID uint8,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530471 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) {
divyadesai4d299552020-08-18 07:13:49 +0000472 logger.Debugw("createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000473 chAniConfigFsm := make(chan Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800474 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530475 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000476 if pDevEntry == nil {
divyadesai4d299552020-08-18 07:13:49 +0000477 logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000478 return
479 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530480 pAniCfgFsm := newUniPonAniConfigFsm(pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800481 pDevEntry.pOnuDB, aTpID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000482 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko3dbcdd22020-07-22 07:38:45 +0000483 if pAniCfgFsm != nil {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800484 if onuTP.pAniConfigFsm == nil {
485 onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm)
486 }
487 onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm
488 onuTP.runAniConfigFsm(aProcessingStep, aUniID, aTpID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000489 } else {
divyadesai4d299552020-08-18 07:13:49 +0000490 logger.Errorw("AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000491 }
492}
493
mpagenkofc4f56e2020-11-04 17:17:49 +0000494// deleteTpResource removes Resources from the ONU's specified Uni
495func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context,
496 aUniID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
497 wg *sync.WaitGroup) {
498 defer wg.Done()
499 logger.Debugw("this would remove TP resources from ONU's UNI", log.Fields{
500 "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "Resource": aResource})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800501 tpID, err := GetTpIDFromTpPath(aPathString)
502 if err != nil {
503 logger.Errorw("error-extracting-tp-id-from-tp-path", log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
504 return
505 }
506 uniTpKey := uniTP{uniID: aUniID, tpID: tpID}
mpagenkoa40e99a2020-11-17 13:50:39 +0000507 if cResourceGemPort == aResource {
508 logger.Debugw("remove GemPort from the list of existing ones of the TP", log.Fields{
509 "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "entry": aEntryID})
510 // check if the requested GemPort exists in the DB
511 // check that the TpConfigRequest was done
512 // initiate OMCI GemPort related removal
513 // remove GemPort from config DB
514 // dev reason update? (for the moment not yet done here!)
515 } else { //if cResourceTcont == aResource {
mpagenkofc4f56e2020-11-04 17:17:49 +0000516 //the TechProfile indicated by path is considered for removal
517 // by now we do not clear the OMCI related configuration (to be done later)
518 // so we use this position here just to remove the internal stored profile data
519 // (needed for checking the existence of the TechProfile after some profile delete)
520 // at the oment we only admit 1 TechProfile (T-Cont), so by now we can just remove the only existing TechProfile
521 // TODO: To be updated with multi-T-Cont implementation
522 logger.Debugw("DeleteTcont clears the existing internal profile", log.Fields{
523 "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "Resource": aResource})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800524
525 onuTP.clearAniSideConfig(aUniID, tpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000526 // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created
527 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
528 if onuTP.pAniConfigFsm != nil {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800529 _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset)
mpagenkofc4f56e2020-11-04 17:17:49 +0000530 }
531
532 //TODO!!! - the real processing could look like that (for starting the removal, where the clearAniSideConfig is done implicitly):
533 //delete the given resource from ONU OMCI config and data base - as background routine
534 /*
535 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
536 go onuTp.deleteAniResource(ctx, processingStep)
537 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
538 //timeout or error detected
539 return
540 }
541 */
542 }
543 //if implemented, the called FSM would generate an adequate event if config has been done,
544 // by now we just stimulate this event here as 'done' - TODO!!: to be removed after full implementation
545 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(OmciAniResourceRemoved)
546}
547
mpagenko3dbcdd22020-07-22 07:38:45 +0000548// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Girish Gowdra041dcb32020-11-16 16:54:30 -0800549func (onuTP *onuUniTechProf) runAniConfigFsm(aProcessingStep uint8, aUniID uint8, aTpID uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000550 /* Uni related ANI config procedure -
551 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
552 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800553 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
554
555 pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000556 if pACStatemachine != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000557 if pACStatemachine.Is(aniStDisabled) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000558 //FSM init requirement to get informed abou FSM completion! (otherwise timeout of the TechProf config)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800559 onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
mpagenko1cc3cb42020-07-27 15:24:38 +0000560 if err := pACStatemachine.Event(aniEvStart); err != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000561 logger.Warnw("AniConfigFSM: can't start", log.Fields{"err": err})
562 // maybe try a FSM reset and then again ... - TODO!!!
563 } else {
564 /***** AniConfigFSM started */
565 logger.Debugw("AniConfigFSM started", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000566 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000567 }
568 } else {
569 logger.Warnw("wrong state of AniConfigFSM - want: disabled", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000570 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000571 // maybe try a FSM reset and then again ... - TODO!!!
572 }
573 } else {
divyadesai4d299552020-08-18 07:13:49 +0000574 logger.Errorw("AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000575 // maybe try a FSM reset and then again ... - TODO!!!
576 }
mpagenkoaf801632020-07-03 10:00:42 +0000577}
mpagenkodff5dda2020-08-28 11:52:01 +0000578
Girish Gowdra041dcb32020-11-16 16:54:30 -0800579// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
580func (onuTP *onuUniTechProf) clearAniSideConfig(aUniID uint8, aTpID uint8) {
mpagenko01e726e2020-10-23 09:45:29 +0000581 logger.Debugw("removing TpIndication and PonAniConfig data", log.Fields{
582 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800583 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
584
585 onuTP.mutexTPState.Lock()
586 defer onuTP.mutexTPState.Unlock()
587 delete(onuTP.mapUniTpIndication, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000588 //delete on the PonAniConfig map of this UNI should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800589 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000590}
591
mpagenkodff5dda2020-08-28 11:52:01 +0000592// setConfigDone sets the requested techProfile config state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800593func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
594 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
595 onuTP.mutexTPState.Lock()
596 defer onuTP.mutexTPState.Unlock()
597 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
598 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000599 } //else: the state is just ignored (does not exist)
600}
601
602// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
Girish Gowdra041dcb32020-11-16 16:54:30 -0800603func (onuTP *onuUniTechProf) getTechProfileDone(aUniID uint8, aTpID uint8) bool {
604 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
605 onuTP.mutexTPState.Lock()
606 defer onuTP.mutexTPState.Unlock()
607 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
608 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
609 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
mpagenko2418ab02020-11-12 12:58:06 +0000610 logger.Debugw("TechProfile not relevant for requested flow config - waiting on delete",
611 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
612 return false //still waiting for removal of this techProfile first
613 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800614 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000615 }
616 }
617 //for all other constellations indicate false = Config not done
618 return false
619}
mpagenko2418ab02020-11-12 12:58:06 +0000620
621// setProfileToDelete sets the requested techProfile toDelete state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800622func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
623 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
624 onuTP.mutexTPState.Lock()
625 defer onuTP.mutexTPState.Unlock()
626 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
627 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000628 } //else: the state is just ignored (does not exist)
629}