blob: 8013cb0f3eae086ab9758b0059b48c929b8c49ca [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 }
252
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000253 if onuTP.baseDeviceHandler.isSkipOnuConfigReconciling() {
254 logger.Debugw(ctx, "reconciling - skip omci-config of ANI side ", log.Fields{"uni-id": aUniID, "device-id": onuTP.deviceID})
mpagenko73143992021-04-09 15:17:10 +0000255 onuTP.mutexTPState.Lock()
256 defer onuTP.mutexTPState.Unlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000257 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
258 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = true
259 }
260 return
261 }
262
mpagenko73143992021-04-09 15:17:10 +0000263 if onuTP.getProfileResetting(uniTpKey) {
264 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
265 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
266 onuTP.mutexTPState.Lock()
267 defer onuTP.mutexTPState.Unlock()
268 onuTP.procResult[uniTpKey] = fmt.Errorf(
269 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
270 aUniID, onuTP.deviceID)
271 return
272 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000273 processingStep++
Girish Gowdra041dcb32020-11-16 16:54:30 -0800274
mpagenko73143992021-04-09 15:17:10 +0000275 //ensure read protection for access to mapPonAniConfig
276 onuTP.mutexTPState.RLock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800277 valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey]
mpagenko73143992021-04-09 15:17:10 +0000278 onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800279 if existPA {
280 if valuePA != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000281 //Config data for this uni and and at least TCont Index 0 exist
mpagenko8b07c1b2020-11-26 10:36:31 +0000282 if err := onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000283 logger.Errorw(ctx, "tech-profile related FSM could not be started",
mpagenko8b07c1b2020-11-26 10:36:31 +0000284 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000285 onuTP.mutexTPState.Lock()
286 defer onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000287 onuTP.procResult[uniTpKey] = err
288 return
289 }
mpagenkodff5dda2020-08-28 11:52:01 +0000290 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000291 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
292 logger.Warnw(ctx, "tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000293 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800294
mpagenko73143992021-04-09 15:17:10 +0000295 onuTP.mutexTPState.Lock()
296 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800297 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200298 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530299 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000300 //which requires to reset it to allow for new usage, e.g. also on a different UNI
301 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000302 if _, ok := onuTP.pAniConfigFsm[uniTpKey]; ok {
303 _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset)
304 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000305 return
mpagenkoaf801632020-07-03 10:00:42 +0000306 }
307 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000308 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000309 logger.Errorw(ctx, "no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000310 "device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000311 onuTP.mutexTPState.Lock()
312 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800313 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 +0200314 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000315 return
mpagenkoaf801632020-07-03 10:00:42 +0000316 }
317 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000318 logger.Errorw(ctx, "no PonAni data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000319 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800320
mpagenko73143992021-04-09 15:17:10 +0000321 onuTP.mutexTPState.Lock()
322 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800323 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 +0200324 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000325 return
mpagenkoaf801632020-07-03 10:00:42 +0000326 }
327}
328
mpagenko3dbcdd22020-07-22 07:38:45 +0000329/* internal methods *********************/
ozgecanetsia4b232302020-11-11 10:58:10 +0300330// nolint: gocyclo
Himani Chawla6d2ae152020-09-02 13:11:20 +0530331func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile(
Girish Gowdra041dcb32020-11-16 16:54:30 -0800332 ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000333 var tpInst tp.TechProfile
334
335 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
336 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
337 subStringSlice := strings.Split(aPathString, "/")
338 if len(subStringSlice) <= 2 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000339 logger.Errorw(ctx, "invalid path name format",
mpagenko3dbcdd22020-07-22 07:38:45 +0000340 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000341 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000342 return
343 }
344
mpagenko73143992021-04-09 15:17:10 +0000345 //ensure write protection for access to used maps
346 onuTP.mutexTPState.Lock()
347 defer onuTP.mutexTPState.Unlock()
348
349 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
350 onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false
351
mpagenko3dbcdd22020-07-22 07:38:45 +0000352 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000353 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
354 // then we throw a warning, set an internal error and abort with error,
355 // which is later re-defined to success response to OLT adapter
356 // if TPId has changed, current data is removed (note that the ONU config state may be
357 // ambivalent in such a case)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800358 if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000359 logger.Warnw(ctx, "Some active profile entry at reading new TechProfile",
mpagenko3dbcdd22020-07-22 07:38:45 +0000360 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800361 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
362 if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID {
mpagenko01e726e2020-10-23 09:45:29 +0000363 // ProfId not changed - assume profile to be still the same
364 // anyway this should not appear after full support of profile (Gem/TCont) removal
dbainbri4d3a0dc2020-12-02 00:33:42 +0000365 logger.Warnw(ctx, "New TechProfile already exists - aborting configuration",
mpagenko01e726e2020-10-23 09:45:29 +0000366 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800367 onuTP.tpProfileExists[uniTPKey] = true
mpagenko01e726e2020-10-23 09:45:29 +0000368 onuTP.chTpConfigProcessingStep <- 0 //error indication
369 return
370 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000371 //delete on the mapUniTpIndication map not needed, just overwritten later
372 //delete on the PonAniConfig map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800373 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenko3dbcdd22020-07-22 07:38:45 +0000374 } else {
375 // this is normal processing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800376 onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
mpagenko3dbcdd22020-07-22 07:38:45 +0000377 }
378
Girish Gowdra041dcb32020-11-16 16:54:30 -0800379 onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000380 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
Girish Gowdra041dcb32020-11-16 16:54:30 -0800381 onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID
382 onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false
383 onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000384 logger.Debugw(ctx, "tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000385 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800386 "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType,
387 "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000388
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000389 Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString)
mpagenko3dbcdd22020-07-22 07:38:45 +0000390 if err == nil {
391 if Value != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000392 logger.Debugw(ctx, "tech-profile read",
mpagenko3dbcdd22020-07-22 07:38:45 +0000393 log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID})
394 tpTmpBytes, _ := kvstore.ToByte(Value.Value)
395
396 if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000397 logger.Errorw(ctx, "TechProf - Failed to unmarshal tech-profile into tpInst",
mpagenko3dbcdd22020-07-22 07:38:45 +0000398 log.Fields{"error": err, "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 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000402 logger.Debugw(ctx, "TechProf - tpInst", log.Fields{"tpInst": tpInst})
mpagenko3dbcdd22020-07-22 07:38:45 +0000403 // access examples
dbainbri4d3a0dc2020-12-02 00:33:42 +0000404 logger.Debugw(ctx, "TechProf content", log.Fields{"Name": tpInst.Name,
mpagenko3dbcdd22020-07-22 07:38:45 +0000405 "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize,
406 "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
407 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000408 logger.Errorw(ctx, "No tech-profile found",
mpagenko3dbcdd22020-07-22 07:38:45 +0000409 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000410 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000411 return
412 }
413 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000414 logger.Errorw(ctx, "kvstore-get failed for path",
mpagenko3dbcdd22020-07-22 07:38:45 +0000415 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000416 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000417 return
418 }
419
mpagenko01e726e2020-10-23 09:45:29 +0000420 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000421 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800422 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000423
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000424 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000425 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra041dcb32020-11-16 16:54:30 -0800426 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID)
Himani Chawla4d908332020-08-31 12:30:20 +0530427 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000428 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
429 if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800430 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000431 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000432 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800433 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000434 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000435 loNumGemPorts := tpInst.NumGemPorts
436 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000437 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000438 if uint32(pos) == loNumGemPorts {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000439 logger.Debugw(ctx, "PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
mpagenko1cc3cb42020-07-27 15:24:38 +0000440 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000441 break
442 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000443 if pos == 0 {
444 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
445 loGemPortRead = true
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000446 }
Himani Chawla1c136902020-12-10 16:30:59 +0530447 //for all GemPorts we need to extend the mapGemPortParams
448 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)] = &gemPortParamStruct{}
449
450 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortID =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000451 uint16(content.GemportID)
452 //direction can be correlated later with Downstream list,
453 // for now just assume bidirectional (upstream never exists alone)
Himani Chawla1c136902020-12-10 16:30:59 +0530454 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000455 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
ozgecanetsia4b232302020-11-11 10:58:10 +0300456 if content.PriorityQueue > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000457 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000458 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue})
459 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800460 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000461 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000462 return
463 }
Himani Chawla1c136902020-12-10 16:30:59 +0530464 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].prioQueueIndex =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000465 uint8(content.PriorityQueue)
Himani Chawla1c136902020-12-10 16:30:59 +0530466 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530467 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000468 if content.AesEncryption == "True" {
Himani Chawla1c136902020-12-10 16:30:59 +0530469 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000470 } else {
Himani Chawla1c136902020-12-10 16:30:59 +0530471 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000472 }
Himani Chawla1c136902020-12-10 16:30:59 +0530473 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].discardPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000474 content.DiscardPolicy
Himani Chawla1c136902020-12-10 16:30:59 +0530475 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].queueSchedPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000476 content.SchedulingPolicy
mpagenko3dbcdd22020-07-22 07:38:45 +0000477 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Himani Chawla1c136902020-12-10 16:30:59 +0530478 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000479 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000480 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300481
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300482 for _, downstreamContent := range tpInst.DownstreamGemPortAttributeList {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000483 logger.Debugw(ctx, "Operating on Downstream Gem Port", log.Fields{"downstream-gem": downstreamContent})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300484 //Commenting this out due to faliure, needs investigation
485 //if uint32(pos) == loNumGemPorts {
486 // logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
487 // log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
488 // break
489 //}
490 isMulticast := false
ozgecanetsia4b232302020-11-11 10:58:10 +0300491 //Flag is defined as string in the TP in voltha-lib-go, parsing it from string
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300492 if downstreamContent.IsMulticast != "" {
493 isMulticast, err = strconv.ParseBool(downstreamContent.IsMulticast)
494 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000495 logger.Errorw(ctx, "multicast-error-config-unknown-flag-in-technology-profile",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300496 log.Fields{"UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "error": err})
497 continue
498 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300499 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000500 logger.Infow(ctx, "Gem Port is multicast", log.Fields{"isMulticast": isMulticast})
ozgecanetsia4b232302020-11-11 10:58:10 +0300501 if isMulticast {
502 mcastGemID := uint16(downstreamContent.McastGemID)
503 _, existing := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID]
504 if existing {
505 //GEM port was previously configured, avoid setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000506 logger.Errorw(ctx, "multicast-error-config-existing-gem-port-config", log.Fields{"UniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300507 "downstream-gem": downstreamContent, "key": mcastGemID})
508 continue
509 } else {
510 //GEM port is not configured, setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000511 logger.Infow(ctx, "creating-multicast-gem-port", log.Fields{"uniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300512 "gemPortId": mcastGemID, "key": mcastGemID})
513
514 //for all further GemPorts we need to extend the mapGemPortParams
515 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID] = &gemPortParamStruct{}
516
517 //Separate McastGemId is derived from OMCI-lib-go, if not needed first needs to be removed there.
518 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortID = mcastGemID
519 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].direction = 2 // for ANI to UNI as defined in G.988
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300520
521 if downstreamContent.AesEncryption == "True" {
522 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 1
523 } else {
524 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 0
525 }
526
527 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
ozgecanetsia4b232302020-11-11 10:58:10 +0300528 if downstreamContent.PriorityQueue > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000529 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300530 log.Fields{"device-id": onuTP.deviceID, "index": mcastGemID, "PrioQueue": downstreamContent.PriorityQueue})
531 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
532 delete(onuTP.mapPonAniConfig, uniTPKey)
533 onuTP.chTpConfigProcessingStep <- 0 //error indication
534 return
ozgecanetsia4b232302020-11-11 10:58:10 +0300535 }
536 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].prioQueueIndex =
537 uint8(downstreamContent.PriorityQueue)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300538 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].pbitString =
539 strings.TrimPrefix(downstreamContent.PbitMap, binaryStringPrefix)
540
541 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].discardPolicy =
542 downstreamContent.DiscardPolicy
543 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueSchedPolicy =
544 downstreamContent.SchedulingPolicy
545 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
546 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueWeight =
547 uint8(downstreamContent.Weight)
548
ozgecanetsia4b232302020-11-11 10:58:10 +0300549 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].isMulticast = isMulticast
550 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].multicastGemPortID =
551 uint16(downstreamContent.McastGemID)
552 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].staticACL = downstreamContent.SControlList
553 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].dynamicACL = downstreamContent.DControlList
554 }
555 }
556 }
557
Himani Chawla4d908332020-08-31 12:30:20 +0530558 if !loGemPortRead {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000559 logger.Errorw(ctx, "PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000560 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000561 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800562 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000563 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000564 return
565 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000566 //logger does not simply output the given structures, just give some example debug values
dbainbri4d3a0dc2020-12-02 00:33:42 +0000567 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000568 "device-id": onuTP.deviceID, "uni-id": aUniID,
569 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
Himani Chawla1c136902020-12-10 16:30:59 +0530570 for gemPortID, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000571 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530572 "GemPort": gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000573 "QueueScheduling": gemEntry.queueSchedPolicy})
574 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000575
mpagenkodff5dda2020-08-28 11:52:01 +0000576 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000577}
578
Himani Chawla6d2ae152020-09-02 13:11:20 +0530579func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
mpagenko8b07c1b2020-11-26 10:36:31 +0000580 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000581
582 //OMCI transfer of ANI data acc. to mapPonAniConfig
583 // also the FSM's are running in background,
mpagenko8b07c1b2020-11-26 10:36:31 +0000584 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800585 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko3dbcdd22020-07-22 07:38:45 +0000586 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000587 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800588 } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000589 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000590 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000591 //AniConfigFsm already init
dbainbri4d3a0dc2020-12-02 00:33:42 +0000592 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000593}
594
595// deleteTpResource removes Resources from the ONU's specified Uni
mpagenko73143992021-04-09 15:17:10 +0000596// nolint: gocyclo
mpagenko8b07c1b2020-11-26 10:36:31 +0000597func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context,
598 aUniID uint8, aTpID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
599 wg *sync.WaitGroup) {
600 defer wg.Done()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000601 logger.Debugw(ctx, "will remove TP resources from ONU's UNI", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000602 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "Resource": aResource})
603 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
604
mpagenko7d6bb022021-03-11 15:07:55 +0000605 bDeviceProcStatusUpdate := true
mpagenko8b07c1b2020-11-26 10:36:31 +0000606 if cResourceGemPort == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000607 logger.Debugw(ctx, "remove GemPort from the list of existing ones of the TP", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000608 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID})
609
mpagenko73143992021-04-09 15:17:10 +0000610 //ensure read protection for access to mapPonAniConfig
611 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000612 // check if the requested GemPort exists in the DB, indicate it to the FSM
613 // store locally to remove it from DB later on success
614 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
615 if pLocAniConfigOnUni == nil {
mpagenko73143992021-04-09 15:17:10 +0000616 onuTP.mutexTPState.RUnlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000617 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000618 logger.Debugw(ctx, "AniConfig or GemEntry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000619 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
620 return
621 }
mpagenko73143992021-04-09 15:17:10 +0000622 onuTP.mutexTPState.RUnlock()
623
Himani Chawla1c136902020-12-10 16:30:59 +0530624 for gemPortID, gemEntry := range pLocAniConfigOnUni.mapGemPortParams {
625 if gemPortID == uint16(aEntryID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000626 //GemEntry to be deleted found
Himani Chawla1c136902020-12-10 16:30:59 +0530627 gemEntry.removeGemID = gemPortID //store the index for later removal
628 onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemPortID]
dbainbri4d3a0dc2020-12-02 00:33:42 +0000629 logger.Debugw(ctx, "Remove-GemEntry stored", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530630 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000631 break //abort loop, always only one GemPort to remove
632 }
633 }
634 if onuTP.mapRemoveGemEntry[uniTPKey] == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000635 logger.Errorw(ctx, "GemPort removal aborted - GemPort not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000636 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
637 /* Do not set some error indication to the outside system interface on delete
638 assume there is nothing to be deleted internally and hope a new config request will recover the situation
639 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s",
640 aEntryID, aUniID, onuTP.deviceID)
641 */
642 return
643 }
644 if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig {
645 // check that the TpConfigRequest was done before
646 // -> that is implicitly done using the AniConfigFsm,
647 // which must be in the according state to remove something
mpagenko8b07c1b2020-11-26 10:36:31 +0000648 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000649 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000650 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
651 /* Do not set some error indication to the outside system interface on delete (see above)
652 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s",
653 aUniID, onuTP.deviceID)
654 */
655 //if the FSM is not valid, also TP related remove data should not be valid:
656 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000657 //ensure write protection for access to mapPonAniConfig
658 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530659 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000660 // remove the removeEntry
661 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000662 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000663 return
664 }
665 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000666 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000667 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
668 /* Do not set some error indication to the outside system interface on delete (see above)
669 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid",
670 aUniID, onuTP.deviceID, aTpID)
671 */
672 //if the FSM is not valid, also TP related remove data should not be valid:
673 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000674 //ensure write protection for access to mapPonAniConfig
675 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530676 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000677 // remove the removeEntry
678 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000679 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000680 return
681 }
mpagenko73143992021-04-09 15:17:10 +0000682 if onuTP.getProfileResetting(uniTPKey) {
683 logger.Debugw(ctx, "aborting GemRemoval on FSM, reset requested in parallel", log.Fields{
684 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
685 //ensure write protection for access to mapPonAniConfig
686 onuTP.mutexTPState.Lock()
687 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
688 // remove the removeEntry
689 delete(onuTP.mapRemoveGemEntry, uniTPKey)
690 onuTP.mutexTPState.Unlock()
691 return
692 }
693 // initiate OMCI GemPort related removal
694 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
695 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000696 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemGemiw, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000697 //even if the FSM invocation did not work we don't indicate a problem within procResult
698 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
699 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
700 return
701 }
702 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000703 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
704 logger.Warnw(ctx, "GemPort removal aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000705 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
706 //even if the FSM delete execution did not work we don't indicate a problem within procResult
707 //we should never respond to delete with error ...
708 //this issue here means that the AniConfigFsm has not finished successfully
709 //which requires to reset it to allow for new usage, e.g. also on a different UNI
710 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000711 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok {
712 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
713 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000714 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
715 return
716 }
717 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000718 //if we can't do the OMCI processing we also suppress the ProcStatusUpdate
719 //this is needed as in the device-down case where all FSM's are getting reset and internal data gets cleared
720 //as a consequence a possible remove-flow does not see any dependency on the TechProfile anymore and is executed (pro forma) directly
721 //a later TechProfile removal would cause the device-reason to be updated to 'techProfile-delete-success' which is not the expected state
722 // and anyway is no real useful information at that stage
723 bDeviceProcStatusUpdate = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000724 logger.Debugw(ctx, "uniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000725 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000726 }
727 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000728 //ensure write protection for access to mapPonAniConfig
729 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530730 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000731 // remove the removeEntry
732 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000733 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000734 // deviceHandler StatusEvent (reason update) (see end of function) is only generated in case some element really was removed
735 } else { //if cResourceTcont == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000736 logger.Debugw(ctx, "reset TCont with AllocId", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000737 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID})
738
mpagenko73143992021-04-09 15:17:10 +0000739 //ensure read protection for access to mapPonAniConfig
740 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000741 // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM
742 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
743 if pLocAniConfigOnUni == nil {
744 // No relevant entry exists anymore - acknowledge success
mpagenko73143992021-04-09 15:17:10 +0000745 onuTP.mutexTPState.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000746 logger.Debugw(ctx, "AniConfig or TCont entry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000747 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
748 return
749 }
mpagenko73143992021-04-09 15:17:10 +0000750 onuTP.mutexTPState.RUnlock()
751
mpagenko8b07c1b2020-11-26 10:36:31 +0000752 if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000753 logger.Errorw(ctx, "TCont removal aborted - indicated AllocId not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000754 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID})
755 /* Do not set some error indication to the outside system interface on delete
756 assume there is nothing to be deleted internally and hope a new config request will recover the situation
757 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s",
758 aEntryID, aUniID, onuTP.deviceID)
759 */
760 return
761 }
762 //T-Cont to be reset found
dbainbri4d3a0dc2020-12-02 00:33:42 +0000763 logger.Debugw(ctx, "Reset-T-Cont AllocId found - valid", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000764 "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID})
765 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000766 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000767 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
768 /* Do not set some error indication to the outside system interface on delete (see above)
769 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s",
770 aUniID, onuTP.deviceID)
771 */
772 //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 +0000773 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000774 return
775 }
776 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000777 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000778 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
779 //even if the FSM invocation did not work we don't indicate a problem within procResult
780 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
781 //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 +0000782 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000783 return
784 }
785 if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig {
786 // check that the TpConfigRequest was done before
787 // -> that is implicitly done using the AniConfigFsm,
788 // which must be in the according state to remove something
mpagenko73143992021-04-09 15:17:10 +0000789 if onuTP.getProfileResetting(uniTPKey) {
790 logger.Debugw(ctx, "aborting TCont removal on FSM, reset requested in parallel", log.Fields{
791 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
792 return
793 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000794 // initiate OMCI TCont related cleanup
795 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
796 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000797 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemTcontPath, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000798 //even if the FSM invocation did not work we don't indicate a problem within procResult
799 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
800 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
801 return
802 }
803 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000804 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
805 logger.Warnw(ctx, "TCont cleanup aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000806 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
807 //even if the FSM delete execution did not work we don't indicate a problem within procResult
808 //we should never respond to delete with error ...
809 //this issue here means that the AniConfigFsm has not finished successfully
810 //which requires to reset it to allow for new usage, e.g. also on a different UNI
811 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000812 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok {
813 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
814 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000815 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
816 return
817 }
818 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000819 //see gemPort comments
820 bDeviceProcStatusUpdate = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000821 logger.Debugw(ctx, "uniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000822 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000823 }
824 //clear the internal store profile data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000825 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000826 // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created
827 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
828 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
829 }
mpagenko7d6bb022021-03-11 15:07:55 +0000830 if bDeviceProcStatusUpdate {
831 // generate deviceHandler StatusEvent in case the FSM was not invoked and OMCI processing not locked due to device state
832 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(ctx, OmciAniResourceRemoved)
833 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000834}
835
Himani Chawla6d2ae152020-09-02 13:11:20 +0530836func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000837 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000838 select {
839 case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000840 logger.Warnw(ctx, "processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000841 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000842 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000843 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000844 if rxStep == aProcessingStep {
845 return true
846 }
847 //all other values are not accepted - including 0 for error indication
dbainbri4d3a0dc2020-12-02 00:33:42 +0000848 logger.Warnw(ctx, "Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000849 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000850 "wantedStep": aProcessingStep, "haveStep": rxStep})
851 return false
852 }
853}
854
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000855// createAniConfigFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000856func (onuTP *onuUniTechProf) createAniConfigFsm(ctx context.Context, aUniID uint8, aTpID uint8,
mpagenko8b07c1b2020-11-26 10:36:31 +0000857 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000858 logger.Debugw(ctx, "createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000859 chAniConfigFsm := make(chan Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800860 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000861 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(ctx, true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000862 if pDevEntry == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000863 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000864 return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000865 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000866 pAniCfgFsm := newUniPonAniConfigFsm(ctx, pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800867 pDevEntry.pOnuDB, aTpID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000868 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko8b07c1b2020-11-26 10:36:31 +0000869 if pAniCfgFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000870 logger.Errorw(ctx, "AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000871 return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000872 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000873 if onuTP.pAniConfigFsm == nil {
874 onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800875 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000876 onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm
dbainbri4d3a0dc2020-12-02 00:33:42 +0000877 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000878}
879
mpagenko3dbcdd22020-07-22 07:38:45 +0000880// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000881func (onuTP *onuUniTechProf) runAniConfigFsm(ctx context.Context, aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000882 /* Uni related ANI config procedure -
883 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
884 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800885 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
886
887 pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000888 if pACStatemachine != nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000889 if aEvent == aniEvStart {
890 if !pACStatemachine.Is(aniStDisabled) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000891 logger.Errorw(ctx, "wrong state of AniConfigFSM to start - want: Disabled", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000892 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000893 // maybe try a FSM reset and then again ... - TODO!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000894 return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000895 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000896 } else if !pACStatemachine.Is(aniStConfigDone) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000897 logger.Errorw(ctx, "wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000898 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000899 return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000900 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000901 //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config)
902 onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
903 if err := pACStatemachine.Event(aEvent); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000904 logger.Errorw(ctx, "AniConfigFSM: can't trigger event", log.Fields{"err": err})
mpagenko8b07c1b2020-11-26 10:36:31 +0000905 return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID)
906 }
907 /***** AniConfigFSM event notified */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000908 logger.Debugw(ctx, "AniConfigFSM event notified", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000909 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent})
910 return nil
mpagenko3dbcdd22020-07-22 07:38:45 +0000911 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000912 logger.Errorw(ctx, "AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000913 // maybe try a FSM reset and then again ... - TODO!!!
914 return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID)
mpagenkoaf801632020-07-03 10:00:42 +0000915}
mpagenkodff5dda2020-08-28 11:52:01 +0000916
Girish Gowdra041dcb32020-11-16 16:54:30 -0800917// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000918func (onuTP *onuUniTechProf) clearAniSideConfig(ctx context.Context, aUniID uint8, aTpID uint8) {
919 logger.Debugw(ctx, "removing TpIndication and PonAniConfig data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000920 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800921 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
922
923 onuTP.mutexTPState.Lock()
924 defer onuTP.mutexTPState.Unlock()
mpagenko73143992021-04-09 15:17:10 +0000925 //deleting a map entry should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800926 delete(onuTP.mapUniTpIndication, uniTpKey)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800927 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko73143992021-04-09 15:17:10 +0000928 delete(onuTP.procResult, uniTpKey)
929 delete(onuTP.tpProfileExists, uniTpKey)
930 delete(onuTP.tpProfileResetting, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000931}
932
mpagenkodff5dda2020-08-28 11:52:01 +0000933// setConfigDone sets the requested techProfile config state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800934func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
935 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
936 onuTP.mutexTPState.Lock()
937 defer onuTP.mutexTPState.Unlock()
938 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
939 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000940 } //else: the state is just ignored (does not exist)
941}
942
943// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
dbainbri4d3a0dc2020-12-02 00:33:42 +0000944func (onuTP *onuUniTechProf) getTechProfileDone(ctx context.Context, aUniID uint8, aTpID uint8) bool {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800945 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000946 onuTP.mutexTPState.RLock()
947 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800948 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
949 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
950 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000951 logger.Debugw(ctx, "TechProfile not relevant for requested flow config - waiting on delete",
mpagenko2418ab02020-11-12 12:58:06 +0000952 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
953 return false //still waiting for removal of this techProfile first
954 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800955 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000956 }
957 }
958 //for all other constellations indicate false = Config not done
959 return false
960}
mpagenko2418ab02020-11-12 12:58:06 +0000961
962// setProfileToDelete sets the requested techProfile toDelete state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800963func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
964 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
965 onuTP.mutexTPState.Lock()
966 defer onuTP.mutexTPState.Unlock()
967 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
968 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000969 } //else: the state is just ignored (does not exist)
970}
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300971
972// setProfileToDelete sets the requested techProfile toDelete state (if possible)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000973func (onuTP *onuUniTechProf) getMulticastGemPorts(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300974 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000975 onuTP.mutexTPState.RLock()
976 defer onuTP.mutexTPState.RUnlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300977 gemPortIds := make([]uint16, 0)
978 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
979 for _, gemPortParam := range techProfile.mapGemPortParams {
980 if gemPortParam.isMulticast {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000981 logger.Debugw(ctx, "Detected multicast gemPort", log.Fields{"device-id": onuTP.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300982 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
983 "mcastGemId": gemPortParam.multicastGemPortID})
984 gemPortIds = append(gemPortIds, gemPortParam.multicastGemPortID)
985 }
986 }
987 } //else: the state is just ignored (does not exist)
988 return gemPortIds
989}
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800990
991func (onuTP *onuUniTechProf) GetAllBidirectionalGemPortIDsForOnu() []uint16 {
992 var gemPortInstIDs []uint16
993 onuTP.mutexTPState.RLock()
994 defer onuTP.mutexTPState.RUnlock()
995 for _, tcontGemList := range onuTP.mapPonAniConfig {
996 for gemPortID, gemPortData := range tcontGemList.mapGemPortParams {
997 if gemPortData != nil && !gemPortData.isMulticast { // only if not multicast gem port
998 gemPortInstIDs = append(gemPortInstIDs, gemPortID)
999 }
1000 }
1001 }
1002 return gemPortInstIDs
1003}
mpagenko73143992021-04-09 15:17:10 +00001004
1005// setProfileResetting sets/resets the indication, that a reset of the TechProfileConfig/Removal is ongoing
1006func (onuTP *onuUniTechProf) setProfileResetting(ctx context.Context, aUniID uint8, aTpID uint8, aState bool) {
1007 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
1008 onuTP.mutexTPState.Lock()
1009 defer onuTP.mutexTPState.Unlock()
1010 onuTP.tpProfileResetting[uniTpKey] = aState
1011}
1012
1013// getProfileResetting returns true, if the the according indication for started reset procedure is set
1014func (onuTP *onuUniTechProf) getProfileResetting(aUniTpKey uniTP) bool {
1015 onuTP.mutexTPState.RLock()
1016 defer onuTP.mutexTPState.RUnlock()
1017 if isResetting, exist := onuTP.tpProfileResetting[aUniTpKey]; exist {
1018 return isResetting
1019 }
1020 return false
1021}