blob: 1e3f9af20b7585256e4b452b3fc3ac40d12d4017 [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"
Andrea Campanella6515c582020-10-05 11:25:00 +020022 "fmt"
ozgecanetsia4b232302020-11-11 10:58:10 +030023 "strconv"
mpagenko3dbcdd22020-07-22 07:38:45 +000024 "strings"
mpagenkoaf801632020-07-03 10:00:42 +000025 "sync"
26
khenaidoo7d3c5582021-08-11 18:09:44 -040027 "github.com/opencord/voltha-lib-go/v7/pkg/log"
28 "github.com/opencord/voltha-protos/v5/go/tech_profile"
mpagenkoaf801632020-07-03 10:00:42 +000029)
30
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000031//definitions for TechProfileProcessing - copied from OltAdapter:openolt_flowmgr.go
32// could perhaps be defined more globally
33const (
Himani Chawla6d2ae152020-09-02 13:11:20 +053034 // binaryStringPrefix is binary string prefix
35 binaryStringPrefix = "0b"
36 // binaryBit1 is binary bit 1 expressed as a character
37 //binaryBit1 = '1'
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000038)
mpagenkoaf801632020-07-03 10:00:42 +000039
40type resourceEntry int
41
42const (
43 cResourceGemPort resourceEntry = 1
44 cResourceTcont resourceEntry = 2
45)
46
mpagenko3dbcdd22020-07-22 07:38:45 +000047type tTechProfileIndication struct {
mpagenkodff5dda2020-08-28 11:52:01 +000048 techProfileType string
Girish Gowdra041dcb32020-11-16 16:54:30 -080049 techProfileID uint8
mpagenkodff5dda2020-08-28 11:52:01 +000050 techProfileConfigDone bool
mpagenko2418ab02020-11-12 12:58:06 +000051 techProfileToDelete bool
mpagenko3dbcdd22020-07-22 07:38:45 +000052}
53
54type tcontParamStruct struct {
55 allocID uint16
56 schedPolicy uint8
57}
58type gemPortParamStruct struct {
Himani Chawla4d908332020-08-31 12:30:20 +053059 //ponOmciCC bool
mpagenko3dbcdd22020-07-22 07:38:45 +000060 gemPortID uint16
61 direction uint8
62 gemPortEncState uint8
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000063 prioQueueIndex uint8
64 pbitString string
mpagenko3dbcdd22020-07-22 07:38:45 +000065 discardPolicy string
Himani Chawla4d908332020-08-31 12:30:20 +053066 //could also be a queue specific parameter, not used that way here
67 //maxQueueSize uint16
mpagenko3dbcdd22020-07-22 07:38:45 +000068 queueSchedPolicy string
69 queueWeight uint8
Himani Chawla1c136902020-12-10 16:30:59 +053070 removeGemID uint16
ozgecanetsia4b232302020-11-11 10:58:10 +030071 isMulticast bool
72 //TODO check if this has any value/difference from gemPortId
73 multicastGemPortID uint16
74 staticACL string
75 dynamicACL string
mpagenko3dbcdd22020-07-22 07:38:45 +000076}
77
78//refers to one tcont and its properties and all assigned GemPorts and their properties
79type tcontGemList struct {
80 tcontParams tcontParamStruct
81 mapGemPortParams map[uint16]*gemPortParamStruct
82}
83
Girish Gowdra041dcb32020-11-16 16:54:30 -080084// refers a unique combination of uniID and tpID for a given ONU.
85type uniTP struct {
86 uniID uint8
87 tpID uint8
88}
mpagenko3dbcdd22020-07-22 07:38:45 +000089
Himani Chawla6d2ae152020-09-02 13:11:20 +053090//onuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU
91type onuUniTechProf struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053092 baseDeviceHandler *deviceHandler
mpagenko01e726e2020-10-23 09:45:29 +000093 deviceID string
mpagenkodff5dda2020-08-28 11:52:01 +000094 tpProcMutex sync.RWMutex
mpagenkodff5dda2020-08-28 11:52:01 +000095 chTpConfigProcessingStep chan uint8
Girish Gowdra041dcb32020-11-16 16:54:30 -080096 mapUniTpIndication map[uniTP]*tTechProfileIndication //use pointer values to ease assignments to the map
97 mapPonAniConfig map[uniTP]*tcontGemList //per UNI: use pointer values to ease assignments to the map
98 pAniConfigFsm map[uniTP]*uniPonAniConfigFsm
99 procResult map[uniTP]error //error indication of processing
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800100 mutexTPState sync.RWMutex
Girish Gowdra041dcb32020-11-16 16:54:30 -0800101 tpProfileExists map[uniTP]bool
mpagenko73143992021-04-09 15:17:10 +0000102 tpProfileResetting map[uniTP]bool
mpagenko8b07c1b2020-11-26 10:36:31 +0000103 mapRemoveGemEntry map[uniTP]*gemPortParamStruct //per UNI: pointer to GemEntry to be removed
mpagenkoaf801632020-07-03 10:00:42 +0000104}
105
ozgecanetsia72e1c9f2021-05-26 17:26:29 +0300106func (onuTP *onuUniTechProf) multicastConfiguredForOtherUniTps(ctx context.Context, uniTpKey uniTP) bool {
107 for _, aniFsm := range onuTP.pAniConfigFsm {
108 if aniFsm.uniTpKey.uniID == uniTpKey.uniID && aniFsm.uniTpKey.tpID == uniTpKey.tpID {
109 continue
110 }
111 if aniFsm.hasMulticastGem(ctx) {
112 return true
113 }
114 }
115 return false
116}
117
Himani Chawla6d2ae152020-09-02 13:11:20 +0530118//newOnuUniTechProf returns the instance of a OnuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000119//(one instance per ONU/deviceHandler for all possible UNI's)
mpagenko01e726e2020-10-23 09:45:29 +0000120func newOnuUniTechProf(ctx context.Context, aDeviceHandler *deviceHandler) *onuUniTechProf {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000121 logger.Debugw(ctx, "init-OnuUniTechProf", log.Fields{"device-id": aDeviceHandler.deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530122 var onuTP onuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000123 onuTP.baseDeviceHandler = aDeviceHandler
mpagenko01e726e2020-10-23 09:45:29 +0000124 onuTP.deviceID = aDeviceHandler.deviceID
mpagenkodff5dda2020-08-28 11:52:01 +0000125 onuTP.chTpConfigProcessingStep = make(chan uint8)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800126 onuTP.mapUniTpIndication = make(map[uniTP]*tTechProfileIndication)
127 onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList)
128 onuTP.procResult = make(map[uniTP]error)
129 onuTP.tpProfileExists = make(map[uniTP]bool)
mpagenko73143992021-04-09 15:17:10 +0000130 onuTP.tpProfileResetting = make(map[uniTP]bool)
mpagenko8b07c1b2020-11-26 10:36:31 +0000131 onuTP.mapRemoveGemEntry = make(map[uniTP]*gemPortParamStruct)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000132
mpagenkoaf801632020-07-03 10:00:42 +0000133 return &onuTP
134}
135
136// lockTpProcMutex locks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530137func (onuTP *onuUniTechProf) lockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000138 onuTP.tpProcMutex.Lock()
139}
140
141// unlockTpProcMutex unlocks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530142func (onuTP *onuUniTechProf) unlockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000143 onuTP.tpProcMutex.Unlock()
144}
145
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000146// resetTpProcessingErrorIndication resets the internal error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000147// need to be called before evaluation of any subsequent processing (given by waitForTpCompletion())
Girish Gowdra041dcb32020-11-16 16:54:30 -0800148func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) {
mpagenko73143992021-04-09 15:17:10 +0000149 onuTP.mutexTPState.Lock()
150 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800151 onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000152}
153
Girish Gowdra041dcb32020-11-16 16:54:30 -0800154func (onuTP *onuUniTechProf) getTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error {
mpagenko73143992021-04-09 15:17:10 +0000155 onuTP.mutexTPState.RLock()
156 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800157 return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}]
mpagenko3dbcdd22020-07-22 07:38:45 +0000158}
159
mpagenko8b07c1b2020-11-26 10:36:31 +0000160// configureUniTp checks existing tp resources to configure and starts the corresponding OMCI configuation of the UNI port
mpagenko3dbcdd22020-07-22 07:38:45 +0000161// all possibly blocking processing must be run in background to allow for deadline supervision!
162// but take care on sequential background processing when needed (logical dependencies)
Himani Chawla4d908332020-08-31 12:30:20 +0530163// use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization
Himani Chawla6d2ae152020-09-02 13:11:20 +0530164func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context,
Girish Gowdra50e56422021-06-01 16:46:04 -0700165 aUniID uint8, aPathString string, tpInst tech_profile.TechProfileInstance, wg *sync.WaitGroup) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000166 defer wg.Done() //always decrement the waitGroup on return
dbainbri4d3a0dc2020-12-02 00:33:42 +0000167 logger.Debugw(ctx, "configure the Uni according to TpPath", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000168 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800169 tpID, err := GetTpIDFromTpPath(aPathString)
170 uniTpKey := uniTP{uniID: aUniID, tpID: tpID}
171 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000172 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 -0800173 return
174 }
mpagenkoaf801632020-07-03 10:00:42 +0000175
mpagenko3dbcdd22020-07-22 07:38:45 +0000176 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530177 var pCurrentUniPort *onuUniPort
mpagenko3dbcdd22020-07-22 07:38:45 +0000178 for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap {
179 // only if this port is validated for operState transfer
Girish Gowdra041dcb32020-11-16 16:54:30 -0800180 if uniPort.uniID == aUniID {
mpagenko3dbcdd22020-07-22 07:38:45 +0000181 pCurrentUniPort = uniPort
182 break //found - end search loop
183 }
184 }
185 if pCurrentUniPort == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000186 logger.Errorw(ctx, "TechProfile configuration aborted: requested uniID not found in PortDB",
mpagenko73143992021-04-09 15:17:10 +0000187 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
188 onuTP.mutexTPState.Lock()
189 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800190 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200191 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000192 return
193 }
mpagenkoaf801632020-07-03 10:00:42 +0000194
mpagenko73143992021-04-09 15:17:10 +0000195 if onuTP.getProfileResetting(uniTpKey) {
196 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
197 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
198 onuTP.mutexTPState.Lock()
199 defer onuTP.mutexTPState.Unlock()
200 onuTP.procResult[uniTpKey] = fmt.Errorf(
201 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
202 aUniID, onuTP.deviceID)
203 return
204 }
mpagenkodff5dda2020-08-28 11:52:01 +0000205 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
mpagenkoaf801632020-07-03 10:00:42 +0000206
mpagenko3dbcdd22020-07-22 07:38:45 +0000207 //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called
208 // in case the KVPath has changed for the given UNI,
209 // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
210 // (ANI) configuration of this port has to be removed first
211 // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
212 // existence of configuration can be detected based on tp stored TCONT's
Andrea Campanella6515c582020-10-05 11:25:00 +0200213 //TODO:
mpagenko3dbcdd22020-07-22 07:38:45 +0000214 /* if tcontMap not empty {
215 go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000216 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000217 //timeout or error detected
218 return
219 }
220 clear tcontMap
221 }
222
223 processingStep++
224 */
Girish Gowdra50e56422021-06-01 16:46:04 -0700225 go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, tpInst, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000226 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000227 //timeout or error detected
mpagenko73143992021-04-09 15:17:10 +0000228 onuTP.mutexTPState.RLock()
Girish Gowdra24dd1132021-07-06 15:25:40 -0700229 ok := onuTP.tpProfileExists[uniTpKey]
230 onuTP.mutexTPState.RUnlock()
231 if ok {
mpagenko01e726e2020-10-23 09:45:29 +0000232 //ignore the internal error in case the new profile is already configured
233 // and abort the processing here
234 return
235 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000236 logger.Errorw(ctx, "tech-profile related configuration aborted on read",
mpagenko01e726e2020-10-23 09:45:29 +0000237 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000238 onuTP.mutexTPState.Lock()
239 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800240 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200241 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000242 return
243 }
mpagenko73143992021-04-09 15:17:10 +0000244 if onuTP.getProfileResetting(uniTpKey) {
245 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
246 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
247 onuTP.mutexTPState.Lock()
248 defer onuTP.mutexTPState.Unlock()
249 onuTP.procResult[uniTpKey] = fmt.Errorf(
250 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
251 aUniID, onuTP.deviceID)
252 return
253 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000254 processingStep++
Girish Gowdra041dcb32020-11-16 16:54:30 -0800255
mpagenko73143992021-04-09 15:17:10 +0000256 //ensure read protection for access to mapPonAniConfig
257 onuTP.mutexTPState.RLock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800258 valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey]
mpagenko73143992021-04-09 15:17:10 +0000259 onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800260 if existPA {
261 if valuePA != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000262 //Config data for this uni and and at least TCont Index 0 exist
mpagenko8b07c1b2020-11-26 10:36:31 +0000263 if err := onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000264 logger.Errorw(ctx, "tech-profile related FSM could not be started",
mpagenko8b07c1b2020-11-26 10:36:31 +0000265 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000266 onuTP.mutexTPState.Lock()
267 defer onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000268 onuTP.procResult[uniTpKey] = err
269 return
270 }
mpagenkodff5dda2020-08-28 11:52:01 +0000271 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000272 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
273 logger.Warnw(ctx, "tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000274 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800275
mpagenko73143992021-04-09 15:17:10 +0000276 onuTP.mutexTPState.Lock()
277 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800278 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200279 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530280 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000281 //which requires to reset it to allow for new usage, e.g. also on a different UNI
282 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000283 if _, ok := onuTP.pAniConfigFsm[uniTpKey]; ok {
284 _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset)
285 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000286 return
mpagenkoaf801632020-07-03 10:00:42 +0000287 }
288 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000289 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000290 logger.Errorw(ctx, "no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000291 "device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000292 onuTP.mutexTPState.Lock()
293 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800294 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 +0200295 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000296 return
mpagenkoaf801632020-07-03 10:00:42 +0000297 }
298 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000299 logger.Errorw(ctx, "no PonAni data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000300 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800301
mpagenko73143992021-04-09 15:17:10 +0000302 onuTP.mutexTPState.Lock()
303 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800304 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 +0200305 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000306 return
mpagenkoaf801632020-07-03 10:00:42 +0000307 }
308}
309
mpagenko3dbcdd22020-07-22 07:38:45 +0000310/* internal methods *********************/
ozgecanetsia4b232302020-11-11 10:58:10 +0300311// nolint: gocyclo
Himani Chawla6d2ae152020-09-02 13:11:20 +0530312func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile(
Girish Gowdra50e56422021-06-01 16:46:04 -0700313 ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, tpInst tech_profile.TechProfileInstance, aProcessingStep uint8) {
314 var err error
mpagenko3dbcdd22020-07-22 07:38:45 +0000315 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
316 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
317 subStringSlice := strings.Split(aPathString, "/")
318 if len(subStringSlice) <= 2 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000319 logger.Errorw(ctx, "invalid path name format",
mpagenko3dbcdd22020-07-22 07:38:45 +0000320 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000321 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000322 return
323 }
324
mpagenko73143992021-04-09 15:17:10 +0000325 //ensure write protection for access to used maps
326 onuTP.mutexTPState.Lock()
327 defer onuTP.mutexTPState.Unlock()
328
329 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
330 onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false
331
mpagenko3dbcdd22020-07-22 07:38:45 +0000332 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000333 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
334 // then we throw a warning, set an internal error and abort with error,
335 // which is later re-defined to success response to OLT adapter
336 // if TPId has changed, current data is removed (note that the ONU config state may be
337 // ambivalent in such a case)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800338 if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000339 logger.Warnw(ctx, "Some active profile entry at reading new TechProfile",
mpagenko3dbcdd22020-07-22 07:38:45 +0000340 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800341 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
342 if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID {
mpagenko01e726e2020-10-23 09:45:29 +0000343 // ProfId not changed - assume profile to be still the same
344 // anyway this should not appear after full support of profile (Gem/TCont) removal
dbainbri4d3a0dc2020-12-02 00:33:42 +0000345 logger.Warnw(ctx, "New TechProfile already exists - aborting configuration",
mpagenko01e726e2020-10-23 09:45:29 +0000346 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800347 onuTP.tpProfileExists[uniTPKey] = true
mpagenko01e726e2020-10-23 09:45:29 +0000348 onuTP.chTpConfigProcessingStep <- 0 //error indication
349 return
350 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000351 //delete on the mapUniTpIndication map not needed, just overwritten later
352 //delete on the PonAniConfig map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800353 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenko3dbcdd22020-07-22 07:38:45 +0000354 } else {
355 // this is normal processing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800356 onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
mpagenko3dbcdd22020-07-22 07:38:45 +0000357 }
358
Girish Gowdra041dcb32020-11-16 16:54:30 -0800359 onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000360 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
Girish Gowdra041dcb32020-11-16 16:54:30 -0800361 onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID
362 onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false
363 onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000364 logger.Debugw(ctx, "tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000365 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800366 "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType,
367 "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000368
mpagenko01e726e2020-10-23 09:45:29 +0000369 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000370 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800371 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000372
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000373 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000374 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra50e56422021-06-01 16:46:04 -0700375 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocId)
Himani Chawla4d908332020-08-31 12:30:20 +0530376 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000377 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
Girish Gowdra50e56422021-06-01 16:46:04 -0700378 if tpInst.UsScheduler.QSchedPolicy == tech_profile.SchedulingPolicy_StrictPriority {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800379 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000380 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000381 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800382 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000383 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000384 loNumGemPorts := tpInst.NumGemPorts
385 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000386 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000387 if uint32(pos) == loNumGemPorts {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000388 logger.Debugw(ctx, "PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
mpagenko1cc3cb42020-07-27 15:24:38 +0000389 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000390 break
391 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000392 if pos == 0 {
393 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
394 loGemPortRead = true
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000395 }
Himani Chawla1c136902020-12-10 16:30:59 +0530396 //for all GemPorts we need to extend the mapGemPortParams
Girish Gowdra50e56422021-06-01 16:46:04 -0700397 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)] = &gemPortParamStruct{}
Himani Chawla1c136902020-12-10 16:30:59 +0530398
Girish Gowdra50e56422021-06-01 16:46:04 -0700399 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortID =
400 uint16(content.GemportId)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000401 //direction can be correlated later with Downstream list,
402 // for now just assume bidirectional (upstream never exists alone)
Girish Gowdra50e56422021-06-01 16:46:04 -0700403 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000404 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
Girish Gowdra50e56422021-06-01 16:46:04 -0700405 if content.PriorityQ > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000406 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Girish Gowdra50e56422021-06-01 16:46:04 -0700407 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQ})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000408 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800409 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000410 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000411 return
412 }
Girish Gowdra50e56422021-06-01 16:46:04 -0700413 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].prioQueueIndex =
414 uint8(content.PriorityQ)
415 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530416 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000417 if content.AesEncryption == "True" {
Girish Gowdra50e56422021-06-01 16:46:04 -0700418 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000419 } else {
Girish Gowdra50e56422021-06-01 16:46:04 -0700420 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000421 }
Girish Gowdra50e56422021-06-01 16:46:04 -0700422 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].discardPolicy =
423 content.DiscardPolicy.String()
424 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].queueSchedPolicy =
425 content.SchedulingPolicy.String()
mpagenko3dbcdd22020-07-22 07:38:45 +0000426 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Girish Gowdra50e56422021-06-01 16:46:04 -0700427 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000428 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000429 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300430
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300431 for _, downstreamContent := range tpInst.DownstreamGemPortAttributeList {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000432 logger.Debugw(ctx, "Operating on Downstream Gem Port", log.Fields{"downstream-gem": downstreamContent})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300433 //Commenting this out due to faliure, needs investigation
434 //if uint32(pos) == loNumGemPorts {
435 // logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
436 // log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
437 // break
438 //}
439 isMulticast := false
ozgecanetsia4b232302020-11-11 10:58:10 +0300440 //Flag is defined as string in the TP in voltha-lib-go, parsing it from string
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300441 if downstreamContent.IsMulticast != "" {
442 isMulticast, err = strconv.ParseBool(downstreamContent.IsMulticast)
443 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000444 logger.Errorw(ctx, "multicast-error-config-unknown-flag-in-technology-profile",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300445 log.Fields{"UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "error": err})
446 continue
447 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300448 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000449 logger.Infow(ctx, "Gem Port is multicast", log.Fields{"isMulticast": isMulticast})
ozgecanetsia4b232302020-11-11 10:58:10 +0300450 if isMulticast {
Girish Gowdra50e56422021-06-01 16:46:04 -0700451 mcastGemID := uint16(downstreamContent.MulticastGemId)
ozgecanetsia4b232302020-11-11 10:58:10 +0300452 _, existing := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID]
453 if existing {
454 //GEM port was previously configured, avoid setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000455 logger.Errorw(ctx, "multicast-error-config-existing-gem-port-config", log.Fields{"UniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300456 "downstream-gem": downstreamContent, "key": mcastGemID})
457 continue
458 } else {
459 //GEM port is not configured, setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000460 logger.Infow(ctx, "creating-multicast-gem-port", log.Fields{"uniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300461 "gemPortId": mcastGemID, "key": mcastGemID})
462
463 //for all further GemPorts we need to extend the mapGemPortParams
464 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID] = &gemPortParamStruct{}
465
466 //Separate McastGemId is derived from OMCI-lib-go, if not needed first needs to be removed there.
467 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortID = mcastGemID
468 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].direction = 2 // for ANI to UNI as defined in G.988
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300469
470 if downstreamContent.AesEncryption == "True" {
471 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 1
472 } else {
473 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 0
474 }
475
476 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
Girish Gowdra50e56422021-06-01 16:46:04 -0700477 if downstreamContent.PriorityQ > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000478 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Girish Gowdra50e56422021-06-01 16:46:04 -0700479 log.Fields{"device-id": onuTP.deviceID, "index": mcastGemID, "PrioQueue": downstreamContent.PriorityQ})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300480 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
481 delete(onuTP.mapPonAniConfig, uniTPKey)
482 onuTP.chTpConfigProcessingStep <- 0 //error indication
483 return
ozgecanetsia4b232302020-11-11 10:58:10 +0300484 }
485 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].prioQueueIndex =
Girish Gowdra50e56422021-06-01 16:46:04 -0700486 uint8(downstreamContent.PriorityQ)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300487 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].pbitString =
488 strings.TrimPrefix(downstreamContent.PbitMap, binaryStringPrefix)
489
490 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].discardPolicy =
Girish Gowdra50e56422021-06-01 16:46:04 -0700491 downstreamContent.DiscardPolicy.String()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300492 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueSchedPolicy =
Girish Gowdra50e56422021-06-01 16:46:04 -0700493 downstreamContent.SchedulingPolicy.String()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300494 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
495 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueWeight =
496 uint8(downstreamContent.Weight)
497
ozgecanetsia4b232302020-11-11 10:58:10 +0300498 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].isMulticast = isMulticast
499 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].multicastGemPortID =
Girish Gowdra50e56422021-06-01 16:46:04 -0700500 uint16(downstreamContent.MulticastGemId)
501 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].staticACL = downstreamContent.StaticAccessControlList
502 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].dynamicACL = downstreamContent.DynamicAccessControlList
ozgecanetsia4b232302020-11-11 10:58:10 +0300503 }
504 }
505 }
506
Himani Chawla4d908332020-08-31 12:30:20 +0530507 if !loGemPortRead {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000508 logger.Errorw(ctx, "PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000509 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000510 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800511 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000512 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000513 return
514 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000515 //logger does not simply output the given structures, just give some example debug values
dbainbri4d3a0dc2020-12-02 00:33:42 +0000516 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000517 "device-id": onuTP.deviceID, "uni-id": aUniID,
518 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
Himani Chawla1c136902020-12-10 16:30:59 +0530519 for gemPortID, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000520 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530521 "GemPort": gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000522 "QueueScheduling": gemEntry.queueSchedPolicy})
523 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000524
mpagenkodff5dda2020-08-28 11:52:01 +0000525 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000526}
527
Himani Chawla6d2ae152020-09-02 13:11:20 +0530528func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
mpagenko8b07c1b2020-11-26 10:36:31 +0000529 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000530
531 //OMCI transfer of ANI data acc. to mapPonAniConfig
532 // also the FSM's are running in background,
mpagenko8b07c1b2020-11-26 10:36:31 +0000533 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800534 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko3dbcdd22020-07-22 07:38:45 +0000535 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000536 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800537 } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000538 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000539 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000540 //AniConfigFsm already init
dbainbri4d3a0dc2020-12-02 00:33:42 +0000541 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000542}
543
544// deleteTpResource removes Resources from the ONU's specified Uni
mpagenko73143992021-04-09 15:17:10 +0000545// nolint: gocyclo
mpagenko8b07c1b2020-11-26 10:36:31 +0000546func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context,
547 aUniID uint8, aTpID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
548 wg *sync.WaitGroup) {
549 defer wg.Done()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000550 logger.Debugw(ctx, "will remove TP resources from ONU's UNI", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000551 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "Resource": aResource})
552 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
553
554 if cResourceGemPort == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000555 logger.Debugw(ctx, "remove GemPort from the list of existing ones of the TP", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000556 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID})
557
mpagenko73143992021-04-09 15:17:10 +0000558 //ensure read protection for access to mapPonAniConfig
559 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000560 // check if the requested GemPort exists in the DB, indicate it to the FSM
561 // store locally to remove it from DB later on success
562 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
563 if pLocAniConfigOnUni == nil {
mpagenko73143992021-04-09 15:17:10 +0000564 onuTP.mutexTPState.RUnlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000565 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000566 logger.Debugw(ctx, "AniConfig or GemEntry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000567 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
568 return
569 }
mpagenko73143992021-04-09 15:17:10 +0000570 onuTP.mutexTPState.RUnlock()
571
Himani Chawla1c136902020-12-10 16:30:59 +0530572 for gemPortID, gemEntry := range pLocAniConfigOnUni.mapGemPortParams {
573 if gemPortID == uint16(aEntryID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000574 //GemEntry to be deleted found
Himani Chawla1c136902020-12-10 16:30:59 +0530575 gemEntry.removeGemID = gemPortID //store the index for later removal
576 onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemPortID]
dbainbri4d3a0dc2020-12-02 00:33:42 +0000577 logger.Debugw(ctx, "Remove-GemEntry stored", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530578 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000579 break //abort loop, always only one GemPort to remove
580 }
581 }
582 if onuTP.mapRemoveGemEntry[uniTPKey] == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000583 logger.Errorw(ctx, "GemPort removal aborted - GemPort not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000584 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
585 /* Do not set some error indication to the outside system interface on delete
586 assume there is nothing to be deleted internally and hope a new config request will recover the situation
587 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s",
588 aEntryID, aUniID, onuTP.deviceID)
589 */
590 return
591 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000592 if onuTP.baseDeviceHandler.isReadyForOmciConfig() {
mpagenko8b07c1b2020-11-26 10:36:31 +0000593 // check that the TpConfigRequest was done before
594 // -> that is implicitly done using the AniConfigFsm,
595 // which must be in the according state to remove something
mpagenko8b07c1b2020-11-26 10:36:31 +0000596 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000597 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000598 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
599 /* Do not set some error indication to the outside system interface on delete (see above)
600 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s",
601 aUniID, onuTP.deviceID)
602 */
603 //if the FSM is not valid, also TP related remove data should not be valid:
604 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000605 //ensure write protection for access to mapPonAniConfig
606 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530607 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000608 // remove the removeEntry
609 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000610 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000611 return
612 }
613 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000614 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000615 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
616 /* Do not set some error indication to the outside system interface on delete (see above)
617 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid",
618 aUniID, onuTP.deviceID, aTpID)
619 */
620 //if the FSM is not valid, also TP related remove data should not be valid:
621 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000622 //ensure write protection for access to mapPonAniConfig
623 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530624 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000625 // remove the removeEntry
626 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000627 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000628 return
629 }
mpagenko73143992021-04-09 15:17:10 +0000630 if onuTP.getProfileResetting(uniTPKey) {
631 logger.Debugw(ctx, "aborting GemRemoval on FSM, reset requested in parallel", log.Fields{
632 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
633 //ensure write protection for access to mapPonAniConfig
634 onuTP.mutexTPState.Lock()
635 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
636 // remove the removeEntry
637 delete(onuTP.mapRemoveGemEntry, uniTPKey)
638 onuTP.mutexTPState.Unlock()
639 return
640 }
641 // initiate OMCI GemPort related removal
642 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
643 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000644 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemGemiw, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000645 //even if the FSM invocation did not work we don't indicate a problem within procResult
646 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
647 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
648 return
649 }
650 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000651 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
652 logger.Warnw(ctx, "GemPort removal aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000653 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
654 //even if the FSM delete execution did not work we don't indicate a problem within procResult
655 //we should never respond to delete with error ...
656 //this issue here means that the AniConfigFsm has not finished successfully
657 //which requires to reset it to allow for new usage, e.g. also on a different UNI
658 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000659 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok {
660 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
661 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000662 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
663 return
664 }
665 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000666 //if we can't do the OMCI processing we also suppress the ProcStatusUpdate
667 //this is needed as in the device-down case where all FSM's are getting reset and internal data gets cleared
668 //as a consequence a possible remove-flow does not see any dependency on the TechProfile anymore and is executed (pro forma) directly
669 //a later TechProfile removal would cause the device-reason to be updated to 'techProfile-delete-success' which is not the expected state
670 // and anyway is no real useful information at that stage
dbainbri4d3a0dc2020-12-02 00:33:42 +0000671 logger.Debugw(ctx, "uniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000672 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000673 }
674 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000675 //ensure write protection for access to mapPonAniConfig
Mahir Gunyel9545be22021-07-04 15:53:16 -0700676 logger.Debugw(ctx, "uniPonAniConfigFsm removing gem from config data and clearing ani FSM", log.Fields{
677 "device-id": onuTP.deviceID, "gem-id": onuTP.mapRemoveGemEntry[uniTPKey].removeGemID, "uniTPKey": uniTPKey})
mpagenko73143992021-04-09 15:17:10 +0000678 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530679 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000680 // remove the removeEntry
681 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000682 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000683 } else { //if cResourceTcont == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000684 logger.Debugw(ctx, "reset TCont with AllocId", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000685 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID})
686
mpagenko73143992021-04-09 15:17:10 +0000687 //ensure read protection for access to mapPonAniConfig
688 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000689 // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM
690 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
691 if pLocAniConfigOnUni == nil {
692 // No relevant entry exists anymore - acknowledge success
mpagenko73143992021-04-09 15:17:10 +0000693 onuTP.mutexTPState.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000694 logger.Debugw(ctx, "AniConfig or TCont entry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000695 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
696 return
697 }
mpagenko73143992021-04-09 15:17:10 +0000698 onuTP.mutexTPState.RUnlock()
699
mpagenko8b07c1b2020-11-26 10:36:31 +0000700 if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000701 logger.Errorw(ctx, "TCont removal aborted - indicated AllocId not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000702 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID})
703 /* Do not set some error indication to the outside system interface on delete
704 assume there is nothing to be deleted internally and hope a new config request will recover the situation
705 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s",
706 aEntryID, aUniID, onuTP.deviceID)
707 */
708 return
709 }
710 //T-Cont to be reset found
dbainbri4d3a0dc2020-12-02 00:33:42 +0000711 logger.Debugw(ctx, "Reset-T-Cont AllocId found - valid", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000712 "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID})
713 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000714 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000715 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
716 /* Do not set some error indication to the outside system interface on delete (see above)
717 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s",
718 aUniID, onuTP.deviceID)
719 */
mpagenko8b07c1b2020-11-26 10:36:31 +0000720 return
721 }
722 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000723 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000724 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
725 //even if the FSM invocation did not work we don't indicate a problem within procResult
726 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
727 //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data
mpagenko8b07c1b2020-11-26 10:36:31 +0000728 return
729 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000730 if onuTP.baseDeviceHandler.isReadyForOmciConfig() {
mpagenko8b07c1b2020-11-26 10:36:31 +0000731 // check that the TpConfigRequest was done before
732 // -> that is implicitly done using the AniConfigFsm,
733 // which must be in the according state to remove something
mpagenko73143992021-04-09 15:17:10 +0000734 if onuTP.getProfileResetting(uniTPKey) {
735 logger.Debugw(ctx, "aborting TCont removal on FSM, reset requested in parallel", log.Fields{
736 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
737 return
738 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000739 // initiate OMCI TCont related cleanup
740 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
741 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000742 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemTcontPath, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000743 //even if the FSM invocation did not work we don't indicate a problem within procResult
744 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
745 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
746 return
747 }
748 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000749 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
750 logger.Warnw(ctx, "TCont cleanup aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000751 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
752 //even if the FSM delete execution did not work we don't indicate a problem within procResult
753 //we should never respond to delete with error ...
754 //this issue here means that the AniConfigFsm has not finished successfully
755 //which requires to reset it to allow for new usage, e.g. also on a different UNI
756 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000757 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok {
758 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
759 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000760 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
761 return
762 }
763 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000764 //see gemPort comments
dbainbri4d3a0dc2020-12-02 00:33:42 +0000765 logger.Debugw(ctx, "uniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000766 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000767 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000768 }
Mahir Gunyel9545be22021-07-04 15:53:16 -0700769
770}
771
772func (onuTP *onuUniTechProf) isTechProfileConfigCleared(ctx context.Context, uniID uint8, tpID uint8) bool {
773 uniTPKey := uniTP{uniID: uniID, tpID: tpID}
774 logger.Debugw(ctx, "isTechProfileConfigCleared", log.Fields{"device-id": onuTP.deviceID})
775 if onuTP.mapPonAniConfig[uniTPKey] != nil {
776 mapGemPortParams := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams
777 unicastGemCount := 0
778 for _, gemEntry := range mapGemPortParams {
779 if !gemEntry.isMulticast {
780 unicastGemCount++
781 }
782 }
783 if unicastGemCount == 0 || onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID == 0 {
784 logger.Debugw(ctx, "clearing-ani-side-config", log.Fields{
785 "device-id": onuTP.deviceID, "uniTpKey": uniTPKey})
786 onuTP.clearAniSideConfig(ctx, uniID, tpID)
787 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok {
788 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
789 }
790 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(ctx, OmciAniResourceRemoved)
791 return true
792 }
mpagenko7d6bb022021-03-11 15:07:55 +0000793 }
Mahir Gunyel9545be22021-07-04 15:53:16 -0700794 return false
mpagenko3dbcdd22020-07-22 07:38:45 +0000795}
796
Himani Chawla6d2ae152020-09-02 13:11:20 +0530797func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000798 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000799 select {
800 case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000801 logger.Warnw(ctx, "processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000802 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000803 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000804 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000805 if rxStep == aProcessingStep {
806 return true
807 }
808 //all other values are not accepted - including 0 for error indication
dbainbri4d3a0dc2020-12-02 00:33:42 +0000809 logger.Warnw(ctx, "Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000810 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000811 "wantedStep": aProcessingStep, "haveStep": rxStep})
812 return false
813 }
814}
815
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000816// createAniConfigFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000817func (onuTP *onuUniTechProf) createAniConfigFsm(ctx context.Context, aUniID uint8, aTpID uint8,
mpagenko8b07c1b2020-11-26 10:36:31 +0000818 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000819 logger.Debugw(ctx, "createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000820 chAniConfigFsm := make(chan Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800821 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000822 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(ctx, true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000823 if pDevEntry == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000824 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000825 return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000826 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000827 pAniCfgFsm := newUniPonAniConfigFsm(ctx, pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800828 pDevEntry.pOnuDB, aTpID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000829 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko8b07c1b2020-11-26 10:36:31 +0000830 if pAniCfgFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000831 logger.Errorw(ctx, "AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000832 return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000833 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000834 if onuTP.pAniConfigFsm == nil {
835 onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800836 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000837 onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm
dbainbri4d3a0dc2020-12-02 00:33:42 +0000838 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000839}
840
mpagenko3dbcdd22020-07-22 07:38:45 +0000841// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000842func (onuTP *onuUniTechProf) runAniConfigFsm(ctx context.Context, aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000843 /* Uni related ANI config procedure -
844 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
845 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800846 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
847
848 pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000849 if pACStatemachine != nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000850 if aEvent == aniEvStart {
851 if !pACStatemachine.Is(aniStDisabled) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000852 logger.Errorw(ctx, "wrong state of AniConfigFSM to start - want: Disabled", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000853 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000854 // maybe try a FSM reset and then again ... - TODO!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000855 return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000856 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000857 } else if !pACStatemachine.Is(aniStConfigDone) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000858 logger.Errorw(ctx, "wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000859 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000860 return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000861 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000862 //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config)
863 onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
864 if err := pACStatemachine.Event(aEvent); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000865 logger.Errorw(ctx, "AniConfigFSM: can't trigger event", log.Fields{"err": err})
mpagenko8b07c1b2020-11-26 10:36:31 +0000866 return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID)
867 }
868 /***** AniConfigFSM event notified */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000869 logger.Debugw(ctx, "AniConfigFSM event notified", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000870 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent})
871 return nil
mpagenko3dbcdd22020-07-22 07:38:45 +0000872 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000873 logger.Errorw(ctx, "AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000874 // maybe try a FSM reset and then again ... - TODO!!!
875 return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID)
mpagenkoaf801632020-07-03 10:00:42 +0000876}
mpagenkodff5dda2020-08-28 11:52:01 +0000877
Girish Gowdra041dcb32020-11-16 16:54:30 -0800878// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000879func (onuTP *onuUniTechProf) clearAniSideConfig(ctx context.Context, aUniID uint8, aTpID uint8) {
880 logger.Debugw(ctx, "removing TpIndication and PonAniConfig data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000881 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800882 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
883
884 onuTP.mutexTPState.Lock()
885 defer onuTP.mutexTPState.Unlock()
mpagenko73143992021-04-09 15:17:10 +0000886 //deleting a map entry should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800887 delete(onuTP.mapUniTpIndication, uniTpKey)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800888 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko73143992021-04-09 15:17:10 +0000889 delete(onuTP.procResult, uniTpKey)
890 delete(onuTP.tpProfileExists, uniTpKey)
891 delete(onuTP.tpProfileResetting, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000892}
893
mpagenkodff5dda2020-08-28 11:52:01 +0000894// setConfigDone sets the requested techProfile config state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800895func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
896 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
897 onuTP.mutexTPState.Lock()
898 defer onuTP.mutexTPState.Unlock()
899 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
900 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000901 } //else: the state is just ignored (does not exist)
902}
903
904// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
dbainbri4d3a0dc2020-12-02 00:33:42 +0000905func (onuTP *onuUniTechProf) getTechProfileDone(ctx context.Context, aUniID uint8, aTpID uint8) bool {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800906 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000907 onuTP.mutexTPState.RLock()
908 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800909 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
910 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
911 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000912 logger.Debugw(ctx, "TechProfile not relevant for requested flow config - waiting on delete",
mpagenko2418ab02020-11-12 12:58:06 +0000913 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
914 return false //still waiting for removal of this techProfile first
915 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800916 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000917 }
918 }
919 //for all other constellations indicate false = Config not done
920 return false
921}
mpagenko2418ab02020-11-12 12:58:06 +0000922
923// setProfileToDelete sets the requested techProfile toDelete state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800924func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
925 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
926 onuTP.mutexTPState.Lock()
927 defer onuTP.mutexTPState.Unlock()
928 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
929 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000930 } //else: the state is just ignored (does not exist)
931}
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300932
933// setProfileToDelete sets the requested techProfile toDelete state (if possible)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000934func (onuTP *onuUniTechProf) getMulticastGemPorts(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300935 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000936 onuTP.mutexTPState.RLock()
937 defer onuTP.mutexTPState.RUnlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300938 gemPortIds := make([]uint16, 0)
939 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
940 for _, gemPortParam := range techProfile.mapGemPortParams {
941 if gemPortParam.isMulticast {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000942 logger.Debugw(ctx, "Detected multicast gemPort", log.Fields{"device-id": onuTP.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300943 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
944 "mcastGemId": gemPortParam.multicastGemPortID})
945 gemPortIds = append(gemPortIds, gemPortParam.multicastGemPortID)
946 }
947 }
948 } //else: the state is just ignored (does not exist)
949 return gemPortIds
950}
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800951
ozgecanetsia82b91a62021-05-21 18:54:49 +0300952func (onuTP *onuUniTechProf) getBidirectionalGemPortIDsForTP(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
953 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
954 onuTP.mutexTPState.RLock()
955 defer onuTP.mutexTPState.RUnlock()
956 gemPortIds := make([]uint16, 0)
957 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
958 logger.Debugw(ctx, "TechProfile exist", log.Fields{"device-id": onuTP.deviceID})
959 for _, gemPortParam := range techProfile.mapGemPortParams {
960 if !gemPortParam.isMulticast {
961 logger.Debugw(ctx, "Detected unicast gemPort", log.Fields{"device-id": onuTP.deviceID,
962 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
963 "GemId": gemPortParam.multicastGemPortID})
964 gemPortIds = append(gemPortIds, gemPortParam.gemPortID)
965 }
966 }
967 } else {
968 logger.Debugw(ctx, "TechProfile doesn't exist", log.Fields{"device-id": onuTP.deviceID})
969 } //else: the state is just ignored (does not exist)
970 logger.Debugw(ctx, "Gem PortID list", log.Fields{"device-id": onuTP.deviceID, "gemportList": gemPortIds})
971 return gemPortIds
972}
973
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800974func (onuTP *onuUniTechProf) GetAllBidirectionalGemPortIDsForOnu() []uint16 {
975 var gemPortInstIDs []uint16
976 onuTP.mutexTPState.RLock()
977 defer onuTP.mutexTPState.RUnlock()
978 for _, tcontGemList := range onuTP.mapPonAniConfig {
979 for gemPortID, gemPortData := range tcontGemList.mapGemPortParams {
980 if gemPortData != nil && !gemPortData.isMulticast { // only if not multicast gem port
981 gemPortInstIDs = append(gemPortInstIDs, gemPortID)
982 }
983 }
984 }
985 return gemPortInstIDs
986}
mpagenko73143992021-04-09 15:17:10 +0000987
988// setProfileResetting sets/resets the indication, that a reset of the TechProfileConfig/Removal is ongoing
989func (onuTP *onuUniTechProf) setProfileResetting(ctx context.Context, aUniID uint8, aTpID uint8, aState bool) {
990 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
991 onuTP.mutexTPState.Lock()
992 defer onuTP.mutexTPState.Unlock()
993 onuTP.tpProfileResetting[uniTpKey] = aState
994}
995
996// getProfileResetting returns true, if the the according indication for started reset procedure is set
997func (onuTP *onuUniTechProf) getProfileResetting(aUniTpKey uniTP) bool {
998 onuTP.mutexTPState.RLock()
999 defer onuTP.mutexTPState.RUnlock()
1000 if isResetting, exist := onuTP.tpProfileResetting[aUniTpKey]; exist {
1001 return isResetting
1002 }
1003 return false
1004}