blob: af0fdbeec4b4db5ad07723acefedca88bc53882f [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"
ozgecanetsia4b232302020-11-11 10:58:10 +030025 "strconv"
mpagenko3dbcdd22020-07-22 07:38:45 +000026 "strings"
mpagenkoaf801632020-07-03 10:00:42 +000027 "sync"
28
dbainbri4d3a0dc2020-12-02 00:33:42 +000029 "github.com/opencord/voltha-lib-go/v4/pkg/db"
30 "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore"
31 "github.com/opencord/voltha-lib-go/v4/pkg/log"
32 tp "github.com/opencord/voltha-lib-go/v4/pkg/techprofile"
mpagenkoaf801632020-07-03 10:00:42 +000033)
34
Matteo Scandolof1f39a72020-11-24 12:08:11 -080035const cBasePathTechProfileKVStore = "%s/technology_profiles"
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000036
37//definitions for TechProfileProcessing - copied from OltAdapter:openolt_flowmgr.go
38// could perhaps be defined more globally
39const (
Himani Chawla6d2ae152020-09-02 13:11:20 +053040 // binaryStringPrefix is binary string prefix
41 binaryStringPrefix = "0b"
42 // binaryBit1 is binary bit 1 expressed as a character
43 //binaryBit1 = '1'
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000044)
mpagenkoaf801632020-07-03 10:00:42 +000045
46type resourceEntry int
47
48const (
49 cResourceGemPort resourceEntry = 1
50 cResourceTcont resourceEntry = 2
51)
52
mpagenko3dbcdd22020-07-22 07:38:45 +000053type tTechProfileIndication struct {
mpagenkodff5dda2020-08-28 11:52:01 +000054 techProfileType string
Girish Gowdra041dcb32020-11-16 16:54:30 -080055 techProfileID uint8
mpagenkodff5dda2020-08-28 11:52:01 +000056 techProfileConfigDone bool
mpagenko2418ab02020-11-12 12:58:06 +000057 techProfileToDelete bool
mpagenko3dbcdd22020-07-22 07:38:45 +000058}
59
60type tcontParamStruct struct {
61 allocID uint16
62 schedPolicy uint8
63}
64type gemPortParamStruct struct {
Himani Chawla4d908332020-08-31 12:30:20 +053065 //ponOmciCC bool
mpagenko3dbcdd22020-07-22 07:38:45 +000066 gemPortID uint16
67 direction uint8
68 gemPortEncState uint8
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000069 prioQueueIndex uint8
70 pbitString string
mpagenko3dbcdd22020-07-22 07:38:45 +000071 discardPolicy string
Himani Chawla4d908332020-08-31 12:30:20 +053072 //could also be a queue specific parameter, not used that way here
73 //maxQueueSize uint16
mpagenko3dbcdd22020-07-22 07:38:45 +000074 queueSchedPolicy string
75 queueWeight uint8
Himani Chawla1c136902020-12-10 16:30:59 +053076 removeGemID uint16
ozgecanetsia4b232302020-11-11 10:58:10 +030077 isMulticast bool
78 //TODO check if this has any value/difference from gemPortId
79 multicastGemPortID uint16
80 staticACL string
81 dynamicACL string
mpagenko3dbcdd22020-07-22 07:38:45 +000082}
83
84//refers to one tcont and its properties and all assigned GemPorts and their properties
85type tcontGemList struct {
86 tcontParams tcontParamStruct
87 mapGemPortParams map[uint16]*gemPortParamStruct
88}
89
Girish Gowdra041dcb32020-11-16 16:54:30 -080090// refers a unique combination of uniID and tpID for a given ONU.
91type uniTP struct {
92 uniID uint8
93 tpID uint8
94}
mpagenko3dbcdd22020-07-22 07:38:45 +000095
Himani Chawla6d2ae152020-09-02 13:11:20 +053096//onuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU
97type onuUniTechProf struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053098 baseDeviceHandler *deviceHandler
mpagenko01e726e2020-10-23 09:45:29 +000099 deviceID string
mpagenkodff5dda2020-08-28 11:52:01 +0000100 tpProcMutex sync.RWMutex
mpagenkodff5dda2020-08-28 11:52:01 +0000101 techProfileKVStore *db.Backend
mpagenkodff5dda2020-08-28 11:52:01 +0000102 chTpConfigProcessingStep chan uint8
Girish Gowdra041dcb32020-11-16 16:54:30 -0800103 mapUniTpIndication map[uniTP]*tTechProfileIndication //use pointer values to ease assignments to the map
104 mapPonAniConfig map[uniTP]*tcontGemList //per UNI: use pointer values to ease assignments to the map
105 pAniConfigFsm map[uniTP]*uniPonAniConfigFsm
106 procResult map[uniTP]error //error indication of processing
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800107 mutexTPState sync.RWMutex
Girish Gowdra041dcb32020-11-16 16:54:30 -0800108 tpProfileExists map[uniTP]bool
mpagenko73143992021-04-09 15:17:10 +0000109 tpProfileResetting map[uniTP]bool
mpagenko8b07c1b2020-11-26 10:36:31 +0000110 mapRemoveGemEntry map[uniTP]*gemPortParamStruct //per UNI: pointer to GemEntry to be removed
mpagenkoaf801632020-07-03 10:00:42 +0000111}
112
Himani Chawla6d2ae152020-09-02 13:11:20 +0530113//newOnuUniTechProf returns the instance of a OnuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000114//(one instance per ONU/deviceHandler for all possible UNI's)
mpagenko01e726e2020-10-23 09:45:29 +0000115func newOnuUniTechProf(ctx context.Context, aDeviceHandler *deviceHandler) *onuUniTechProf {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000116 logger.Debugw(ctx, "init-OnuUniTechProf", log.Fields{"device-id": aDeviceHandler.deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530117 var onuTP onuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000118 onuTP.baseDeviceHandler = aDeviceHandler
mpagenko01e726e2020-10-23 09:45:29 +0000119 onuTP.deviceID = aDeviceHandler.deviceID
mpagenkodff5dda2020-08-28 11:52:01 +0000120 onuTP.chTpConfigProcessingStep = make(chan uint8)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800121 onuTP.mapUniTpIndication = make(map[uniTP]*tTechProfileIndication)
122 onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList)
123 onuTP.procResult = make(map[uniTP]error)
124 onuTP.tpProfileExists = make(map[uniTP]bool)
mpagenko73143992021-04-09 15:17:10 +0000125 onuTP.tpProfileResetting = make(map[uniTP]bool)
mpagenko8b07c1b2020-11-26 10:36:31 +0000126 onuTP.mapRemoveGemEntry = make(map[uniTP]*gemPortParamStruct)
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800127 baseKvStorePath := fmt.Sprintf(cBasePathTechProfileKVStore, aDeviceHandler.pOpenOnuAc.cm.Backend.PathPrefix)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000128 onuTP.techProfileKVStore = aDeviceHandler.setBackend(ctx, baseKvStorePath)
mpagenkoaf801632020-07-03 10:00:42 +0000129 if onuTP.techProfileKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000130 logger.Errorw(ctx, "Can't access techProfileKVStore - no backend connection to service",
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800131 log.Fields{"device-id": aDeviceHandler.deviceID, "service": baseKvStorePath})
mpagenkoaf801632020-07-03 10:00:42 +0000132 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000133
mpagenkoaf801632020-07-03 10:00:42 +0000134 return &onuTP
135}
136
137// lockTpProcMutex locks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530138func (onuTP *onuUniTechProf) lockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000139 onuTP.tpProcMutex.Lock()
140}
141
142// unlockTpProcMutex unlocks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530143func (onuTP *onuUniTechProf) unlockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000144 onuTP.tpProcMutex.Unlock()
145}
146
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000147// resetTpProcessingErrorIndication resets the internal error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000148// need to be called before evaluation of any subsequent processing (given by waitForTpCompletion())
Girish Gowdra041dcb32020-11-16 16:54:30 -0800149func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) {
mpagenko73143992021-04-09 15:17:10 +0000150 onuTP.mutexTPState.Lock()
151 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800152 onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000153}
154
Girish Gowdra041dcb32020-11-16 16:54:30 -0800155func (onuTP *onuUniTechProf) getTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error {
mpagenko73143992021-04-09 15:17:10 +0000156 onuTP.mutexTPState.RLock()
157 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800158 return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}]
mpagenko3dbcdd22020-07-22 07:38:45 +0000159}
160
mpagenko8b07c1b2020-11-26 10:36:31 +0000161// configureUniTp checks existing tp resources to configure and starts the corresponding OMCI configuation of the UNI port
mpagenko3dbcdd22020-07-22 07:38:45 +0000162// all possibly blocking processing must be run in background to allow for deadline supervision!
163// but take care on sequential background processing when needed (logical dependencies)
Himani Chawla4d908332020-08-31 12:30:20 +0530164// use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization
Himani Chawla6d2ae152020-09-02 13:11:20 +0530165func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context,
mpagenkodff5dda2020-08-28 11:52:01 +0000166 aUniID uint8, aPathString string, wg *sync.WaitGroup) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000167 defer wg.Done() //always decrement the waitGroup on return
dbainbri4d3a0dc2020-12-02 00:33:42 +0000168 logger.Debugw(ctx, "configure the Uni according to TpPath", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000169 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800170 tpID, err := GetTpIDFromTpPath(aPathString)
171 uniTpKey := uniTP{uniID: aUniID, tpID: tpID}
172 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000173 logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800174 return
175 }
mpagenkoaf801632020-07-03 10:00:42 +0000176 if onuTP.techProfileKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000177 logger.Errorw(ctx, "techProfileKVStore not set - abort",
mpagenko8b07c1b2020-11-26 10:36:31 +0000178 log.Fields{"device-id": onuTP.deviceID})
mpagenko73143992021-04-09 15:17:10 +0000179 onuTP.mutexTPState.Lock()
180 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800181 onuTP.procResult[uniTpKey] = errors.New("techProfile config aborted: techProfileKVStore not set")
mpagenkoaf801632020-07-03 10:00:42 +0000182 return
183 }
184
mpagenko3dbcdd22020-07-22 07:38:45 +0000185 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530186 var pCurrentUniPort *onuUniPort
mpagenko3dbcdd22020-07-22 07:38:45 +0000187 for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap {
188 // only if this port is validated for operState transfer
Girish Gowdra041dcb32020-11-16 16:54:30 -0800189 if uniPort.uniID == aUniID {
mpagenko3dbcdd22020-07-22 07:38:45 +0000190 pCurrentUniPort = uniPort
191 break //found - end search loop
192 }
193 }
194 if pCurrentUniPort == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000195 logger.Errorw(ctx, "TechProfile configuration aborted: requested uniID not found in PortDB",
mpagenko73143992021-04-09 15:17:10 +0000196 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
197 onuTP.mutexTPState.Lock()
198 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800199 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200200 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000201 return
202 }
mpagenkoaf801632020-07-03 10:00:42 +0000203
mpagenko73143992021-04-09 15:17:10 +0000204 if onuTP.getProfileResetting(uniTpKey) {
205 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
206 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
207 onuTP.mutexTPState.Lock()
208 defer onuTP.mutexTPState.Unlock()
209 onuTP.procResult[uniTpKey] = fmt.Errorf(
210 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
211 aUniID, onuTP.deviceID)
212 return
213 }
mpagenkodff5dda2020-08-28 11:52:01 +0000214 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
mpagenkoaf801632020-07-03 10:00:42 +0000215
mpagenko3dbcdd22020-07-22 07:38:45 +0000216 //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called
217 // in case the KVPath has changed for the given UNI,
218 // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
219 // (ANI) configuration of this port has to be removed first
220 // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
221 // existence of configuration can be detected based on tp stored TCONT's
Andrea Campanella6515c582020-10-05 11:25:00 +0200222 //TODO:
mpagenko3dbcdd22020-07-22 07:38:45 +0000223 /* if tcontMap not empty {
224 go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000225 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000226 //timeout or error detected
227 return
228 }
229 clear tcontMap
230 }
231
232 processingStep++
233 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800234 go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000235 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000236 //timeout or error detected
mpagenko73143992021-04-09 15:17:10 +0000237 onuTP.mutexTPState.RLock()
238 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800239 if onuTP.tpProfileExists[uniTpKey] {
mpagenko01e726e2020-10-23 09:45:29 +0000240 //ignore the internal error in case the new profile is already configured
241 // and abort the processing here
242 return
243 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000244 logger.Errorw(ctx, "tech-profile related configuration aborted on read",
mpagenko01e726e2020-10-23 09:45:29 +0000245 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000246 onuTP.mutexTPState.Lock()
247 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800248 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200249 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000250 return
251 }
mpagenko73143992021-04-09 15:17:10 +0000252 if onuTP.getProfileResetting(uniTpKey) {
253 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
254 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
255 onuTP.mutexTPState.Lock()
256 defer onuTP.mutexTPState.Unlock()
257 onuTP.procResult[uniTpKey] = fmt.Errorf(
258 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
259 aUniID, onuTP.deviceID)
260 return
261 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000262 processingStep++
Girish Gowdra041dcb32020-11-16 16:54:30 -0800263
mpagenko73143992021-04-09 15:17:10 +0000264 //ensure read protection for access to mapPonAniConfig
265 onuTP.mutexTPState.RLock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800266 valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey]
mpagenko73143992021-04-09 15:17:10 +0000267 onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800268 if existPA {
269 if valuePA != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000270 //Config data for this uni and and at least TCont Index 0 exist
mpagenko8b07c1b2020-11-26 10:36:31 +0000271 if err := onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000272 logger.Errorw(ctx, "tech-profile related FSM could not be started",
mpagenko8b07c1b2020-11-26 10:36:31 +0000273 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000274 onuTP.mutexTPState.Lock()
275 defer onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000276 onuTP.procResult[uniTpKey] = err
277 return
278 }
mpagenkodff5dda2020-08-28 11:52:01 +0000279 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000280 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
281 logger.Warnw(ctx, "tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000282 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800283
mpagenko73143992021-04-09 15:17:10 +0000284 onuTP.mutexTPState.Lock()
285 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800286 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200287 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530288 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000289 //which requires to reset it to allow for new usage, e.g. also on a different UNI
290 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000291 if _, ok := onuTP.pAniConfigFsm[uniTpKey]; ok {
292 _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset)
293 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000294 return
mpagenkoaf801632020-07-03 10:00:42 +0000295 }
296 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000297 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000298 logger.Errorw(ctx, "no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000299 "device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000300 onuTP.mutexTPState.Lock()
301 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800302 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 +0200303 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000304 return
mpagenkoaf801632020-07-03 10:00:42 +0000305 }
306 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000307 logger.Errorw(ctx, "no PonAni data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000308 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800309
mpagenko73143992021-04-09 15:17:10 +0000310 onuTP.mutexTPState.Lock()
311 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800312 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 +0200313 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000314 return
mpagenkoaf801632020-07-03 10:00:42 +0000315 }
316}
317
mpagenko3dbcdd22020-07-22 07:38:45 +0000318/* internal methods *********************/
ozgecanetsia4b232302020-11-11 10:58:10 +0300319// nolint: gocyclo
Himani Chawla6d2ae152020-09-02 13:11:20 +0530320func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile(
Girish Gowdra041dcb32020-11-16 16:54:30 -0800321 ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000322 var tpInst tp.TechProfile
323
324 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
325 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
326 subStringSlice := strings.Split(aPathString, "/")
327 if len(subStringSlice) <= 2 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000328 logger.Errorw(ctx, "invalid path name format",
mpagenko3dbcdd22020-07-22 07:38:45 +0000329 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000330 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000331 return
332 }
333
mpagenko73143992021-04-09 15:17:10 +0000334 //ensure write protection for access to used maps
335 onuTP.mutexTPState.Lock()
336 defer onuTP.mutexTPState.Unlock()
337
338 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
339 onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false
340
mpagenko3dbcdd22020-07-22 07:38:45 +0000341 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000342 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
343 // then we throw a warning, set an internal error and abort with error,
344 // which is later re-defined to success response to OLT adapter
345 // if TPId has changed, current data is removed (note that the ONU config state may be
346 // ambivalent in such a case)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800347 if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000348 logger.Warnw(ctx, "Some active profile entry at reading new TechProfile",
mpagenko3dbcdd22020-07-22 07:38:45 +0000349 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800350 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
351 if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID {
mpagenko01e726e2020-10-23 09:45:29 +0000352 // ProfId not changed - assume profile to be still the same
353 // anyway this should not appear after full support of profile (Gem/TCont) removal
dbainbri4d3a0dc2020-12-02 00:33:42 +0000354 logger.Warnw(ctx, "New TechProfile already exists - aborting configuration",
mpagenko01e726e2020-10-23 09:45:29 +0000355 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800356 onuTP.tpProfileExists[uniTPKey] = true
mpagenko01e726e2020-10-23 09:45:29 +0000357 onuTP.chTpConfigProcessingStep <- 0 //error indication
358 return
359 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000360 //delete on the mapUniTpIndication map not needed, just overwritten later
361 //delete on the PonAniConfig map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800362 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenko3dbcdd22020-07-22 07:38:45 +0000363 } else {
364 // this is normal processing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800365 onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
mpagenko3dbcdd22020-07-22 07:38:45 +0000366 }
367
Girish Gowdra041dcb32020-11-16 16:54:30 -0800368 onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000369 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
Girish Gowdra041dcb32020-11-16 16:54:30 -0800370 onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID
371 onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false
372 onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000373 logger.Debugw(ctx, "tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000374 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800375 "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType,
376 "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000377
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000378 Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString)
mpagenko3dbcdd22020-07-22 07:38:45 +0000379 if err == nil {
380 if Value != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000381 logger.Debugw(ctx, "tech-profile read",
mpagenko3dbcdd22020-07-22 07:38:45 +0000382 log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID})
383 tpTmpBytes, _ := kvstore.ToByte(Value.Value)
384
385 if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000386 logger.Errorw(ctx, "TechProf - Failed to unmarshal tech-profile into tpInst",
mpagenko3dbcdd22020-07-22 07:38:45 +0000387 log.Fields{"error": err, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000388 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000389 return
390 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000391 logger.Debugw(ctx, "TechProf - tpInst", log.Fields{"tpInst": tpInst})
mpagenko3dbcdd22020-07-22 07:38:45 +0000392 // access examples
dbainbri4d3a0dc2020-12-02 00:33:42 +0000393 logger.Debugw(ctx, "TechProf content", log.Fields{"Name": tpInst.Name,
mpagenko3dbcdd22020-07-22 07:38:45 +0000394 "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize,
395 "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
396 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000397 logger.Errorw(ctx, "No tech-profile found",
mpagenko3dbcdd22020-07-22 07:38:45 +0000398 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000399 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000400 return
401 }
402 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000403 logger.Errorw(ctx, "kvstore-get failed for path",
mpagenko3dbcdd22020-07-22 07:38:45 +0000404 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000405 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000406 return
407 }
408
mpagenko01e726e2020-10-23 09:45:29 +0000409 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000410 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800411 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000412
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000413 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000414 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra041dcb32020-11-16 16:54:30 -0800415 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID)
Himani Chawla4d908332020-08-31 12:30:20 +0530416 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000417 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
418 if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800419 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000420 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000421 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800422 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000423 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000424 loNumGemPorts := tpInst.NumGemPorts
425 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000426 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000427 if uint32(pos) == loNumGemPorts {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000428 logger.Debugw(ctx, "PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
mpagenko1cc3cb42020-07-27 15:24:38 +0000429 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000430 break
431 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000432 if pos == 0 {
433 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
434 loGemPortRead = true
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000435 }
Himani Chawla1c136902020-12-10 16:30:59 +0530436 //for all GemPorts we need to extend the mapGemPortParams
437 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)] = &gemPortParamStruct{}
438
439 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortID =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000440 uint16(content.GemportID)
441 //direction can be correlated later with Downstream list,
442 // for now just assume bidirectional (upstream never exists alone)
Himani Chawla1c136902020-12-10 16:30:59 +0530443 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000444 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
ozgecanetsia4b232302020-11-11 10:58:10 +0300445 if content.PriorityQueue > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000446 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000447 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue})
448 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800449 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000450 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000451 return
452 }
Himani Chawla1c136902020-12-10 16:30:59 +0530453 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].prioQueueIndex =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000454 uint8(content.PriorityQueue)
Himani Chawla1c136902020-12-10 16:30:59 +0530455 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530456 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000457 if content.AesEncryption == "True" {
Himani Chawla1c136902020-12-10 16:30:59 +0530458 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000459 } else {
Himani Chawla1c136902020-12-10 16:30:59 +0530460 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000461 }
Himani Chawla1c136902020-12-10 16:30:59 +0530462 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].discardPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000463 content.DiscardPolicy
Himani Chawla1c136902020-12-10 16:30:59 +0530464 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].queueSchedPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000465 content.SchedulingPolicy
mpagenko3dbcdd22020-07-22 07:38:45 +0000466 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Himani Chawla1c136902020-12-10 16:30:59 +0530467 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000468 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000469 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300470
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300471 for _, downstreamContent := range tpInst.DownstreamGemPortAttributeList {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000472 logger.Debugw(ctx, "Operating on Downstream Gem Port", log.Fields{"downstream-gem": downstreamContent})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300473 //Commenting this out due to faliure, needs investigation
474 //if uint32(pos) == loNumGemPorts {
475 // logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
476 // log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
477 // break
478 //}
479 isMulticast := false
ozgecanetsia4b232302020-11-11 10:58:10 +0300480 //Flag is defined as string in the TP in voltha-lib-go, parsing it from string
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300481 if downstreamContent.IsMulticast != "" {
482 isMulticast, err = strconv.ParseBool(downstreamContent.IsMulticast)
483 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000484 logger.Errorw(ctx, "multicast-error-config-unknown-flag-in-technology-profile",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300485 log.Fields{"UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "error": err})
486 continue
487 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300488 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000489 logger.Infow(ctx, "Gem Port is multicast", log.Fields{"isMulticast": isMulticast})
ozgecanetsia4b232302020-11-11 10:58:10 +0300490 if isMulticast {
491 mcastGemID := uint16(downstreamContent.McastGemID)
492 _, existing := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID]
493 if existing {
494 //GEM port was previously configured, avoid setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000495 logger.Errorw(ctx, "multicast-error-config-existing-gem-port-config", log.Fields{"UniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300496 "downstream-gem": downstreamContent, "key": mcastGemID})
497 continue
498 } else {
499 //GEM port is not configured, setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000500 logger.Infow(ctx, "creating-multicast-gem-port", log.Fields{"uniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300501 "gemPortId": mcastGemID, "key": mcastGemID})
502
503 //for all further GemPorts we need to extend the mapGemPortParams
504 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID] = &gemPortParamStruct{}
505
506 //Separate McastGemId is derived from OMCI-lib-go, if not needed first needs to be removed there.
507 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortID = mcastGemID
508 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].direction = 2 // for ANI to UNI as defined in G.988
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300509
510 if downstreamContent.AesEncryption == "True" {
511 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 1
512 } else {
513 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 0
514 }
515
516 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
ozgecanetsia4b232302020-11-11 10:58:10 +0300517 if downstreamContent.PriorityQueue > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000518 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300519 log.Fields{"device-id": onuTP.deviceID, "index": mcastGemID, "PrioQueue": downstreamContent.PriorityQueue})
520 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
521 delete(onuTP.mapPonAniConfig, uniTPKey)
522 onuTP.chTpConfigProcessingStep <- 0 //error indication
523 return
ozgecanetsia4b232302020-11-11 10:58:10 +0300524 }
525 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].prioQueueIndex =
526 uint8(downstreamContent.PriorityQueue)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300527 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].pbitString =
528 strings.TrimPrefix(downstreamContent.PbitMap, binaryStringPrefix)
529
530 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].discardPolicy =
531 downstreamContent.DiscardPolicy
532 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueSchedPolicy =
533 downstreamContent.SchedulingPolicy
534 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
535 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueWeight =
536 uint8(downstreamContent.Weight)
537
ozgecanetsia4b232302020-11-11 10:58:10 +0300538 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].isMulticast = isMulticast
539 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].multicastGemPortID =
540 uint16(downstreamContent.McastGemID)
541 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].staticACL = downstreamContent.SControlList
542 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].dynamicACL = downstreamContent.DControlList
543 }
544 }
545 }
546
Himani Chawla4d908332020-08-31 12:30:20 +0530547 if !loGemPortRead {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000548 logger.Errorw(ctx, "PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000549 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000550 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800551 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000552 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000553 return
554 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000555 //logger does not simply output the given structures, just give some example debug values
dbainbri4d3a0dc2020-12-02 00:33:42 +0000556 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000557 "device-id": onuTP.deviceID, "uni-id": aUniID,
558 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
Himani Chawla1c136902020-12-10 16:30:59 +0530559 for gemPortID, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000560 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530561 "GemPort": gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000562 "QueueScheduling": gemEntry.queueSchedPolicy})
563 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000564
mpagenkodff5dda2020-08-28 11:52:01 +0000565 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000566}
567
Himani Chawla6d2ae152020-09-02 13:11:20 +0530568func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
mpagenko8b07c1b2020-11-26 10:36:31 +0000569 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000570
571 //OMCI transfer of ANI data acc. to mapPonAniConfig
572 // also the FSM's are running in background,
mpagenko8b07c1b2020-11-26 10:36:31 +0000573 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800574 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko3dbcdd22020-07-22 07:38:45 +0000575 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000576 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800577 } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000578 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000579 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000580 //AniConfigFsm already init
dbainbri4d3a0dc2020-12-02 00:33:42 +0000581 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000582}
583
584// deleteTpResource removes Resources from the ONU's specified Uni
mpagenko73143992021-04-09 15:17:10 +0000585// nolint: gocyclo
mpagenko8b07c1b2020-11-26 10:36:31 +0000586func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context,
587 aUniID uint8, aTpID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
588 wg *sync.WaitGroup) {
589 defer wg.Done()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000590 logger.Debugw(ctx, "will remove TP resources from ONU's UNI", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000591 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "Resource": aResource})
592 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
593
mpagenko7d6bb022021-03-11 15:07:55 +0000594 bDeviceProcStatusUpdate := true
mpagenko8b07c1b2020-11-26 10:36:31 +0000595 if cResourceGemPort == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000596 logger.Debugw(ctx, "remove GemPort from the list of existing ones of the TP", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000597 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID})
598
mpagenko73143992021-04-09 15:17:10 +0000599 //ensure read protection for access to mapPonAniConfig
600 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000601 // check if the requested GemPort exists in the DB, indicate it to the FSM
602 // store locally to remove it from DB later on success
603 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
604 if pLocAniConfigOnUni == nil {
mpagenko73143992021-04-09 15:17:10 +0000605 onuTP.mutexTPState.RUnlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000606 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000607 logger.Debugw(ctx, "AniConfig or GemEntry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000608 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
609 return
610 }
mpagenko73143992021-04-09 15:17:10 +0000611 onuTP.mutexTPState.RUnlock()
612
Himani Chawla1c136902020-12-10 16:30:59 +0530613 for gemPortID, gemEntry := range pLocAniConfigOnUni.mapGemPortParams {
614 if gemPortID == uint16(aEntryID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000615 //GemEntry to be deleted found
Himani Chawla1c136902020-12-10 16:30:59 +0530616 gemEntry.removeGemID = gemPortID //store the index for later removal
617 onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemPortID]
dbainbri4d3a0dc2020-12-02 00:33:42 +0000618 logger.Debugw(ctx, "Remove-GemEntry stored", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530619 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000620 break //abort loop, always only one GemPort to remove
621 }
622 }
623 if onuTP.mapRemoveGemEntry[uniTPKey] == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000624 logger.Errorw(ctx, "GemPort removal aborted - GemPort not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000625 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
626 /* Do not set some error indication to the outside system interface on delete
627 assume there is nothing to be deleted internally and hope a new config request will recover the situation
628 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s",
629 aEntryID, aUniID, onuTP.deviceID)
630 */
631 return
632 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000633 if onuTP.baseDeviceHandler.isReadyForOmciConfig() {
mpagenko8b07c1b2020-11-26 10:36:31 +0000634 // check that the TpConfigRequest was done before
635 // -> that is implicitly done using the AniConfigFsm,
636 // which must be in the according state to remove something
mpagenko8b07c1b2020-11-26 10:36:31 +0000637 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000638 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000639 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
640 /* Do not set some error indication to the outside system interface on delete (see above)
641 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s",
642 aUniID, onuTP.deviceID)
643 */
644 //if the FSM is not valid, also TP related remove data should not be valid:
645 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000646 //ensure write protection for access to mapPonAniConfig
647 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530648 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000649 // remove the removeEntry
650 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000651 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000652 return
653 }
654 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000655 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000656 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
657 /* Do not set some error indication to the outside system interface on delete (see above)
658 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid",
659 aUniID, onuTP.deviceID, aTpID)
660 */
661 //if the FSM is not valid, also TP related remove data should not be valid:
662 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000663 //ensure write protection for access to mapPonAniConfig
664 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530665 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000666 // remove the removeEntry
667 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000668 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000669 return
670 }
mpagenko73143992021-04-09 15:17:10 +0000671 if onuTP.getProfileResetting(uniTPKey) {
672 logger.Debugw(ctx, "aborting GemRemoval on FSM, reset requested in parallel", log.Fields{
673 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
674 //ensure write protection for access to mapPonAniConfig
675 onuTP.mutexTPState.Lock()
676 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
677 // remove the removeEntry
678 delete(onuTP.mapRemoveGemEntry, uniTPKey)
679 onuTP.mutexTPState.Unlock()
680 return
681 }
682 // initiate OMCI GemPort related removal
683 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
684 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000685 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemGemiw, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000686 //even if the FSM invocation did not work we don't indicate a problem within procResult
687 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
688 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
689 return
690 }
691 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000692 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
693 logger.Warnw(ctx, "GemPort removal aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000694 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
695 //even if the FSM delete execution did not work we don't indicate a problem within procResult
696 //we should never respond to delete with error ...
697 //this issue here means that the AniConfigFsm has not finished successfully
698 //which requires to reset it to allow for new usage, e.g. also on a different UNI
699 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000700 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok {
701 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
702 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000703 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
704 return
705 }
706 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000707 //if we can't do the OMCI processing we also suppress the ProcStatusUpdate
708 //this is needed as in the device-down case where all FSM's are getting reset and internal data gets cleared
709 //as a consequence a possible remove-flow does not see any dependency on the TechProfile anymore and is executed (pro forma) directly
710 //a later TechProfile removal would cause the device-reason to be updated to 'techProfile-delete-success' which is not the expected state
711 // and anyway is no real useful information at that stage
712 bDeviceProcStatusUpdate = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000713 logger.Debugw(ctx, "uniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000714 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000715 }
716 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000717 //ensure write protection for access to mapPonAniConfig
718 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530719 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000720 // remove the removeEntry
721 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000722 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000723 // deviceHandler StatusEvent (reason update) (see end of function) is only generated in case some element really was removed
724 } else { //if cResourceTcont == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000725 logger.Debugw(ctx, "reset TCont with AllocId", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000726 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID})
727
mpagenko73143992021-04-09 15:17:10 +0000728 //ensure read protection for access to mapPonAniConfig
729 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000730 // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM
731 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
732 if pLocAniConfigOnUni == nil {
733 // No relevant entry exists anymore - acknowledge success
mpagenko73143992021-04-09 15:17:10 +0000734 onuTP.mutexTPState.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000735 logger.Debugw(ctx, "AniConfig or TCont entry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000736 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
737 return
738 }
mpagenko73143992021-04-09 15:17:10 +0000739 onuTP.mutexTPState.RUnlock()
740
mpagenko8b07c1b2020-11-26 10:36:31 +0000741 if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000742 logger.Errorw(ctx, "TCont removal aborted - indicated AllocId not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000743 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID})
744 /* Do not set some error indication to the outside system interface on delete
745 assume there is nothing to be deleted internally and hope a new config request will recover the situation
746 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s",
747 aEntryID, aUniID, onuTP.deviceID)
748 */
749 return
750 }
751 //T-Cont to be reset found
dbainbri4d3a0dc2020-12-02 00:33:42 +0000752 logger.Debugw(ctx, "Reset-T-Cont AllocId found - valid", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000753 "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID})
754 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000755 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000756 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
757 /* Do not set some error indication to the outside system interface on delete (see above)
758 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s",
759 aUniID, onuTP.deviceID)
760 */
761 //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000762 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000763 return
764 }
765 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000766 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000767 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
768 //even if the FSM invocation did not work we don't indicate a problem within procResult
769 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
770 //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000771 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000772 return
773 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000774 if onuTP.baseDeviceHandler.isReadyForOmciConfig() {
mpagenko8b07c1b2020-11-26 10:36:31 +0000775 // check that the TpConfigRequest was done before
776 // -> that is implicitly done using the AniConfigFsm,
777 // which must be in the according state to remove something
mpagenko73143992021-04-09 15:17:10 +0000778 if onuTP.getProfileResetting(uniTPKey) {
779 logger.Debugw(ctx, "aborting TCont removal on FSM, reset requested in parallel", log.Fields{
780 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
781 return
782 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000783 // initiate OMCI TCont related cleanup
784 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
785 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000786 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemTcontPath, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000787 //even if the FSM invocation did not work we don't indicate a problem within procResult
788 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
789 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
790 return
791 }
792 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000793 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
794 logger.Warnw(ctx, "TCont cleanup aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000795 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
796 //even if the FSM delete execution did not work we don't indicate a problem within procResult
797 //we should never respond to delete with error ...
798 //this issue here means that the AniConfigFsm has not finished successfully
799 //which requires to reset it to allow for new usage, e.g. also on a different UNI
800 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000801 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok {
802 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
803 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000804 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
805 return
806 }
807 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000808 //see gemPort comments
809 bDeviceProcStatusUpdate = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000810 logger.Debugw(ctx, "uniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000811 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000812 }
813 //clear the internal store profile data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000814 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000815 // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created
816 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
817 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
818 }
mpagenko7d6bb022021-03-11 15:07:55 +0000819 if bDeviceProcStatusUpdate {
820 // generate deviceHandler StatusEvent in case the FSM was not invoked and OMCI processing not locked due to device state
821 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(ctx, OmciAniResourceRemoved)
822 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000823}
824
Himani Chawla6d2ae152020-09-02 13:11:20 +0530825func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000826 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000827 select {
828 case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000829 logger.Warnw(ctx, "processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000830 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000831 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000832 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000833 if rxStep == aProcessingStep {
834 return true
835 }
836 //all other values are not accepted - including 0 for error indication
dbainbri4d3a0dc2020-12-02 00:33:42 +0000837 logger.Warnw(ctx, "Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000838 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000839 "wantedStep": aProcessingStep, "haveStep": rxStep})
840 return false
841 }
842}
843
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000844// createAniConfigFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000845func (onuTP *onuUniTechProf) createAniConfigFsm(ctx context.Context, aUniID uint8, aTpID uint8,
mpagenko8b07c1b2020-11-26 10:36:31 +0000846 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000847 logger.Debugw(ctx, "createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000848 chAniConfigFsm := make(chan Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800849 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000850 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(ctx, true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000851 if pDevEntry == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000852 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000853 return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000854 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000855 pAniCfgFsm := newUniPonAniConfigFsm(ctx, pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800856 pDevEntry.pOnuDB, aTpID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000857 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko8b07c1b2020-11-26 10:36:31 +0000858 if pAniCfgFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000859 logger.Errorw(ctx, "AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000860 return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000861 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000862 if onuTP.pAniConfigFsm == nil {
863 onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800864 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000865 onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm
dbainbri4d3a0dc2020-12-02 00:33:42 +0000866 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000867}
868
mpagenko3dbcdd22020-07-22 07:38:45 +0000869// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000870func (onuTP *onuUniTechProf) runAniConfigFsm(ctx context.Context, aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000871 /* Uni related ANI config procedure -
872 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
873 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800874 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
875
876 pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000877 if pACStatemachine != nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000878 if aEvent == aniEvStart {
879 if !pACStatemachine.Is(aniStDisabled) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000880 logger.Errorw(ctx, "wrong state of AniConfigFSM to start - want: Disabled", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000881 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000882 // maybe try a FSM reset and then again ... - TODO!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000883 return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000884 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000885 } else if !pACStatemachine.Is(aniStConfigDone) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000886 logger.Errorw(ctx, "wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000887 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000888 return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000889 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000890 //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config)
891 onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
892 if err := pACStatemachine.Event(aEvent); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000893 logger.Errorw(ctx, "AniConfigFSM: can't trigger event", log.Fields{"err": err})
mpagenko8b07c1b2020-11-26 10:36:31 +0000894 return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID)
895 }
896 /***** AniConfigFSM event notified */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000897 logger.Debugw(ctx, "AniConfigFSM event notified", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000898 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent})
899 return nil
mpagenko3dbcdd22020-07-22 07:38:45 +0000900 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000901 logger.Errorw(ctx, "AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000902 // maybe try a FSM reset and then again ... - TODO!!!
903 return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID)
mpagenkoaf801632020-07-03 10:00:42 +0000904}
mpagenkodff5dda2020-08-28 11:52:01 +0000905
Girish Gowdra041dcb32020-11-16 16:54:30 -0800906// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000907func (onuTP *onuUniTechProf) clearAniSideConfig(ctx context.Context, aUniID uint8, aTpID uint8) {
908 logger.Debugw(ctx, "removing TpIndication and PonAniConfig data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000909 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800910 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
911
912 onuTP.mutexTPState.Lock()
913 defer onuTP.mutexTPState.Unlock()
mpagenko73143992021-04-09 15:17:10 +0000914 //deleting a map entry should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800915 delete(onuTP.mapUniTpIndication, uniTpKey)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800916 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko73143992021-04-09 15:17:10 +0000917 delete(onuTP.procResult, uniTpKey)
918 delete(onuTP.tpProfileExists, uniTpKey)
919 delete(onuTP.tpProfileResetting, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000920}
921
mpagenkodff5dda2020-08-28 11:52:01 +0000922// setConfigDone sets the requested techProfile config state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800923func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
924 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
925 onuTP.mutexTPState.Lock()
926 defer onuTP.mutexTPState.Unlock()
927 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
928 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000929 } //else: the state is just ignored (does not exist)
930}
931
932// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
dbainbri4d3a0dc2020-12-02 00:33:42 +0000933func (onuTP *onuUniTechProf) getTechProfileDone(ctx context.Context, aUniID uint8, aTpID uint8) bool {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800934 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000935 onuTP.mutexTPState.RLock()
936 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800937 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
938 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
939 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000940 logger.Debugw(ctx, "TechProfile not relevant for requested flow config - waiting on delete",
mpagenko2418ab02020-11-12 12:58:06 +0000941 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
942 return false //still waiting for removal of this techProfile first
943 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800944 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000945 }
946 }
947 //for all other constellations indicate false = Config not done
948 return false
949}
mpagenko2418ab02020-11-12 12:58:06 +0000950
951// setProfileToDelete sets the requested techProfile toDelete state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800952func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
953 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
954 onuTP.mutexTPState.Lock()
955 defer onuTP.mutexTPState.Unlock()
956 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
957 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000958 } //else: the state is just ignored (does not exist)
959}
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300960
961// setProfileToDelete sets the requested techProfile toDelete state (if possible)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000962func (onuTP *onuUniTechProf) getMulticastGemPorts(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300963 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000964 onuTP.mutexTPState.RLock()
965 defer onuTP.mutexTPState.RUnlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300966 gemPortIds := make([]uint16, 0)
967 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
968 for _, gemPortParam := range techProfile.mapGemPortParams {
969 if gemPortParam.isMulticast {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000970 logger.Debugw(ctx, "Detected multicast gemPort", log.Fields{"device-id": onuTP.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300971 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
972 "mcastGemId": gemPortParam.multicastGemPortID})
973 gemPortIds = append(gemPortIds, gemPortParam.multicastGemPortID)
974 }
975 }
976 } //else: the state is just ignored (does not exist)
977 return gemPortIds
978}
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800979
980func (onuTP *onuUniTechProf) GetAllBidirectionalGemPortIDsForOnu() []uint16 {
981 var gemPortInstIDs []uint16
982 onuTP.mutexTPState.RLock()
983 defer onuTP.mutexTPState.RUnlock()
984 for _, tcontGemList := range onuTP.mapPonAniConfig {
985 for gemPortID, gemPortData := range tcontGemList.mapGemPortParams {
986 if gemPortData != nil && !gemPortData.isMulticast { // only if not multicast gem port
987 gemPortInstIDs = append(gemPortInstIDs, gemPortID)
988 }
989 }
990 }
991 return gemPortInstIDs
992}
mpagenko73143992021-04-09 15:17:10 +0000993
994// setProfileResetting sets/resets the indication, that a reset of the TechProfileConfig/Removal is ongoing
995func (onuTP *onuUniTechProf) setProfileResetting(ctx context.Context, aUniID uint8, aTpID uint8, aState bool) {
996 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
997 onuTP.mutexTPState.Lock()
998 defer onuTP.mutexTPState.Unlock()
999 onuTP.tpProfileResetting[uniTpKey] = aState
1000}
1001
1002// getProfileResetting returns true, if the the according indication for started reset procedure is set
1003func (onuTP *onuUniTechProf) getProfileResetting(aUniTpKey uniTP) bool {
1004 onuTP.mutexTPState.RLock()
1005 defer onuTP.mutexTPState.RUnlock()
1006 if isResetting, exist := onuTP.tpProfileResetting[aUniTpKey]; exist {
1007 return isResetting
1008 }
1009 return false
1010}