blob: 102f32da361cad80bb45771933a984d1c6d14bce [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
mpagenko8b07c1b2020-11-26 10:36:31 +000075 removeIndex uint16
mpagenko3dbcdd22020-07-22 07:38:45 +000076}
77
78//refers to one tcont and its properties and all assigned GemPorts and their properties
79type tcontGemList struct {
80 tcontParams tcontParamStruct
81 mapGemPortParams map[uint16]*gemPortParamStruct
82}
83
Girish Gowdra041dcb32020-11-16 16:54:30 -080084// refers a unique combination of uniID and tpID for a given ONU.
85type uniTP struct {
86 uniID uint8
87 tpID uint8
88}
mpagenko3dbcdd22020-07-22 07:38:45 +000089
Himani Chawla6d2ae152020-09-02 13:11:20 +053090//onuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU
91type onuUniTechProf struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053092 baseDeviceHandler *deviceHandler
mpagenko01e726e2020-10-23 09:45:29 +000093 deviceID string
mpagenkodff5dda2020-08-28 11:52:01 +000094 tpProcMutex sync.RWMutex
mpagenkodff5dda2020-08-28 11:52:01 +000095 techProfileKVStore *db.Backend
mpagenkodff5dda2020-08-28 11:52:01 +000096 chTpConfigProcessingStep chan uint8
Girish Gowdra041dcb32020-11-16 16:54:30 -080097 mapUniTpIndication map[uniTP]*tTechProfileIndication //use pointer values to ease assignments to the map
98 mapPonAniConfig map[uniTP]*tcontGemList //per UNI: use pointer values to ease assignments to the map
99 pAniConfigFsm map[uniTP]*uniPonAniConfigFsm
100 procResult map[uniTP]error //error indication of processing
mpagenkodff5dda2020-08-28 11:52:01 +0000101 mutexTPState sync.Mutex
Girish Gowdra041dcb32020-11-16 16:54:30 -0800102 tpProfileExists map[uniTP]bool
mpagenko8b07c1b2020-11-26 10:36:31 +0000103 mapRemoveGemEntry map[uniTP]*gemPortParamStruct //per UNI: pointer to GemEntry to be removed
mpagenkoaf801632020-07-03 10:00:42 +0000104}
105
Himani Chawla6d2ae152020-09-02 13:11:20 +0530106//newOnuUniTechProf returns the instance of a OnuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000107//(one instance per ONU/deviceHandler for all possible UNI's)
mpagenko01e726e2020-10-23 09:45:29 +0000108func newOnuUniTechProf(ctx context.Context, aDeviceHandler *deviceHandler) *onuUniTechProf {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000109 logger.Debugw("init-OnuUniTechProf", log.Fields{"device-id": aDeviceHandler.deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530110 var onuTP onuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000111 onuTP.baseDeviceHandler = aDeviceHandler
mpagenko01e726e2020-10-23 09:45:29 +0000112 onuTP.deviceID = aDeviceHandler.deviceID
mpagenkoaf801632020-07-03 10:00:42 +0000113 onuTP.tpProcMutex = sync.RWMutex{}
mpagenkodff5dda2020-08-28 11:52:01 +0000114 onuTP.chTpConfigProcessingStep = make(chan uint8)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800115 onuTP.mapUniTpIndication = make(map[uniTP]*tTechProfileIndication)
116 onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList)
117 onuTP.procResult = make(map[uniTP]error)
118 onuTP.tpProfileExists = make(map[uniTP]bool)
mpagenko8b07c1b2020-11-26 10:36:31 +0000119 onuTP.mapRemoveGemEntry = make(map[uniTP]*gemPortParamStruct)
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800120 baseKvStorePath := fmt.Sprintf(cBasePathTechProfileKVStore, aDeviceHandler.pOpenOnuAc.cm.Backend.PathPrefix)
121 onuTP.techProfileKVStore = aDeviceHandler.setBackend(baseKvStorePath)
mpagenkoaf801632020-07-03 10:00:42 +0000122 if onuTP.techProfileKVStore == nil {
123 logger.Errorw("Can't access techProfileKVStore - no backend connection to service",
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800124 log.Fields{"device-id": aDeviceHandler.deviceID, "service": baseKvStorePath})
mpagenkoaf801632020-07-03 10:00:42 +0000125 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000126
mpagenkoaf801632020-07-03 10:00:42 +0000127 return &onuTP
128}
129
130// lockTpProcMutex locks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530131func (onuTP *onuUniTechProf) lockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000132 onuTP.tpProcMutex.Lock()
133}
134
135// unlockTpProcMutex unlocks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530136func (onuTP *onuUniTechProf) unlockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000137 onuTP.tpProcMutex.Unlock()
138}
139
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000140// resetTpProcessingErrorIndication resets the internal error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000141// need to be called before evaluation of any subsequent processing (given by waitForTpCompletion())
Girish Gowdra041dcb32020-11-16 16:54:30 -0800142func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) {
143 onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000144}
145
Girish Gowdra041dcb32020-11-16 16:54:30 -0800146func (onuTP *onuUniTechProf) getTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error {
147 return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}]
mpagenko3dbcdd22020-07-22 07:38:45 +0000148}
149
mpagenko8b07c1b2020-11-26 10:36:31 +0000150// configureUniTp checks existing tp resources to configure and starts the corresponding OMCI configuation of the UNI port
mpagenko3dbcdd22020-07-22 07:38:45 +0000151// all possibly blocking processing must be run in background to allow for deadline supervision!
152// but take care on sequential background processing when needed (logical dependencies)
Himani Chawla4d908332020-08-31 12:30:20 +0530153// use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization
Himani Chawla6d2ae152020-09-02 13:11:20 +0530154func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context,
mpagenkodff5dda2020-08-28 11:52:01 +0000155 aUniID uint8, aPathString string, wg *sync.WaitGroup) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000156 defer wg.Done() //always decrement the waitGroup on return
mpagenkoaf801632020-07-03 10:00:42 +0000157 logger.Debugw("configure the Uni according to TpPath", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000158 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800159 tpID, err := GetTpIDFromTpPath(aPathString)
160 uniTpKey := uniTP{uniID: aUniID, tpID: tpID}
161 if err != nil {
162 logger.Errorw("error-extracting-tp-id-from-tp-path", log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
163 return
164 }
mpagenkoaf801632020-07-03 10:00:42 +0000165 if onuTP.techProfileKVStore == nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000166 logger.Errorw("techProfileKVStore not set - abort",
167 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800168 onuTP.procResult[uniTpKey] = errors.New("techProfile config aborted: techProfileKVStore not set")
mpagenkoaf801632020-07-03 10:00:42 +0000169 return
170 }
171
mpagenko3dbcdd22020-07-22 07:38:45 +0000172 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530173 var pCurrentUniPort *onuUniPort
mpagenko3dbcdd22020-07-22 07:38:45 +0000174 for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap {
175 // only if this port is validated for operState transfer
Girish Gowdra041dcb32020-11-16 16:54:30 -0800176 if uniPort.uniID == aUniID {
mpagenko3dbcdd22020-07-22 07:38:45 +0000177 pCurrentUniPort = uniPort
178 break //found - end search loop
179 }
180 }
181 if pCurrentUniPort == nil {
182 logger.Errorw("TechProfile configuration aborted: requested uniID not found in PortDB",
mpagenko01e726e2020-10-23 09:45:29 +0000183 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800184 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200185 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000186 return
187 }
mpagenkoaf801632020-07-03 10:00:42 +0000188
mpagenkodff5dda2020-08-28 11:52:01 +0000189 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
mpagenkoaf801632020-07-03 10:00:42 +0000190
mpagenko3dbcdd22020-07-22 07:38:45 +0000191 //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called
192 // in case the KVPath has changed for the given UNI,
193 // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
194 // (ANI) configuration of this port has to be removed first
195 // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
196 // existence of configuration can be detected based on tp stored TCONT's
Andrea Campanella6515c582020-10-05 11:25:00 +0200197 //TODO:
mpagenko3dbcdd22020-07-22 07:38:45 +0000198 /* if tcontMap not empty {
199 go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000200 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000201 //timeout or error detected
202 return
203 }
204 clear tcontMap
205 }
206
207 processingStep++
208 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800209 go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000210 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000211 //timeout or error detected
Girish Gowdra041dcb32020-11-16 16:54:30 -0800212 if onuTP.tpProfileExists[uniTpKey] {
mpagenko01e726e2020-10-23 09:45:29 +0000213 //ignore the internal error in case the new profile is already configured
214 // and abort the processing here
215 return
216 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000217 logger.Errorw("tech-profile related configuration aborted on read",
mpagenko01e726e2020-10-23 09:45:29 +0000218 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800219 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200220 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000221 return
222 }
223
224 processingStep++
Girish Gowdra041dcb32020-11-16 16:54:30 -0800225
226 valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey]
227
228 if existPA {
229 if valuePA != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000230 //Config data for this uni and and at least TCont Index 0 exist
mpagenko8b07c1b2020-11-26 10:36:31 +0000231 if err := onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep); err != nil {
232 logger.Errorw("tech-profile related FSM could not be started",
233 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
234 onuTP.procResult[uniTpKey] = err
235 return
236 }
mpagenkodff5dda2020-08-28 11:52:01 +0000237 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000238 //timeout or error detected
mpagenko8b07c1b2020-11-26 10:36:31 +0000239 logger.Errorw("tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000240 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800241
242 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200243 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530244 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000245 //which requires to reset it to allow for new usage, e.g. also on a different UNI
246 //(without that it would be reset on device down indication latest)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800247 _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +0000248 return
mpagenkoaf801632020-07-03 10:00:42 +0000249 }
250 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000251 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
mpagenko8b07c1b2020-11-26 10:36:31 +0000252 logger.Errorw("no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000253 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800254
255 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 +0200256 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000257 return
mpagenkoaf801632020-07-03 10:00:42 +0000258 }
259 } else {
mpagenko8b07c1b2020-11-26 10:36:31 +0000260 logger.Errorw("no PonAni data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000261 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800262
263 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 +0200264 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000265 return
mpagenkoaf801632020-07-03 10:00:42 +0000266 }
267}
268
mpagenko3dbcdd22020-07-22 07:38:45 +0000269/* internal methods *********************/
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000270
Himani Chawla6d2ae152020-09-02 13:11:20 +0530271func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile(
Girish Gowdra041dcb32020-11-16 16:54:30 -0800272 ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000273 var tpInst tp.TechProfile
274
Girish Gowdra041dcb32020-11-16 16:54:30 -0800275 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
276
277 onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false
278
mpagenko3dbcdd22020-07-22 07:38:45 +0000279 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
280 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
281 subStringSlice := strings.Split(aPathString, "/")
282 if len(subStringSlice) <= 2 {
283 logger.Errorw("invalid path name format",
284 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000285 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000286 return
287 }
288
mpagenko3dbcdd22020-07-22 07:38:45 +0000289 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000290 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
291 // then we throw a warning, set an internal error and abort with error,
292 // which is later re-defined to success response to OLT adapter
293 // if TPId has changed, current data is removed (note that the ONU config state may be
294 // ambivalent in such a case)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800295 if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP {
mpagenko3dbcdd22020-07-22 07:38:45 +0000296 logger.Warnw("Some active profile entry at reading new TechProfile",
297 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800298 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
299 if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID {
mpagenko01e726e2020-10-23 09:45:29 +0000300 // ProfId not changed - assume profile to be still the same
301 // anyway this should not appear after full support of profile (Gem/TCont) removal
302 logger.Warnw("New TechProfile already exists - aborting configuration",
303 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800304 onuTP.tpProfileExists[uniTPKey] = true
mpagenko01e726e2020-10-23 09:45:29 +0000305 onuTP.chTpConfigProcessingStep <- 0 //error indication
306 return
307 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000308 //delete on the mapUniTpIndication map not needed, just overwritten later
309 //delete on the PonAniConfig map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800310 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenko3dbcdd22020-07-22 07:38:45 +0000311 } else {
312 // this is normal processing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800313 onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
mpagenko3dbcdd22020-07-22 07:38:45 +0000314 }
315
Girish Gowdra041dcb32020-11-16 16:54:30 -0800316 onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000317 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
Girish Gowdra041dcb32020-11-16 16:54:30 -0800318 onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID
319 onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false
320 onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false
mpagenko3dbcdd22020-07-22 07:38:45 +0000321 logger.Debugw("tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000322 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800323 "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType,
324 "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000325
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000326 Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString)
mpagenko3dbcdd22020-07-22 07:38:45 +0000327 if err == nil {
328 if Value != nil {
329 logger.Debugw("tech-profile read",
330 log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID})
331 tpTmpBytes, _ := kvstore.ToByte(Value.Value)
332
333 if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil {
334 logger.Errorw("TechProf - Failed to unmarshal tech-profile into tpInst",
335 log.Fields{"error": err, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000336 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000337 return
338 }
339 logger.Debugw("TechProf - tpInst", log.Fields{"tpInst": tpInst})
340 // access examples
341 logger.Debugw("TechProf content", log.Fields{"Name": tpInst.Name,
342 "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize,
343 "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
344 } else {
345 logger.Errorw("No tech-profile found",
346 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000347 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000348 return
349 }
350 } else {
351 logger.Errorw("kvstore-get failed for path",
352 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000353 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000354 return
355 }
356
mpagenko01e726e2020-10-23 09:45:29 +0000357 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000358 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
359 localMapGemPortParams[0] = &gemPortParamStruct{}
Girish Gowdra041dcb32020-11-16 16:54:30 -0800360 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000361
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000362 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000363 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra041dcb32020-11-16 16:54:30 -0800364 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID)
Himani Chawla4d908332020-08-31 12:30:20 +0530365 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000366 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
367 if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800368 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000369 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000370 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800371 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000372 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000373 loNumGemPorts := tpInst.NumGemPorts
374 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000375 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000376 if uint32(pos) == loNumGemPorts {
377 logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
378 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000379 break
380 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000381 if pos == 0 {
382 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
383 loGemPortRead = true
384 } else {
385 //for all further GemPorts we need to extend the mapGemPortParams
Girish Gowdra041dcb32020-11-16 16:54:30 -0800386 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)] = &gemPortParamStruct{}
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000387 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800388 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortID =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000389 uint16(content.GemportID)
390 //direction can be correlated later with Downstream list,
391 // for now just assume bidirectional (upstream never exists alone)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800392 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000393 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
394 if 7 < content.PriorityQueue {
395 logger.Errorw("PonAniConfig reject on GemPortList - PrioQueue value invalid",
396 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue})
397 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800398 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000399 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000400 return
401 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800402 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].prioQueueIndex =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000403 uint8(content.PriorityQueue)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800404 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530405 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000406 if content.AesEncryption == "True" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800407 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000408 } else {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800409 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000410 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800411 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].discardPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000412 content.DiscardPolicy
Girish Gowdra041dcb32020-11-16 16:54:30 -0800413 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].queueSchedPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000414 content.SchedulingPolicy
mpagenko3dbcdd22020-07-22 07:38:45 +0000415 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Girish Gowdra041dcb32020-11-16 16:54:30 -0800416 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000417 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000418 }
Himani Chawla4d908332020-08-31 12:30:20 +0530419 if !loGemPortRead {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000420 logger.Errorw("PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000421 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000422 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800423 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000424 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000425 return
426 }
Himani Chawla4d908332020-08-31 12:30:20 +0530427 //TODO!! MC (downstream) GemPorts can be set using DownstreamGemPortAttributeList separately
mpagenko3dbcdd22020-07-22 07:38:45 +0000428
429 //logger does not simply output the given structures, just give some example debug values
430 logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000431 "device-id": onuTP.deviceID, "uni-id": aUniID,
432 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800433 for gemIndex, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000434 logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
435 "GemIndex": gemIndex,
436 "GemPort": gemEntry.gemPortID,
437 "QueueScheduling": gemEntry.queueSchedPolicy})
438 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000439
mpagenkodff5dda2020-08-28 11:52:01 +0000440 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000441}
442
Himani Chawla6d2ae152020-09-02 13:11:20 +0530443func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
mpagenko8b07c1b2020-11-26 10:36:31 +0000444 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000445
446 //OMCI transfer of ANI data acc. to mapPonAniConfig
447 // also the FSM's are running in background,
mpagenko8b07c1b2020-11-26 10:36:31 +0000448 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800449 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko3dbcdd22020-07-22 07:38:45 +0000450 if onuTP.pAniConfigFsm == nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000451 return onuTP.createAniConfigFsm(aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800452 } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
mpagenko8b07c1b2020-11-26 10:36:31 +0000453 return onuTP.createAniConfigFsm(aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000454 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000455 //AniConfigFsm already init
456 return onuTP.runAniConfigFsm(aniEvStart, aProcessingStep, aUniID, aTpID)
457}
458
459// deleteTpResource removes Resources from the ONU's specified Uni
460func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context,
461 aUniID uint8, aTpID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
462 wg *sync.WaitGroup) {
463 defer wg.Done()
464 logger.Debugw("will remove TP resources from ONU's UNI", log.Fields{
465 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "Resource": aResource})
466 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
467
468 if cResourceGemPort == aResource {
469 logger.Debugw("remove GemPort from the list of existing ones of the TP", log.Fields{
470 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID})
471
472 // check if the requested GemPort exists in the DB, indicate it to the FSM
473 // store locally to remove it from DB later on success
474 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
475 if pLocAniConfigOnUni == nil {
476 // No relevant entry exists anymore - acknowledge success
477 logger.Debugw("AniConfig or GemEntry do not exists in DB", log.Fields{
478 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
479 return
480 }
481 for gemIndex, gemEntry := range pLocAniConfigOnUni.mapGemPortParams {
482 if gemEntry.gemPortID == uint16(aEntryID) {
483 //GemEntry to be deleted found
484 gemEntry.removeIndex = gemIndex //store the index for later removal
485 onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemIndex]
486 logger.Debugw("Remove-GemEntry stored", log.Fields{
487 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemIndex": gemIndex})
488 break //abort loop, always only one GemPort to remove
489 }
490 }
491 if onuTP.mapRemoveGemEntry[uniTPKey] == nil {
492 logger.Errorw("GemPort removal aborted - GemPort not found",
493 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
494 /* Do not set some error indication to the outside system interface on delete
495 assume there is nothing to be deleted internally and hope a new config request will recover the situation
496 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s",
497 aEntryID, aUniID, onuTP.deviceID)
498 */
499 return
500 }
501 if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig {
502 // check that the TpConfigRequest was done before
503 // -> that is implicitly done using the AniConfigFsm,
504 // which must be in the according state to remove something
505 // initiate OMCI GemPort related removal
506 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
507 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
508 if onuTP.pAniConfigFsm == nil {
509 logger.Errorw("abort GemPort removal - no AniConfigFsm available",
510 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
511 /* Do not set some error indication to the outside system interface on delete (see above)
512 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s",
513 aUniID, onuTP.deviceID)
514 */
515 //if the FSM is not valid, also TP related remove data should not be valid:
516 // remove GemPort from config DB
517 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeIndex)
518 // remove the removeEntry
519 delete(onuTP.mapRemoveGemEntry, uniTPKey)
520 return
521 }
522 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
523 logger.Errorw("abort GemPort removal - no AniConfigFsm available for this uni/tp",
524 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
525 /* Do not set some error indication to the outside system interface on delete (see above)
526 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid",
527 aUniID, onuTP.deviceID, aTpID)
528 */
529 //if the FSM is not valid, also TP related remove data should not be valid:
530 // remove GemPort from config DB
531 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeIndex)
532 // remove the removeEntry
533 delete(onuTP.mapRemoveGemEntry, uniTPKey)
534 return
535 }
536 if nil != onuTP.runAniConfigFsm(aniEvRemGemiw, processingStep, aUniID, aTpID) {
537 //even if the FSM invocation did not work we don't indicate a problem within procResult
538 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
539 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
540 return
541 }
542 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
543 //timeout or error detected
544 logger.Errorw("GemPort removal aborted - Omci AniSideConfig failed",
545 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
546 //even if the FSM delete execution did not work we don't indicate a problem within procResult
547 //we should never respond to delete with error ...
548 //this issue here means that the AniConfigFsm has not finished successfully
549 //which requires to reset it to allow for new usage, e.g. also on a different UNI
550 //(without that it would be reset on device down indication latest)
551 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
552 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
553 return
554 }
555 } else {
556 logger.Debugw("uniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{
557 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.deviceReason})
558 }
559 // remove GemPort from config DB
560 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeIndex)
561 // remove the removeEntry
562 delete(onuTP.mapRemoveGemEntry, uniTPKey)
563 // deviceHandler StatusEvent (reason update) (see end of function) is only generated in case some element really was removed
564 } else { //if cResourceTcont == aResource {
565 logger.Debugw("reset TCont with AllocId", log.Fields{
566 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID})
567
568 // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM
569 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
570 if pLocAniConfigOnUni == nil {
571 // No relevant entry exists anymore - acknowledge success
572 logger.Debugw("AniConfig or TCont entry do not exists in DB", log.Fields{
573 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
574 return
575 }
576 if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) {
577 logger.Errorw("TCont removal aborted - indicated AllocId not found",
578 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID})
579 /* Do not set some error indication to the outside system interface on delete
580 assume there is nothing to be deleted internally and hope a new config request will recover the situation
581 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s",
582 aEntryID, aUniID, onuTP.deviceID)
583 */
584 return
585 }
586 //T-Cont to be reset found
587 logger.Debugw("Reset-T-Cont AllocId found - valid", log.Fields{
588 "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID})
589 if onuTP.pAniConfigFsm == nil {
590 logger.Errorw("no TCont removal on OMCI - no AniConfigFsm available",
591 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
592 /* Do not set some error indication to the outside system interface on delete (see above)
593 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s",
594 aUniID, onuTP.deviceID)
595 */
596 //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data
597 onuTP.clearAniSideConfig(aUniID, aTpID)
598 return
599 }
600 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
601 logger.Errorw("no TCont removal on OMCI - no AniConfigFsm available for this uni/tp",
602 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
603 //even if the FSM invocation did not work we don't indicate a problem within procResult
604 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
605 //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data
606 onuTP.clearAniSideConfig(aUniID, aTpID)
607 return
608 }
609 if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig {
610 // check that the TpConfigRequest was done before
611 // -> that is implicitly done using the AniConfigFsm,
612 // which must be in the according state to remove something
613 // initiate OMCI TCont related cleanup
614 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
615 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
616 if nil != onuTP.runAniConfigFsm(aniEvRemTcontPath, processingStep, aUniID, aTpID) {
617 //even if the FSM invocation did not work we don't indicate a problem within procResult
618 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
619 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
620 return
621 }
622 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
623 //timeout or error detected
624 logger.Errorw("TCont cleanup aborted - Omci AniSideConfig failed",
625 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
626 //even if the FSM delete execution did not work we don't indicate a problem within procResult
627 //we should never respond to delete with error ...
628 //this issue here means that the AniConfigFsm has not finished successfully
629 //which requires to reset it to allow for new usage, e.g. also on a different UNI
630 //(without that it would be reset on device down indication latest)
631 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
632 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
633 return
634 }
635 } else {
636 logger.Debugw("uniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{
637 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.deviceReason})
638 }
639 //clear the internal store profile data
640 onuTP.clearAniSideConfig(aUniID, aTpID)
641 // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created
642 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
643 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
644 }
645 // generate deviceHandler StatusEvent in case the FSM was not invoked
646 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(OmciAniResourceRemoved)
mpagenko3dbcdd22020-07-22 07:38:45 +0000647}
648
Himani Chawla6d2ae152020-09-02 13:11:20 +0530649func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000650 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000651 select {
652 case <-ctx.Done():
653 logger.Warnw("processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000654 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000655 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000656 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000657 if rxStep == aProcessingStep {
658 return true
659 }
660 //all other values are not accepted - including 0 for error indication
661 logger.Warnw("Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000662 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000663 "wantedStep": aProcessingStep, "haveStep": rxStep})
664 return false
665 }
666}
667
Himani Chawla4d908332020-08-31 12:30:20 +0530668// createUniLockFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Girish Gowdra041dcb32020-11-16 16:54:30 -0800669func (onuTP *onuUniTechProf) createAniConfigFsm(aUniID uint8, aTpID uint8,
mpagenko8b07c1b2020-11-26 10:36:31 +0000670 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) error {
divyadesai4d299552020-08-18 07:13:49 +0000671 logger.Debugw("createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000672 chAniConfigFsm := make(chan Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800673 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530674 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000675 if pDevEntry == nil {
divyadesai4d299552020-08-18 07:13:49 +0000676 logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000677 return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000678 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530679 pAniCfgFsm := newUniPonAniConfigFsm(pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800680 pDevEntry.pOnuDB, aTpID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000681 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko8b07c1b2020-11-26 10:36:31 +0000682 if pAniCfgFsm == nil {
divyadesai4d299552020-08-18 07:13:49 +0000683 logger.Errorw("AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000684 return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000685 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000686 if onuTP.pAniConfigFsm == nil {
687 onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800688 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000689 onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm
690 return onuTP.runAniConfigFsm(aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000691}
692
mpagenko3dbcdd22020-07-22 07:38:45 +0000693// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
mpagenko8b07c1b2020-11-26 10:36:31 +0000694func (onuTP *onuUniTechProf) runAniConfigFsm(aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000695 /* Uni related ANI config procedure -
696 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
697 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800698 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
699
700 pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000701 if pACStatemachine != nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000702 if aEvent == aniEvStart {
703 if !pACStatemachine.Is(aniStDisabled) {
704 logger.Errorw("wrong state of AniConfigFSM to start - want: Disabled", log.Fields{
705 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000706 // maybe try a FSM reset and then again ... - TODO!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000707 return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000708 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000709 } else if !pACStatemachine.Is(aniStConfigDone) {
710 logger.Errorw("wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000711 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000712 return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000713 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000714 //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config)
715 onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
716 if err := pACStatemachine.Event(aEvent); err != nil {
717 logger.Errorw("AniConfigFSM: can't trigger event", log.Fields{"err": err})
718 return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID)
719 }
720 /***** AniConfigFSM event notified */
721 logger.Debugw("AniConfigFSM event notified", log.Fields{
722 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent})
723 return nil
mpagenko3dbcdd22020-07-22 07:38:45 +0000724 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000725 logger.Errorw("AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
726 // maybe try a FSM reset and then again ... - TODO!!!
727 return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID)
mpagenkoaf801632020-07-03 10:00:42 +0000728}
mpagenkodff5dda2020-08-28 11:52:01 +0000729
Girish Gowdra041dcb32020-11-16 16:54:30 -0800730// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
731func (onuTP *onuUniTechProf) clearAniSideConfig(aUniID uint8, aTpID uint8) {
mpagenko01e726e2020-10-23 09:45:29 +0000732 logger.Debugw("removing TpIndication and PonAniConfig data", log.Fields{
733 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800734 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
735
736 onuTP.mutexTPState.Lock()
737 defer onuTP.mutexTPState.Unlock()
738 delete(onuTP.mapUniTpIndication, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000739 //delete on the PonAniConfig map of this UNI should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800740 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000741}
742
mpagenkodff5dda2020-08-28 11:52:01 +0000743// setConfigDone sets the requested techProfile config state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800744func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
745 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
746 onuTP.mutexTPState.Lock()
747 defer onuTP.mutexTPState.Unlock()
748 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
749 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000750 } //else: the state is just ignored (does not exist)
751}
752
753// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
Girish Gowdra041dcb32020-11-16 16:54:30 -0800754func (onuTP *onuUniTechProf) getTechProfileDone(aUniID uint8, aTpID uint8) bool {
755 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
756 onuTP.mutexTPState.Lock()
757 defer onuTP.mutexTPState.Unlock()
758 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
759 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
760 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
mpagenko2418ab02020-11-12 12:58:06 +0000761 logger.Debugw("TechProfile not relevant for requested flow config - waiting on delete",
762 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
763 return false //still waiting for removal of this techProfile first
764 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800765 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000766 }
767 }
768 //for all other constellations indicate false = Config not done
769 return false
770}
mpagenko2418ab02020-11-12 12:58:06 +0000771
772// setProfileToDelete sets the requested techProfile toDelete state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800773func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
774 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
775 onuTP.mutexTPState.Lock()
776 defer onuTP.mutexTPState.Unlock()
777 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
778 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000779 } //else: the state is just ignored (does not exist)
780}