blob: dff13d4ae82595bb2b7edfea374bac2dbaa78f45 [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
ozgecanetsia72e1c9f2021-05-26 17:26:29 +0300113func (onuTP *onuUniTechProf) multicastConfiguredForOtherUniTps(ctx context.Context, uniTpKey uniTP) bool {
114 for _, aniFsm := range onuTP.pAniConfigFsm {
115 if aniFsm.uniTpKey.uniID == uniTpKey.uniID && aniFsm.uniTpKey.tpID == uniTpKey.tpID {
116 continue
117 }
118 if aniFsm.hasMulticastGem(ctx) {
119 return true
120 }
121 }
122 return false
123}
124
Himani Chawla6d2ae152020-09-02 13:11:20 +0530125//newOnuUniTechProf returns the instance of a OnuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000126//(one instance per ONU/deviceHandler for all possible UNI's)
mpagenko01e726e2020-10-23 09:45:29 +0000127func newOnuUniTechProf(ctx context.Context, aDeviceHandler *deviceHandler) *onuUniTechProf {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000128 logger.Debugw(ctx, "init-OnuUniTechProf", log.Fields{"device-id": aDeviceHandler.deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530129 var onuTP onuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000130 onuTP.baseDeviceHandler = aDeviceHandler
mpagenko01e726e2020-10-23 09:45:29 +0000131 onuTP.deviceID = aDeviceHandler.deviceID
mpagenkodff5dda2020-08-28 11:52:01 +0000132 onuTP.chTpConfigProcessingStep = make(chan uint8)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800133 onuTP.mapUniTpIndication = make(map[uniTP]*tTechProfileIndication)
134 onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList)
135 onuTP.procResult = make(map[uniTP]error)
136 onuTP.tpProfileExists = make(map[uniTP]bool)
mpagenko73143992021-04-09 15:17:10 +0000137 onuTP.tpProfileResetting = make(map[uniTP]bool)
mpagenko8b07c1b2020-11-26 10:36:31 +0000138 onuTP.mapRemoveGemEntry = make(map[uniTP]*gemPortParamStruct)
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800139 baseKvStorePath := fmt.Sprintf(cBasePathTechProfileKVStore, aDeviceHandler.pOpenOnuAc.cm.Backend.PathPrefix)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000140 onuTP.techProfileKVStore = aDeviceHandler.setBackend(ctx, baseKvStorePath)
mpagenkoaf801632020-07-03 10:00:42 +0000141 if onuTP.techProfileKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000142 logger.Errorw(ctx, "Can't access techProfileKVStore - no backend connection to service",
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800143 log.Fields{"device-id": aDeviceHandler.deviceID, "service": baseKvStorePath})
mpagenkoaf801632020-07-03 10:00:42 +0000144 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000145
mpagenkoaf801632020-07-03 10:00:42 +0000146 return &onuTP
147}
148
149// lockTpProcMutex locks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530150func (onuTP *onuUniTechProf) lockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000151 onuTP.tpProcMutex.Lock()
152}
153
154// unlockTpProcMutex unlocks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530155func (onuTP *onuUniTechProf) unlockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000156 onuTP.tpProcMutex.Unlock()
157}
158
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000159// resetTpProcessingErrorIndication resets the internal error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000160// need to be called before evaluation of any subsequent processing (given by waitForTpCompletion())
Girish Gowdra041dcb32020-11-16 16:54:30 -0800161func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) {
mpagenko73143992021-04-09 15:17:10 +0000162 onuTP.mutexTPState.Lock()
163 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800164 onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000165}
166
Girish Gowdra041dcb32020-11-16 16:54:30 -0800167func (onuTP *onuUniTechProf) getTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error {
mpagenko73143992021-04-09 15:17:10 +0000168 onuTP.mutexTPState.RLock()
169 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800170 return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}]
mpagenko3dbcdd22020-07-22 07:38:45 +0000171}
172
mpagenko8b07c1b2020-11-26 10:36:31 +0000173// configureUniTp checks existing tp resources to configure and starts the corresponding OMCI configuation of the UNI port
mpagenko3dbcdd22020-07-22 07:38:45 +0000174// all possibly blocking processing must be run in background to allow for deadline supervision!
175// but take care on sequential background processing when needed (logical dependencies)
Himani Chawla4d908332020-08-31 12:30:20 +0530176// use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization
Himani Chawla6d2ae152020-09-02 13:11:20 +0530177func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context,
mpagenkodff5dda2020-08-28 11:52:01 +0000178 aUniID uint8, aPathString string, wg *sync.WaitGroup) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000179 defer wg.Done() //always decrement the waitGroup on return
dbainbri4d3a0dc2020-12-02 00:33:42 +0000180 logger.Debugw(ctx, "configure the Uni according to TpPath", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000181 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800182 tpID, err := GetTpIDFromTpPath(aPathString)
183 uniTpKey := uniTP{uniID: aUniID, tpID: tpID}
184 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000185 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 -0800186 return
187 }
mpagenkoaf801632020-07-03 10:00:42 +0000188 if onuTP.techProfileKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000189 logger.Errorw(ctx, "techProfileKVStore not set - abort",
mpagenko8b07c1b2020-11-26 10:36:31 +0000190 log.Fields{"device-id": onuTP.deviceID})
mpagenko73143992021-04-09 15:17:10 +0000191 onuTP.mutexTPState.Lock()
192 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800193 onuTP.procResult[uniTpKey] = errors.New("techProfile config aborted: techProfileKVStore not set")
mpagenkoaf801632020-07-03 10:00:42 +0000194 return
195 }
196
mpagenko3dbcdd22020-07-22 07:38:45 +0000197 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530198 var pCurrentUniPort *onuUniPort
mpagenko3dbcdd22020-07-22 07:38:45 +0000199 for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap {
200 // only if this port is validated for operState transfer
Girish Gowdra041dcb32020-11-16 16:54:30 -0800201 if uniPort.uniID == aUniID {
mpagenko3dbcdd22020-07-22 07:38:45 +0000202 pCurrentUniPort = uniPort
203 break //found - end search loop
204 }
205 }
206 if pCurrentUniPort == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000207 logger.Errorw(ctx, "TechProfile configuration aborted: requested uniID not found in PortDB",
mpagenko73143992021-04-09 15:17:10 +0000208 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
209 onuTP.mutexTPState.Lock()
210 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800211 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200212 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000213 return
214 }
mpagenkoaf801632020-07-03 10:00:42 +0000215
mpagenko73143992021-04-09 15:17:10 +0000216 if onuTP.getProfileResetting(uniTpKey) {
217 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
218 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
219 onuTP.mutexTPState.Lock()
220 defer onuTP.mutexTPState.Unlock()
221 onuTP.procResult[uniTpKey] = fmt.Errorf(
222 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
223 aUniID, onuTP.deviceID)
224 return
225 }
mpagenkodff5dda2020-08-28 11:52:01 +0000226 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
mpagenkoaf801632020-07-03 10:00:42 +0000227
mpagenko3dbcdd22020-07-22 07:38:45 +0000228 //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called
229 // in case the KVPath has changed for the given UNI,
230 // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
231 // (ANI) configuration of this port has to be removed first
232 // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
233 // existence of configuration can be detected based on tp stored TCONT's
Andrea Campanella6515c582020-10-05 11:25:00 +0200234 //TODO:
mpagenko3dbcdd22020-07-22 07:38:45 +0000235 /* if tcontMap not empty {
236 go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000237 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000238 //timeout or error detected
239 return
240 }
241 clear tcontMap
242 }
243
244 processingStep++
245 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800246 go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000247 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000248 //timeout or error detected
mpagenko73143992021-04-09 15:17:10 +0000249 onuTP.mutexTPState.RLock()
250 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800251 if onuTP.tpProfileExists[uniTpKey] {
mpagenko01e726e2020-10-23 09:45:29 +0000252 //ignore the internal error in case the new profile is already configured
253 // and abort the processing here
254 return
255 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000256 logger.Errorw(ctx, "tech-profile related configuration aborted on read",
mpagenko01e726e2020-10-23 09:45:29 +0000257 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000258 onuTP.mutexTPState.Lock()
259 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800260 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200261 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000262 return
263 }
mpagenko73143992021-04-09 15:17:10 +0000264 if onuTP.getProfileResetting(uniTpKey) {
265 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
266 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
267 onuTP.mutexTPState.Lock()
268 defer onuTP.mutexTPState.Unlock()
269 onuTP.procResult[uniTpKey] = fmt.Errorf(
270 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
271 aUniID, onuTP.deviceID)
272 return
273 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000274 processingStep++
Girish Gowdra041dcb32020-11-16 16:54:30 -0800275
mpagenko73143992021-04-09 15:17:10 +0000276 //ensure read protection for access to mapPonAniConfig
277 onuTP.mutexTPState.RLock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800278 valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey]
mpagenko73143992021-04-09 15:17:10 +0000279 onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800280 if existPA {
281 if valuePA != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000282 //Config data for this uni and and at least TCont Index 0 exist
mpagenko8b07c1b2020-11-26 10:36:31 +0000283 if err := onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000284 logger.Errorw(ctx, "tech-profile related FSM could not be started",
mpagenko8b07c1b2020-11-26 10:36:31 +0000285 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000286 onuTP.mutexTPState.Lock()
287 defer onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000288 onuTP.procResult[uniTpKey] = err
289 return
290 }
mpagenkodff5dda2020-08-28 11:52:01 +0000291 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000292 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
293 logger.Warnw(ctx, "tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000294 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800295
mpagenko73143992021-04-09 15:17:10 +0000296 onuTP.mutexTPState.Lock()
297 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800298 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200299 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530300 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000301 //which requires to reset it to allow for new usage, e.g. also on a different UNI
302 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000303 if _, ok := onuTP.pAniConfigFsm[uniTpKey]; ok {
304 _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset)
305 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000306 return
mpagenkoaf801632020-07-03 10:00:42 +0000307 }
308 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000309 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000310 logger.Errorw(ctx, "no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000311 "device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000312 onuTP.mutexTPState.Lock()
313 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800314 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 +0200315 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000316 return
mpagenkoaf801632020-07-03 10:00:42 +0000317 }
318 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000319 logger.Errorw(ctx, "no PonAni data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000320 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800321
mpagenko73143992021-04-09 15:17:10 +0000322 onuTP.mutexTPState.Lock()
323 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800324 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 +0200325 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000326 return
mpagenkoaf801632020-07-03 10:00:42 +0000327 }
328}
329
mpagenko3dbcdd22020-07-22 07:38:45 +0000330/* internal methods *********************/
ozgecanetsia4b232302020-11-11 10:58:10 +0300331// nolint: gocyclo
Himani Chawla6d2ae152020-09-02 13:11:20 +0530332func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile(
Girish Gowdra041dcb32020-11-16 16:54:30 -0800333 ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000334 var tpInst tp.TechProfile
335
336 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
337 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
338 subStringSlice := strings.Split(aPathString, "/")
339 if len(subStringSlice) <= 2 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000340 logger.Errorw(ctx, "invalid path name format",
mpagenko3dbcdd22020-07-22 07:38:45 +0000341 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000342 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000343 return
344 }
345
mpagenko73143992021-04-09 15:17:10 +0000346 //ensure write protection for access to used maps
347 onuTP.mutexTPState.Lock()
348 defer onuTP.mutexTPState.Unlock()
349
350 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
351 onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false
352
mpagenko3dbcdd22020-07-22 07:38:45 +0000353 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000354 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
355 // then we throw a warning, set an internal error and abort with error,
356 // which is later re-defined to success response to OLT adapter
357 // if TPId has changed, current data is removed (note that the ONU config state may be
358 // ambivalent in such a case)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800359 if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000360 logger.Warnw(ctx, "Some active profile entry at reading new TechProfile",
mpagenko3dbcdd22020-07-22 07:38:45 +0000361 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800362 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
363 if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID {
mpagenko01e726e2020-10-23 09:45:29 +0000364 // ProfId not changed - assume profile to be still the same
365 // anyway this should not appear after full support of profile (Gem/TCont) removal
dbainbri4d3a0dc2020-12-02 00:33:42 +0000366 logger.Warnw(ctx, "New TechProfile already exists - aborting configuration",
mpagenko01e726e2020-10-23 09:45:29 +0000367 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800368 onuTP.tpProfileExists[uniTPKey] = true
mpagenko01e726e2020-10-23 09:45:29 +0000369 onuTP.chTpConfigProcessingStep <- 0 //error indication
370 return
371 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000372 //delete on the mapUniTpIndication map not needed, just overwritten later
373 //delete on the PonAniConfig map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800374 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenko3dbcdd22020-07-22 07:38:45 +0000375 } else {
376 // this is normal processing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800377 onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
mpagenko3dbcdd22020-07-22 07:38:45 +0000378 }
379
Girish Gowdra041dcb32020-11-16 16:54:30 -0800380 onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000381 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
Girish Gowdra041dcb32020-11-16 16:54:30 -0800382 onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID
383 onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false
384 onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000385 logger.Debugw(ctx, "tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000386 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800387 "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType,
388 "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000389
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000390 Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString)
mpagenko3dbcdd22020-07-22 07:38:45 +0000391 if err == nil {
392 if Value != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000393 logger.Debugw(ctx, "tech-profile read",
mpagenko3dbcdd22020-07-22 07:38:45 +0000394 log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID})
395 tpTmpBytes, _ := kvstore.ToByte(Value.Value)
396
397 if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000398 logger.Errorw(ctx, "TechProf - Failed to unmarshal tech-profile into tpInst",
mpagenko3dbcdd22020-07-22 07:38:45 +0000399 log.Fields{"error": err, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000400 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000401 return
402 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000403 logger.Debugw(ctx, "TechProf - tpInst", log.Fields{"tpInst": tpInst})
mpagenko3dbcdd22020-07-22 07:38:45 +0000404 // access examples
dbainbri4d3a0dc2020-12-02 00:33:42 +0000405 logger.Debugw(ctx, "TechProf content", log.Fields{"Name": tpInst.Name,
mpagenko3dbcdd22020-07-22 07:38:45 +0000406 "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize,
407 "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
408 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000409 logger.Errorw(ctx, "No tech-profile found",
mpagenko3dbcdd22020-07-22 07:38:45 +0000410 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000411 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000412 return
413 }
414 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000415 logger.Errorw(ctx, "kvstore-get failed for path",
mpagenko3dbcdd22020-07-22 07:38:45 +0000416 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000417 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000418 return
419 }
420
mpagenko01e726e2020-10-23 09:45:29 +0000421 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000422 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800423 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000424
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000425 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000426 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra041dcb32020-11-16 16:54:30 -0800427 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID)
Himani Chawla4d908332020-08-31 12:30:20 +0530428 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000429 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
430 if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800431 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000432 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000433 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800434 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000435 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000436 loNumGemPorts := tpInst.NumGemPorts
437 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000438 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000439 if uint32(pos) == loNumGemPorts {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000440 logger.Debugw(ctx, "PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
mpagenko1cc3cb42020-07-27 15:24:38 +0000441 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000442 break
443 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000444 if pos == 0 {
445 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
446 loGemPortRead = true
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000447 }
Himani Chawla1c136902020-12-10 16:30:59 +0530448 //for all GemPorts we need to extend the mapGemPortParams
449 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)] = &gemPortParamStruct{}
450
451 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortID =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000452 uint16(content.GemportID)
453 //direction can be correlated later with Downstream list,
454 // for now just assume bidirectional (upstream never exists alone)
Himani Chawla1c136902020-12-10 16:30:59 +0530455 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000456 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
ozgecanetsia4b232302020-11-11 10:58:10 +0300457 if content.PriorityQueue > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000458 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000459 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue})
460 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800461 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000462 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000463 return
464 }
Himani Chawla1c136902020-12-10 16:30:59 +0530465 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].prioQueueIndex =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000466 uint8(content.PriorityQueue)
Himani Chawla1c136902020-12-10 16:30:59 +0530467 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530468 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000469 if content.AesEncryption == "True" {
Himani Chawla1c136902020-12-10 16:30:59 +0530470 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000471 } else {
Himani Chawla1c136902020-12-10 16:30:59 +0530472 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000473 }
Himani Chawla1c136902020-12-10 16:30:59 +0530474 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].discardPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000475 content.DiscardPolicy
Himani Chawla1c136902020-12-10 16:30:59 +0530476 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].queueSchedPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000477 content.SchedulingPolicy
mpagenko3dbcdd22020-07-22 07:38:45 +0000478 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Himani Chawla1c136902020-12-10 16:30:59 +0530479 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000480 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000481 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300482
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300483 for _, downstreamContent := range tpInst.DownstreamGemPortAttributeList {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000484 logger.Debugw(ctx, "Operating on Downstream Gem Port", log.Fields{"downstream-gem": downstreamContent})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300485 //Commenting this out due to faliure, needs investigation
486 //if uint32(pos) == loNumGemPorts {
487 // logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
488 // log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
489 // break
490 //}
491 isMulticast := false
ozgecanetsia4b232302020-11-11 10:58:10 +0300492 //Flag is defined as string in the TP in voltha-lib-go, parsing it from string
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300493 if downstreamContent.IsMulticast != "" {
494 isMulticast, err = strconv.ParseBool(downstreamContent.IsMulticast)
495 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000496 logger.Errorw(ctx, "multicast-error-config-unknown-flag-in-technology-profile",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300497 log.Fields{"UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "error": err})
498 continue
499 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300500 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000501 logger.Infow(ctx, "Gem Port is multicast", log.Fields{"isMulticast": isMulticast})
ozgecanetsia4b232302020-11-11 10:58:10 +0300502 if isMulticast {
503 mcastGemID := uint16(downstreamContent.McastGemID)
504 _, existing := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID]
505 if existing {
506 //GEM port was previously configured, avoid setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000507 logger.Errorw(ctx, "multicast-error-config-existing-gem-port-config", log.Fields{"UniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300508 "downstream-gem": downstreamContent, "key": mcastGemID})
509 continue
510 } else {
511 //GEM port is not configured, setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000512 logger.Infow(ctx, "creating-multicast-gem-port", log.Fields{"uniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300513 "gemPortId": mcastGemID, "key": mcastGemID})
514
515 //for all further GemPorts we need to extend the mapGemPortParams
516 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID] = &gemPortParamStruct{}
517
518 //Separate McastGemId is derived from OMCI-lib-go, if not needed first needs to be removed there.
519 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortID = mcastGemID
520 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].direction = 2 // for ANI to UNI as defined in G.988
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300521
522 if downstreamContent.AesEncryption == "True" {
523 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 1
524 } else {
525 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 0
526 }
527
528 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
ozgecanetsia4b232302020-11-11 10:58:10 +0300529 if downstreamContent.PriorityQueue > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000530 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300531 log.Fields{"device-id": onuTP.deviceID, "index": mcastGemID, "PrioQueue": downstreamContent.PriorityQueue})
532 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
533 delete(onuTP.mapPonAniConfig, uniTPKey)
534 onuTP.chTpConfigProcessingStep <- 0 //error indication
535 return
ozgecanetsia4b232302020-11-11 10:58:10 +0300536 }
537 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].prioQueueIndex =
538 uint8(downstreamContent.PriorityQueue)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300539 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].pbitString =
540 strings.TrimPrefix(downstreamContent.PbitMap, binaryStringPrefix)
541
542 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].discardPolicy =
543 downstreamContent.DiscardPolicy
544 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueSchedPolicy =
545 downstreamContent.SchedulingPolicy
546 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
547 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueWeight =
548 uint8(downstreamContent.Weight)
549
ozgecanetsia4b232302020-11-11 10:58:10 +0300550 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].isMulticast = isMulticast
551 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].multicastGemPortID =
552 uint16(downstreamContent.McastGemID)
553 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].staticACL = downstreamContent.SControlList
554 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].dynamicACL = downstreamContent.DControlList
555 }
556 }
557 }
558
Himani Chawla4d908332020-08-31 12:30:20 +0530559 if !loGemPortRead {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000560 logger.Errorw(ctx, "PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000561 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000562 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800563 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000564 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000565 return
566 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000567 //logger does not simply output the given structures, just give some example debug values
dbainbri4d3a0dc2020-12-02 00:33:42 +0000568 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000569 "device-id": onuTP.deviceID, "uni-id": aUniID,
570 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
Himani Chawla1c136902020-12-10 16:30:59 +0530571 for gemPortID, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000572 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530573 "GemPort": gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000574 "QueueScheduling": gemEntry.queueSchedPolicy})
575 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000576
mpagenkodff5dda2020-08-28 11:52:01 +0000577 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000578}
579
Himani Chawla6d2ae152020-09-02 13:11:20 +0530580func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
mpagenko8b07c1b2020-11-26 10:36:31 +0000581 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000582
583 //OMCI transfer of ANI data acc. to mapPonAniConfig
584 // also the FSM's are running in background,
mpagenko8b07c1b2020-11-26 10:36:31 +0000585 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800586 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko3dbcdd22020-07-22 07:38:45 +0000587 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000588 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800589 } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000590 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000591 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000592 //AniConfigFsm already init
dbainbri4d3a0dc2020-12-02 00:33:42 +0000593 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000594}
595
596// deleteTpResource removes Resources from the ONU's specified Uni
mpagenko73143992021-04-09 15:17:10 +0000597// nolint: gocyclo
mpagenko8b07c1b2020-11-26 10:36:31 +0000598func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context,
599 aUniID uint8, aTpID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
600 wg *sync.WaitGroup) {
601 defer wg.Done()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000602 logger.Debugw(ctx, "will remove TP resources from ONU's UNI", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000603 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "Resource": aResource})
604 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
605
mpagenko7d6bb022021-03-11 15:07:55 +0000606 bDeviceProcStatusUpdate := true
mpagenko8b07c1b2020-11-26 10:36:31 +0000607 if cResourceGemPort == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000608 logger.Debugw(ctx, "remove GemPort from the list of existing ones of the TP", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000609 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID})
610
mpagenko73143992021-04-09 15:17:10 +0000611 //ensure read protection for access to mapPonAniConfig
612 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000613 // check if the requested GemPort exists in the DB, indicate it to the FSM
614 // store locally to remove it from DB later on success
615 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
616 if pLocAniConfigOnUni == nil {
mpagenko73143992021-04-09 15:17:10 +0000617 onuTP.mutexTPState.RUnlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000618 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000619 logger.Debugw(ctx, "AniConfig or GemEntry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000620 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
621 return
622 }
mpagenko73143992021-04-09 15:17:10 +0000623 onuTP.mutexTPState.RUnlock()
624
Himani Chawla1c136902020-12-10 16:30:59 +0530625 for gemPortID, gemEntry := range pLocAniConfigOnUni.mapGemPortParams {
626 if gemPortID == uint16(aEntryID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000627 //GemEntry to be deleted found
Himani Chawla1c136902020-12-10 16:30:59 +0530628 gemEntry.removeGemID = gemPortID //store the index for later removal
629 onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemPortID]
dbainbri4d3a0dc2020-12-02 00:33:42 +0000630 logger.Debugw(ctx, "Remove-GemEntry stored", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530631 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000632 break //abort loop, always only one GemPort to remove
633 }
634 }
635 if onuTP.mapRemoveGemEntry[uniTPKey] == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000636 logger.Errorw(ctx, "GemPort removal aborted - GemPort not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000637 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
638 /* Do not set some error indication to the outside system interface on delete
639 assume there is nothing to be deleted internally and hope a new config request will recover the situation
640 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s",
641 aEntryID, aUniID, onuTP.deviceID)
642 */
643 return
644 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000645 if onuTP.baseDeviceHandler.isReadyForOmciConfig() {
mpagenko8b07c1b2020-11-26 10:36:31 +0000646 // check that the TpConfigRequest was done before
647 // -> that is implicitly done using the AniConfigFsm,
648 // which must be in the according state to remove something
mpagenko8b07c1b2020-11-26 10:36:31 +0000649 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000650 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000651 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
652 /* Do not set some error indication to the outside system interface on delete (see above)
653 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s",
654 aUniID, onuTP.deviceID)
655 */
656 //if the FSM is not valid, also TP related remove data should not be valid:
657 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000658 //ensure write protection for access to mapPonAniConfig
659 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530660 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000661 // remove the removeEntry
662 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000663 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000664 return
665 }
666 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000667 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000668 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
669 /* Do not set some error indication to the outside system interface on delete (see above)
670 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid",
671 aUniID, onuTP.deviceID, aTpID)
672 */
673 //if the FSM is not valid, also TP related remove data should not be valid:
674 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000675 //ensure write protection for access to mapPonAniConfig
676 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530677 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000678 // remove the removeEntry
679 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000680 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000681 return
682 }
mpagenko73143992021-04-09 15:17:10 +0000683 if onuTP.getProfileResetting(uniTPKey) {
684 logger.Debugw(ctx, "aborting GemRemoval on FSM, reset requested in parallel", log.Fields{
685 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
686 //ensure write protection for access to mapPonAniConfig
687 onuTP.mutexTPState.Lock()
688 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
689 // remove the removeEntry
690 delete(onuTP.mapRemoveGemEntry, uniTPKey)
691 onuTP.mutexTPState.Unlock()
692 return
693 }
694 // initiate OMCI GemPort related removal
695 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
696 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000697 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemGemiw, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000698 //even if the FSM invocation did not work we don't indicate a problem within procResult
699 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
700 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
701 return
702 }
703 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000704 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
705 logger.Warnw(ctx, "GemPort removal aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000706 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
707 //even if the FSM delete execution did not work we don't indicate a problem within procResult
708 //we should never respond to delete with error ...
709 //this issue here means that the AniConfigFsm has not finished successfully
710 //which requires to reset it to allow for new usage, e.g. also on a different UNI
711 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000712 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok {
713 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
714 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000715 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
716 return
717 }
718 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000719 //if we can't do the OMCI processing we also suppress the ProcStatusUpdate
720 //this is needed as in the device-down case where all FSM's are getting reset and internal data gets cleared
721 //as a consequence a possible remove-flow does not see any dependency on the TechProfile anymore and is executed (pro forma) directly
722 //a later TechProfile removal would cause the device-reason to be updated to 'techProfile-delete-success' which is not the expected state
723 // and anyway is no real useful information at that stage
724 bDeviceProcStatusUpdate = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000725 logger.Debugw(ctx, "uniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000726 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000727 }
728 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000729 //ensure write protection for access to mapPonAniConfig
730 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530731 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000732 // remove the removeEntry
733 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000734 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000735 // deviceHandler StatusEvent (reason update) (see end of function) is only generated in case some element really was removed
736 } else { //if cResourceTcont == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000737 logger.Debugw(ctx, "reset TCont with AllocId", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000738 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID})
739
mpagenko73143992021-04-09 15:17:10 +0000740 //ensure read protection for access to mapPonAniConfig
741 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000742 // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM
743 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
744 if pLocAniConfigOnUni == nil {
745 // No relevant entry exists anymore - acknowledge success
mpagenko73143992021-04-09 15:17:10 +0000746 onuTP.mutexTPState.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000747 logger.Debugw(ctx, "AniConfig or TCont entry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000748 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
749 return
750 }
mpagenko73143992021-04-09 15:17:10 +0000751 onuTP.mutexTPState.RUnlock()
752
mpagenko8b07c1b2020-11-26 10:36:31 +0000753 if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000754 logger.Errorw(ctx, "TCont removal aborted - indicated AllocId not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000755 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID})
756 /* Do not set some error indication to the outside system interface on delete
757 assume there is nothing to be deleted internally and hope a new config request will recover the situation
758 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s",
759 aEntryID, aUniID, onuTP.deviceID)
760 */
761 return
762 }
763 //T-Cont to be reset found
dbainbri4d3a0dc2020-12-02 00:33:42 +0000764 logger.Debugw(ctx, "Reset-T-Cont AllocId found - valid", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000765 "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID})
766 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000767 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000768 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
769 /* Do not set some error indication to the outside system interface on delete (see above)
770 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s",
771 aUniID, onuTP.deviceID)
772 */
773 //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 +0000774 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000775 return
776 }
777 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000778 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000779 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
780 //even if the FSM invocation did not work we don't indicate a problem within procResult
781 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
782 //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 +0000783 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000784 return
785 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000786 if onuTP.baseDeviceHandler.isReadyForOmciConfig() {
mpagenko8b07c1b2020-11-26 10:36:31 +0000787 // check that the TpConfigRequest was done before
788 // -> that is implicitly done using the AniConfigFsm,
789 // which must be in the according state to remove something
mpagenko73143992021-04-09 15:17:10 +0000790 if onuTP.getProfileResetting(uniTPKey) {
791 logger.Debugw(ctx, "aborting TCont removal on FSM, reset requested in parallel", log.Fields{
792 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
793 return
794 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000795 // initiate OMCI TCont related cleanup
796 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
797 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000798 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemTcontPath, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000799 //even if the FSM invocation did not work we don't indicate a problem within procResult
800 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
801 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
802 return
803 }
804 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000805 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
806 logger.Warnw(ctx, "TCont cleanup aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000807 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
808 //even if the FSM delete execution did not work we don't indicate a problem within procResult
809 //we should never respond to delete with error ...
810 //this issue here means that the AniConfigFsm has not finished successfully
811 //which requires to reset it to allow for new usage, e.g. also on a different UNI
812 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000813 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok {
814 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
815 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000816 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
817 return
818 }
819 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000820 //see gemPort comments
821 bDeviceProcStatusUpdate = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000822 logger.Debugw(ctx, "uniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000823 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000824 }
825 //clear the internal store profile data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000826 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000827 // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created
828 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
829 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
830 }
mpagenko7d6bb022021-03-11 15:07:55 +0000831 if bDeviceProcStatusUpdate {
832 // generate deviceHandler StatusEvent in case the FSM was not invoked and OMCI processing not locked due to device state
833 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(ctx, OmciAniResourceRemoved)
834 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000835}
836
Himani Chawla6d2ae152020-09-02 13:11:20 +0530837func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000838 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000839 select {
840 case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000841 logger.Warnw(ctx, "processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000842 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000843 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000844 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000845 if rxStep == aProcessingStep {
846 return true
847 }
848 //all other values are not accepted - including 0 for error indication
dbainbri4d3a0dc2020-12-02 00:33:42 +0000849 logger.Warnw(ctx, "Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000850 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000851 "wantedStep": aProcessingStep, "haveStep": rxStep})
852 return false
853 }
854}
855
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000856// createAniConfigFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000857func (onuTP *onuUniTechProf) createAniConfigFsm(ctx context.Context, aUniID uint8, aTpID uint8,
mpagenko8b07c1b2020-11-26 10:36:31 +0000858 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000859 logger.Debugw(ctx, "createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000860 chAniConfigFsm := make(chan Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800861 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000862 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(ctx, true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000863 if pDevEntry == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000864 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000865 return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000866 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000867 pAniCfgFsm := newUniPonAniConfigFsm(ctx, pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800868 pDevEntry.pOnuDB, aTpID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000869 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko8b07c1b2020-11-26 10:36:31 +0000870 if pAniCfgFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000871 logger.Errorw(ctx, "AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000872 return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000873 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000874 if onuTP.pAniConfigFsm == nil {
875 onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800876 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000877 onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm
dbainbri4d3a0dc2020-12-02 00:33:42 +0000878 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000879}
880
mpagenko3dbcdd22020-07-22 07:38:45 +0000881// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000882func (onuTP *onuUniTechProf) runAniConfigFsm(ctx context.Context, aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000883 /* Uni related ANI config procedure -
884 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
885 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800886 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
887
888 pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000889 if pACStatemachine != nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000890 if aEvent == aniEvStart {
891 if !pACStatemachine.Is(aniStDisabled) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000892 logger.Errorw(ctx, "wrong state of AniConfigFSM to start - want: Disabled", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000893 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000894 // maybe try a FSM reset and then again ... - TODO!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000895 return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000896 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000897 } else if !pACStatemachine.Is(aniStConfigDone) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000898 logger.Errorw(ctx, "wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000899 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000900 return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000901 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000902 //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config)
903 onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
904 if err := pACStatemachine.Event(aEvent); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000905 logger.Errorw(ctx, "AniConfigFSM: can't trigger event", log.Fields{"err": err})
mpagenko8b07c1b2020-11-26 10:36:31 +0000906 return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID)
907 }
908 /***** AniConfigFSM event notified */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000909 logger.Debugw(ctx, "AniConfigFSM event notified", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000910 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent})
911 return nil
mpagenko3dbcdd22020-07-22 07:38:45 +0000912 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000913 logger.Errorw(ctx, "AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000914 // maybe try a FSM reset and then again ... - TODO!!!
915 return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID)
mpagenkoaf801632020-07-03 10:00:42 +0000916}
mpagenkodff5dda2020-08-28 11:52:01 +0000917
Girish Gowdra041dcb32020-11-16 16:54:30 -0800918// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000919func (onuTP *onuUniTechProf) clearAniSideConfig(ctx context.Context, aUniID uint8, aTpID uint8) {
920 logger.Debugw(ctx, "removing TpIndication and PonAniConfig data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000921 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800922 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
923
924 onuTP.mutexTPState.Lock()
925 defer onuTP.mutexTPState.Unlock()
mpagenko73143992021-04-09 15:17:10 +0000926 //deleting a map entry should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800927 delete(onuTP.mapUniTpIndication, uniTpKey)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800928 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko73143992021-04-09 15:17:10 +0000929 delete(onuTP.procResult, uniTpKey)
930 delete(onuTP.tpProfileExists, uniTpKey)
931 delete(onuTP.tpProfileResetting, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000932}
933
mpagenkodff5dda2020-08-28 11:52:01 +0000934// setConfigDone sets the requested techProfile config state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800935func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
936 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
937 onuTP.mutexTPState.Lock()
938 defer onuTP.mutexTPState.Unlock()
939 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
940 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000941 } //else: the state is just ignored (does not exist)
942}
943
944// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
dbainbri4d3a0dc2020-12-02 00:33:42 +0000945func (onuTP *onuUniTechProf) getTechProfileDone(ctx context.Context, aUniID uint8, aTpID uint8) bool {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800946 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000947 onuTP.mutexTPState.RLock()
948 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800949 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
950 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
951 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000952 logger.Debugw(ctx, "TechProfile not relevant for requested flow config - waiting on delete",
mpagenko2418ab02020-11-12 12:58:06 +0000953 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
954 return false //still waiting for removal of this techProfile first
955 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800956 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000957 }
958 }
959 //for all other constellations indicate false = Config not done
960 return false
961}
mpagenko2418ab02020-11-12 12:58:06 +0000962
963// setProfileToDelete sets the requested techProfile toDelete state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800964func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
965 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
966 onuTP.mutexTPState.Lock()
967 defer onuTP.mutexTPState.Unlock()
968 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
969 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000970 } //else: the state is just ignored (does not exist)
971}
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300972
973// setProfileToDelete sets the requested techProfile toDelete state (if possible)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000974func (onuTP *onuUniTechProf) getMulticastGemPorts(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300975 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000976 onuTP.mutexTPState.RLock()
977 defer onuTP.mutexTPState.RUnlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300978 gemPortIds := make([]uint16, 0)
979 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
980 for _, gemPortParam := range techProfile.mapGemPortParams {
981 if gemPortParam.isMulticast {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000982 logger.Debugw(ctx, "Detected multicast gemPort", log.Fields{"device-id": onuTP.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300983 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
984 "mcastGemId": gemPortParam.multicastGemPortID})
985 gemPortIds = append(gemPortIds, gemPortParam.multicastGemPortID)
986 }
987 }
988 } //else: the state is just ignored (does not exist)
989 return gemPortIds
990}
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800991
992func (onuTP *onuUniTechProf) GetAllBidirectionalGemPortIDsForOnu() []uint16 {
993 var gemPortInstIDs []uint16
994 onuTP.mutexTPState.RLock()
995 defer onuTP.mutexTPState.RUnlock()
996 for _, tcontGemList := range onuTP.mapPonAniConfig {
997 for gemPortID, gemPortData := range tcontGemList.mapGemPortParams {
998 if gemPortData != nil && !gemPortData.isMulticast { // only if not multicast gem port
999 gemPortInstIDs = append(gemPortInstIDs, gemPortID)
1000 }
1001 }
1002 }
1003 return gemPortInstIDs
1004}
mpagenko73143992021-04-09 15:17:10 +00001005
1006// setProfileResetting sets/resets the indication, that a reset of the TechProfileConfig/Removal is ongoing
1007func (onuTP *onuUniTechProf) setProfileResetting(ctx context.Context, aUniID uint8, aTpID uint8, aState bool) {
1008 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
1009 onuTP.mutexTPState.Lock()
1010 defer onuTP.mutexTPState.Unlock()
1011 onuTP.tpProfileResetting[uniTpKey] = aState
1012}
1013
1014// getProfileResetting returns true, if the the according indication for started reset procedure is set
1015func (onuTP *onuUniTechProf) getProfileResetting(aUniTpKey uniTP) bool {
1016 onuTP.mutexTPState.RLock()
1017 defer onuTP.mutexTPState.RUnlock()
1018 if isResetting, exist := onuTP.tpProfileResetting[aUniTpKey]; exist {
1019 return isResetting
1020 }
1021 return false
1022}