blob: 6e365abbf7809b0be3a48460eb638e1467bf697d [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
Mahir Gunyel9545be22021-07-04 15:53:16 -070027 "github.com/opencord/voltha-protos/v4/go/tech_profile"
28
Girish Gowdra50e56422021-06-01 16:46:04 -070029 "github.com/opencord/voltha-lib-go/v5/pkg/log"
mpagenkoaf801632020-07-03 10:00:42 +000030)
31
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000032//definitions for TechProfileProcessing - copied from OltAdapter:openolt_flowmgr.go
33// could perhaps be defined more globally
34const (
Himani Chawla6d2ae152020-09-02 13:11:20 +053035 // binaryStringPrefix is binary string prefix
36 binaryStringPrefix = "0b"
37 // binaryBit1 is binary bit 1 expressed as a character
38 //binaryBit1 = '1'
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000039)
mpagenkoaf801632020-07-03 10:00:42 +000040
41type resourceEntry int
42
43const (
44 cResourceGemPort resourceEntry = 1
45 cResourceTcont resourceEntry = 2
46)
47
mpagenko3dbcdd22020-07-22 07:38:45 +000048type tTechProfileIndication struct {
mpagenkodff5dda2020-08-28 11:52:01 +000049 techProfileType string
Girish Gowdra041dcb32020-11-16 16:54:30 -080050 techProfileID uint8
mpagenkodff5dda2020-08-28 11:52:01 +000051 techProfileConfigDone bool
mpagenko2418ab02020-11-12 12:58:06 +000052 techProfileToDelete bool
mpagenko3dbcdd22020-07-22 07:38:45 +000053}
54
55type tcontParamStruct struct {
56 allocID uint16
57 schedPolicy uint8
58}
59type gemPortParamStruct struct {
Himani Chawla4d908332020-08-31 12:30:20 +053060 //ponOmciCC bool
mpagenko3dbcdd22020-07-22 07:38:45 +000061 gemPortID uint16
62 direction uint8
63 gemPortEncState uint8
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000064 prioQueueIndex uint8
65 pbitString string
mpagenko3dbcdd22020-07-22 07:38:45 +000066 discardPolicy string
Himani Chawla4d908332020-08-31 12:30:20 +053067 //could also be a queue specific parameter, not used that way here
68 //maxQueueSize uint16
mpagenko3dbcdd22020-07-22 07:38:45 +000069 queueSchedPolicy string
70 queueWeight uint8
Himani Chawla1c136902020-12-10 16:30:59 +053071 removeGemID uint16
ozgecanetsia4b232302020-11-11 10:58:10 +030072 isMulticast bool
73 //TODO check if this has any value/difference from gemPortId
74 multicastGemPortID uint16
75 staticACL string
76 dynamicACL string
mpagenko3dbcdd22020-07-22 07:38:45 +000077}
78
79//refers to one tcont and its properties and all assigned GemPorts and their properties
80type tcontGemList struct {
81 tcontParams tcontParamStruct
82 mapGemPortParams map[uint16]*gemPortParamStruct
83}
84
Girish Gowdra041dcb32020-11-16 16:54:30 -080085// refers a unique combination of uniID and tpID for a given ONU.
86type uniTP struct {
87 uniID uint8
88 tpID uint8
89}
mpagenko3dbcdd22020-07-22 07:38:45 +000090
Himani Chawla6d2ae152020-09-02 13:11:20 +053091//onuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU
92type onuUniTechProf struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053093 baseDeviceHandler *deviceHandler
mpagenko01e726e2020-10-23 09:45:29 +000094 deviceID string
mpagenkodff5dda2020-08-28 11:52:01 +000095 tpProcMutex sync.RWMutex
mpagenkodff5dda2020-08-28 11:52:01 +000096 chTpConfigProcessingStep chan uint8
Girish Gowdra041dcb32020-11-16 16:54:30 -080097 mapUniTpIndication map[uniTP]*tTechProfileIndication //use pointer values to ease assignments to the map
98 mapPonAniConfig map[uniTP]*tcontGemList //per UNI: use pointer values to ease assignments to the map
99 pAniConfigFsm map[uniTP]*uniPonAniConfigFsm
100 procResult map[uniTP]error //error indication of processing
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800101 mutexTPState sync.RWMutex
Girish Gowdra041dcb32020-11-16 16:54:30 -0800102 tpProfileExists map[uniTP]bool
mpagenko73143992021-04-09 15:17:10 +0000103 tpProfileResetting map[uniTP]bool
mpagenko8b07c1b2020-11-26 10:36:31 +0000104 mapRemoveGemEntry map[uniTP]*gemPortParamStruct //per UNI: pointer to GemEntry to be removed
mpagenkoaf801632020-07-03 10:00:42 +0000105}
106
ozgecanetsia72e1c9f2021-05-26 17:26:29 +0300107func (onuTP *onuUniTechProf) multicastConfiguredForOtherUniTps(ctx context.Context, uniTpKey uniTP) bool {
108 for _, aniFsm := range onuTP.pAniConfigFsm {
109 if aniFsm.uniTpKey.uniID == uniTpKey.uniID && aniFsm.uniTpKey.tpID == uniTpKey.tpID {
110 continue
111 }
112 if aniFsm.hasMulticastGem(ctx) {
113 return true
114 }
115 }
116 return false
117}
118
Himani Chawla6d2ae152020-09-02 13:11:20 +0530119//newOnuUniTechProf returns the instance of a OnuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000120//(one instance per ONU/deviceHandler for all possible UNI's)
mpagenko01e726e2020-10-23 09:45:29 +0000121func newOnuUniTechProf(ctx context.Context, aDeviceHandler *deviceHandler) *onuUniTechProf {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000122 logger.Debugw(ctx, "init-OnuUniTechProf", log.Fields{"device-id": aDeviceHandler.deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530123 var onuTP onuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000124 onuTP.baseDeviceHandler = aDeviceHandler
mpagenko01e726e2020-10-23 09:45:29 +0000125 onuTP.deviceID = aDeviceHandler.deviceID
mpagenkodff5dda2020-08-28 11:52:01 +0000126 onuTP.chTpConfigProcessingStep = make(chan uint8)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800127 onuTP.mapUniTpIndication = make(map[uniTP]*tTechProfileIndication)
128 onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList)
129 onuTP.procResult = make(map[uniTP]error)
130 onuTP.tpProfileExists = make(map[uniTP]bool)
mpagenko73143992021-04-09 15:17:10 +0000131 onuTP.tpProfileResetting = make(map[uniTP]bool)
mpagenko8b07c1b2020-11-26 10:36:31 +0000132 onuTP.mapRemoveGemEntry = make(map[uniTP]*gemPortParamStruct)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000133
mpagenkoaf801632020-07-03 10:00:42 +0000134 return &onuTP
135}
136
137// lockTpProcMutex locks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530138func (onuTP *onuUniTechProf) lockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000139 onuTP.tpProcMutex.Lock()
140}
141
142// unlockTpProcMutex unlocks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530143func (onuTP *onuUniTechProf) unlockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000144 onuTP.tpProcMutex.Unlock()
145}
146
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000147// resetTpProcessingErrorIndication resets the internal error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000148// need to be called before evaluation of any subsequent processing (given by waitForTpCompletion())
Girish Gowdra041dcb32020-11-16 16:54:30 -0800149func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) {
mpagenko73143992021-04-09 15:17:10 +0000150 onuTP.mutexTPState.Lock()
151 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800152 onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000153}
154
Girish Gowdra041dcb32020-11-16 16:54:30 -0800155func (onuTP *onuUniTechProf) getTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error {
mpagenko73143992021-04-09 15:17:10 +0000156 onuTP.mutexTPState.RLock()
157 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800158 return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}]
mpagenko3dbcdd22020-07-22 07:38:45 +0000159}
160
mpagenko8b07c1b2020-11-26 10:36:31 +0000161// configureUniTp checks existing tp resources to configure and starts the corresponding OMCI configuation of the UNI port
mpagenko3dbcdd22020-07-22 07:38:45 +0000162// all possibly blocking processing must be run in background to allow for deadline supervision!
163// but take care on sequential background processing when needed (logical dependencies)
Himani Chawla4d908332020-08-31 12:30:20 +0530164// use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization
Himani Chawla6d2ae152020-09-02 13:11:20 +0530165func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context,
Girish Gowdra50e56422021-06-01 16:46:04 -0700166 aUniID uint8, aPathString string, tpInst tech_profile.TechProfileInstance, wg *sync.WaitGroup) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000167 defer wg.Done() //always decrement the waitGroup on return
dbainbri4d3a0dc2020-12-02 00:33:42 +0000168 logger.Debugw(ctx, "configure the Uni according to TpPath", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000169 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800170 tpID, err := GetTpIDFromTpPath(aPathString)
171 uniTpKey := uniTP{uniID: aUniID, tpID: tpID}
172 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000173 logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800174 return
175 }
mpagenkoaf801632020-07-03 10:00:42 +0000176
mpagenko3dbcdd22020-07-22 07:38:45 +0000177 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530178 var pCurrentUniPort *onuUniPort
mpagenko3dbcdd22020-07-22 07:38:45 +0000179 for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap {
180 // only if this port is validated for operState transfer
Girish Gowdra041dcb32020-11-16 16:54:30 -0800181 if uniPort.uniID == aUniID {
mpagenko3dbcdd22020-07-22 07:38:45 +0000182 pCurrentUniPort = uniPort
183 break //found - end search loop
184 }
185 }
186 if pCurrentUniPort == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000187 logger.Errorw(ctx, "TechProfile configuration aborted: requested uniID not found in PortDB",
mpagenko73143992021-04-09 15:17:10 +0000188 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
189 onuTP.mutexTPState.Lock()
190 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800191 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200192 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000193 return
194 }
mpagenkoaf801632020-07-03 10:00:42 +0000195
mpagenko73143992021-04-09 15:17:10 +0000196 if onuTP.getProfileResetting(uniTpKey) {
197 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
198 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
199 onuTP.mutexTPState.Lock()
200 defer onuTP.mutexTPState.Unlock()
201 onuTP.procResult[uniTpKey] = fmt.Errorf(
202 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
203 aUniID, onuTP.deviceID)
204 return
205 }
mpagenkodff5dda2020-08-28 11:52:01 +0000206 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
mpagenkoaf801632020-07-03 10:00:42 +0000207
mpagenko3dbcdd22020-07-22 07:38:45 +0000208 //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called
209 // in case the KVPath has changed for the given UNI,
210 // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
211 // (ANI) configuration of this port has to be removed first
212 // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
213 // existence of configuration can be detected based on tp stored TCONT's
Andrea Campanella6515c582020-10-05 11:25:00 +0200214 //TODO:
mpagenko3dbcdd22020-07-22 07:38:45 +0000215 /* if tcontMap not empty {
216 go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000217 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000218 //timeout or error detected
219 return
220 }
221 clear tcontMap
222 }
223
224 processingStep++
225 */
Girish Gowdra50e56422021-06-01 16:46:04 -0700226 go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, tpInst, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000227 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000228 //timeout or error detected
mpagenko73143992021-04-09 15:17:10 +0000229 onuTP.mutexTPState.RLock()
Girish Gowdra24dd1132021-07-06 15:25:40 -0700230 ok := onuTP.tpProfileExists[uniTpKey]
231 onuTP.mutexTPState.RUnlock()
232 if ok {
mpagenko01e726e2020-10-23 09:45:29 +0000233 //ignore the internal error in case the new profile is already configured
234 // and abort the processing here
235 return
236 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000237 logger.Errorw(ctx, "tech-profile related configuration aborted on read",
mpagenko01e726e2020-10-23 09:45:29 +0000238 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000239 onuTP.mutexTPState.Lock()
240 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800241 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200242 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000243 return
244 }
mpagenko73143992021-04-09 15:17:10 +0000245 if onuTP.getProfileResetting(uniTpKey) {
246 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
247 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
248 onuTP.mutexTPState.Lock()
249 defer onuTP.mutexTPState.Unlock()
250 onuTP.procResult[uniTpKey] = fmt.Errorf(
251 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
252 aUniID, onuTP.deviceID)
253 return
254 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000255 processingStep++
Girish Gowdra041dcb32020-11-16 16:54:30 -0800256
mpagenko73143992021-04-09 15:17:10 +0000257 //ensure read protection for access to mapPonAniConfig
258 onuTP.mutexTPState.RLock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800259 valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey]
mpagenko73143992021-04-09 15:17:10 +0000260 onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800261 if existPA {
262 if valuePA != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000263 //Config data for this uni and and at least TCont Index 0 exist
mpagenko8b07c1b2020-11-26 10:36:31 +0000264 if err := onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000265 logger.Errorw(ctx, "tech-profile related FSM could not be started",
mpagenko8b07c1b2020-11-26 10:36:31 +0000266 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000267 onuTP.mutexTPState.Lock()
268 defer onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000269 onuTP.procResult[uniTpKey] = err
270 return
271 }
mpagenkodff5dda2020-08-28 11:52:01 +0000272 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000273 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
274 logger.Warnw(ctx, "tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000275 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800276
mpagenko73143992021-04-09 15:17:10 +0000277 onuTP.mutexTPState.Lock()
278 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800279 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200280 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530281 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000282 //which requires to reset it to allow for new usage, e.g. also on a different UNI
283 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000284 if _, ok := onuTP.pAniConfigFsm[uniTpKey]; ok {
285 _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset)
286 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000287 return
mpagenkoaf801632020-07-03 10:00:42 +0000288 }
289 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000290 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000291 logger.Errorw(ctx, "no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000292 "device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000293 onuTP.mutexTPState.Lock()
294 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800295 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 +0200296 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000297 return
mpagenkoaf801632020-07-03 10:00:42 +0000298 }
299 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000300 logger.Errorw(ctx, "no PonAni data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000301 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800302
mpagenko73143992021-04-09 15:17:10 +0000303 onuTP.mutexTPState.Lock()
304 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800305 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 +0200306 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000307 return
mpagenkoaf801632020-07-03 10:00:42 +0000308 }
309}
310
mpagenko3dbcdd22020-07-22 07:38:45 +0000311/* internal methods *********************/
ozgecanetsia4b232302020-11-11 10:58:10 +0300312// nolint: gocyclo
Himani Chawla6d2ae152020-09-02 13:11:20 +0530313func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile(
Girish Gowdra50e56422021-06-01 16:46:04 -0700314 ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, tpInst tech_profile.TechProfileInstance, aProcessingStep uint8) {
315 var err error
mpagenko3dbcdd22020-07-22 07:38:45 +0000316 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
317 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
318 subStringSlice := strings.Split(aPathString, "/")
319 if len(subStringSlice) <= 2 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000320 logger.Errorw(ctx, "invalid path name format",
mpagenko3dbcdd22020-07-22 07:38:45 +0000321 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000322 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000323 return
324 }
325
mpagenko73143992021-04-09 15:17:10 +0000326 //ensure write protection for access to used maps
327 onuTP.mutexTPState.Lock()
328 defer onuTP.mutexTPState.Unlock()
329
330 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
331 onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false
332
mpagenko3dbcdd22020-07-22 07:38:45 +0000333 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000334 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
335 // then we throw a warning, set an internal error and abort with error,
336 // which is later re-defined to success response to OLT adapter
337 // if TPId has changed, current data is removed (note that the ONU config state may be
338 // ambivalent in such a case)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800339 if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000340 logger.Warnw(ctx, "Some active profile entry at reading new TechProfile",
mpagenko3dbcdd22020-07-22 07:38:45 +0000341 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800342 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
343 if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID {
mpagenko01e726e2020-10-23 09:45:29 +0000344 // ProfId not changed - assume profile to be still the same
345 // anyway this should not appear after full support of profile (Gem/TCont) removal
dbainbri4d3a0dc2020-12-02 00:33:42 +0000346 logger.Warnw(ctx, "New TechProfile already exists - aborting configuration",
mpagenko01e726e2020-10-23 09:45:29 +0000347 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800348 onuTP.tpProfileExists[uniTPKey] = true
mpagenko01e726e2020-10-23 09:45:29 +0000349 onuTP.chTpConfigProcessingStep <- 0 //error indication
350 return
351 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000352 //delete on the mapUniTpIndication map not needed, just overwritten later
353 //delete on the PonAniConfig map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800354 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenko3dbcdd22020-07-22 07:38:45 +0000355 } else {
356 // this is normal processing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800357 onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
mpagenko3dbcdd22020-07-22 07:38:45 +0000358 }
359
Girish Gowdra041dcb32020-11-16 16:54:30 -0800360 onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000361 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
Girish Gowdra041dcb32020-11-16 16:54:30 -0800362 onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID
363 onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false
364 onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000365 logger.Debugw(ctx, "tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000366 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800367 "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType,
368 "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000369
mpagenko01e726e2020-10-23 09:45:29 +0000370 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000371 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800372 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000373
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000374 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000375 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra50e56422021-06-01 16:46:04 -0700376 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocId)
Himani Chawla4d908332020-08-31 12:30:20 +0530377 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000378 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
Girish Gowdra50e56422021-06-01 16:46:04 -0700379 if tpInst.UsScheduler.QSchedPolicy == tech_profile.SchedulingPolicy_StrictPriority {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800380 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000381 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000382 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800383 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000384 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000385 loNumGemPorts := tpInst.NumGemPorts
386 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000387 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000388 if uint32(pos) == loNumGemPorts {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000389 logger.Debugw(ctx, "PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
mpagenko1cc3cb42020-07-27 15:24:38 +0000390 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000391 break
392 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000393 if pos == 0 {
394 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
395 loGemPortRead = true
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000396 }
Himani Chawla1c136902020-12-10 16:30:59 +0530397 //for all GemPorts we need to extend the mapGemPortParams
Girish Gowdra50e56422021-06-01 16:46:04 -0700398 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)] = &gemPortParamStruct{}
Himani Chawla1c136902020-12-10 16:30:59 +0530399
Girish Gowdra50e56422021-06-01 16:46:04 -0700400 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortID =
401 uint16(content.GemportId)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000402 //direction can be correlated later with Downstream list,
403 // for now just assume bidirectional (upstream never exists alone)
Girish Gowdra50e56422021-06-01 16:46:04 -0700404 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000405 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
Girish Gowdra50e56422021-06-01 16:46:04 -0700406 if content.PriorityQ > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000407 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Girish Gowdra50e56422021-06-01 16:46:04 -0700408 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQ})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000409 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800410 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000411 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000412 return
413 }
Girish Gowdra50e56422021-06-01 16:46:04 -0700414 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].prioQueueIndex =
415 uint8(content.PriorityQ)
416 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530417 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000418 if content.AesEncryption == "True" {
Girish Gowdra50e56422021-06-01 16:46:04 -0700419 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000420 } else {
Girish Gowdra50e56422021-06-01 16:46:04 -0700421 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000422 }
Girish Gowdra50e56422021-06-01 16:46:04 -0700423 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].discardPolicy =
424 content.DiscardPolicy.String()
425 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].queueSchedPolicy =
426 content.SchedulingPolicy.String()
mpagenko3dbcdd22020-07-22 07:38:45 +0000427 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Girish Gowdra50e56422021-06-01 16:46:04 -0700428 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000429 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000430 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300431
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300432 for _, downstreamContent := range tpInst.DownstreamGemPortAttributeList {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000433 logger.Debugw(ctx, "Operating on Downstream Gem Port", log.Fields{"downstream-gem": downstreamContent})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300434 //Commenting this out due to faliure, needs investigation
435 //if uint32(pos) == loNumGemPorts {
436 // logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
437 // log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
438 // break
439 //}
440 isMulticast := false
ozgecanetsia4b232302020-11-11 10:58:10 +0300441 //Flag is defined as string in the TP in voltha-lib-go, parsing it from string
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300442 if downstreamContent.IsMulticast != "" {
443 isMulticast, err = strconv.ParseBool(downstreamContent.IsMulticast)
444 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000445 logger.Errorw(ctx, "multicast-error-config-unknown-flag-in-technology-profile",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300446 log.Fields{"UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "error": err})
447 continue
448 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300449 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000450 logger.Infow(ctx, "Gem Port is multicast", log.Fields{"isMulticast": isMulticast})
ozgecanetsia4b232302020-11-11 10:58:10 +0300451 if isMulticast {
Girish Gowdra50e56422021-06-01 16:46:04 -0700452 mcastGemID := uint16(downstreamContent.MulticastGemId)
ozgecanetsia4b232302020-11-11 10:58:10 +0300453 _, existing := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID]
454 if existing {
455 //GEM port was previously configured, avoid setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000456 logger.Errorw(ctx, "multicast-error-config-existing-gem-port-config", log.Fields{"UniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300457 "downstream-gem": downstreamContent, "key": mcastGemID})
458 continue
459 } else {
460 //GEM port is not configured, setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000461 logger.Infow(ctx, "creating-multicast-gem-port", log.Fields{"uniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300462 "gemPortId": mcastGemID, "key": mcastGemID})
463
464 //for all further GemPorts we need to extend the mapGemPortParams
465 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID] = &gemPortParamStruct{}
466
467 //Separate McastGemId is derived from OMCI-lib-go, if not needed first needs to be removed there.
468 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortID = mcastGemID
469 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].direction = 2 // for ANI to UNI as defined in G.988
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300470
471 if downstreamContent.AesEncryption == "True" {
472 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 1
473 } else {
474 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 0
475 }
476
477 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
Girish Gowdra50e56422021-06-01 16:46:04 -0700478 if downstreamContent.PriorityQ > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000479 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Girish Gowdra50e56422021-06-01 16:46:04 -0700480 log.Fields{"device-id": onuTP.deviceID, "index": mcastGemID, "PrioQueue": downstreamContent.PriorityQ})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300481 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
482 delete(onuTP.mapPonAniConfig, uniTPKey)
483 onuTP.chTpConfigProcessingStep <- 0 //error indication
484 return
ozgecanetsia4b232302020-11-11 10:58:10 +0300485 }
486 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].prioQueueIndex =
Girish Gowdra50e56422021-06-01 16:46:04 -0700487 uint8(downstreamContent.PriorityQ)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300488 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].pbitString =
489 strings.TrimPrefix(downstreamContent.PbitMap, binaryStringPrefix)
490
491 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].discardPolicy =
Girish Gowdra50e56422021-06-01 16:46:04 -0700492 downstreamContent.DiscardPolicy.String()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300493 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueSchedPolicy =
Girish Gowdra50e56422021-06-01 16:46:04 -0700494 downstreamContent.SchedulingPolicy.String()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300495 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
496 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueWeight =
497 uint8(downstreamContent.Weight)
498
ozgecanetsia4b232302020-11-11 10:58:10 +0300499 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].isMulticast = isMulticast
500 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].multicastGemPortID =
Girish Gowdra50e56422021-06-01 16:46:04 -0700501 uint16(downstreamContent.MulticastGemId)
502 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].staticACL = downstreamContent.StaticAccessControlList
503 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].dynamicACL = downstreamContent.DynamicAccessControlList
ozgecanetsia4b232302020-11-11 10:58:10 +0300504 }
505 }
506 }
507
Himani Chawla4d908332020-08-31 12:30:20 +0530508 if !loGemPortRead {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000509 logger.Errorw(ctx, "PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000510 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000511 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800512 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000513 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000514 return
515 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000516 //logger does not simply output the given structures, just give some example debug values
dbainbri4d3a0dc2020-12-02 00:33:42 +0000517 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000518 "device-id": onuTP.deviceID, "uni-id": aUniID,
519 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
Himani Chawla1c136902020-12-10 16:30:59 +0530520 for gemPortID, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000521 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530522 "GemPort": gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000523 "QueueScheduling": gemEntry.queueSchedPolicy})
524 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000525
mpagenkodff5dda2020-08-28 11:52:01 +0000526 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000527}
528
Himani Chawla6d2ae152020-09-02 13:11:20 +0530529func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
mpagenko8b07c1b2020-11-26 10:36:31 +0000530 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000531
532 //OMCI transfer of ANI data acc. to mapPonAniConfig
533 // also the FSM's are running in background,
mpagenko8b07c1b2020-11-26 10:36:31 +0000534 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800535 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko3dbcdd22020-07-22 07:38:45 +0000536 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000537 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800538 } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000539 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000540 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000541 //AniConfigFsm already init
dbainbri4d3a0dc2020-12-02 00:33:42 +0000542 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000543}
544
545// deleteTpResource removes Resources from the ONU's specified Uni
mpagenko73143992021-04-09 15:17:10 +0000546// nolint: gocyclo
mpagenko8b07c1b2020-11-26 10:36:31 +0000547func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context,
548 aUniID uint8, aTpID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
549 wg *sync.WaitGroup) {
550 defer wg.Done()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000551 logger.Debugw(ctx, "will remove TP resources from ONU's UNI", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000552 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "Resource": aResource})
553 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
554
555 if cResourceGemPort == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000556 logger.Debugw(ctx, "remove GemPort from the list of existing ones of the TP", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000557 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID})
558
mpagenko73143992021-04-09 15:17:10 +0000559 //ensure read protection for access to mapPonAniConfig
560 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000561 // check if the requested GemPort exists in the DB, indicate it to the FSM
562 // store locally to remove it from DB later on success
563 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
564 if pLocAniConfigOnUni == nil {
mpagenko73143992021-04-09 15:17:10 +0000565 onuTP.mutexTPState.RUnlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000566 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000567 logger.Debugw(ctx, "AniConfig or GemEntry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000568 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
569 return
570 }
mpagenko73143992021-04-09 15:17:10 +0000571 onuTP.mutexTPState.RUnlock()
572
Himani Chawla1c136902020-12-10 16:30:59 +0530573 for gemPortID, gemEntry := range pLocAniConfigOnUni.mapGemPortParams {
574 if gemPortID == uint16(aEntryID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000575 //GemEntry to be deleted found
Himani Chawla1c136902020-12-10 16:30:59 +0530576 gemEntry.removeGemID = gemPortID //store the index for later removal
577 onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemPortID]
dbainbri4d3a0dc2020-12-02 00:33:42 +0000578 logger.Debugw(ctx, "Remove-GemEntry stored", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530579 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000580 break //abort loop, always only one GemPort to remove
581 }
582 }
583 if onuTP.mapRemoveGemEntry[uniTPKey] == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000584 logger.Errorw(ctx, "GemPort removal aborted - GemPort not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000585 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
586 /* Do not set some error indication to the outside system interface on delete
587 assume there is nothing to be deleted internally and hope a new config request will recover the situation
588 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s",
589 aEntryID, aUniID, onuTP.deviceID)
590 */
591 return
592 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000593 if onuTP.baseDeviceHandler.isReadyForOmciConfig() {
mpagenko8b07c1b2020-11-26 10:36:31 +0000594 // check that the TpConfigRequest was done before
595 // -> that is implicitly done using the AniConfigFsm,
596 // which must be in the according state to remove something
mpagenko8b07c1b2020-11-26 10:36:31 +0000597 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000598 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000599 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
600 /* Do not set some error indication to the outside system interface on delete (see above)
601 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s",
602 aUniID, onuTP.deviceID)
603 */
604 //if the FSM is not valid, also TP related remove data should not be valid:
605 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000606 //ensure write protection for access to mapPonAniConfig
607 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530608 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000609 // remove the removeEntry
610 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000611 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000612 return
613 }
614 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000615 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000616 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
617 /* Do not set some error indication to the outside system interface on delete (see above)
618 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid",
619 aUniID, onuTP.deviceID, aTpID)
620 */
621 //if the FSM is not valid, also TP related remove data should not be valid:
622 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000623 //ensure write protection for access to mapPonAniConfig
624 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530625 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000626 // remove the removeEntry
627 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000628 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000629 return
630 }
mpagenko73143992021-04-09 15:17:10 +0000631 if onuTP.getProfileResetting(uniTPKey) {
632 logger.Debugw(ctx, "aborting GemRemoval on FSM, reset requested in parallel", log.Fields{
633 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
634 //ensure write protection for access to mapPonAniConfig
635 onuTP.mutexTPState.Lock()
636 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
637 // remove the removeEntry
638 delete(onuTP.mapRemoveGemEntry, uniTPKey)
639 onuTP.mutexTPState.Unlock()
640 return
641 }
642 // initiate OMCI GemPort related removal
643 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
644 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000645 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemGemiw, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000646 //even if the FSM invocation did not work we don't indicate a problem within procResult
647 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
648 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
649 return
650 }
651 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000652 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
653 logger.Warnw(ctx, "GemPort removal aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000654 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
655 //even if the FSM delete execution did not work we don't indicate a problem within procResult
656 //we should never respond to delete with error ...
657 //this issue here means that the AniConfigFsm has not finished successfully
658 //which requires to reset it to allow for new usage, e.g. also on a different UNI
659 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000660 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok {
661 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
662 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000663 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
664 return
665 }
666 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000667 //if we can't do the OMCI processing we also suppress the ProcStatusUpdate
668 //this is needed as in the device-down case where all FSM's are getting reset and internal data gets cleared
669 //as a consequence a possible remove-flow does not see any dependency on the TechProfile anymore and is executed (pro forma) directly
670 //a later TechProfile removal would cause the device-reason to be updated to 'techProfile-delete-success' which is not the expected state
671 // and anyway is no real useful information at that stage
dbainbri4d3a0dc2020-12-02 00:33:42 +0000672 logger.Debugw(ctx, "uniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000673 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000674 }
675 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000676 //ensure write protection for access to mapPonAniConfig
Mahir Gunyel9545be22021-07-04 15:53:16 -0700677 logger.Debugw(ctx, "uniPonAniConfigFsm removing gem from config data and clearing ani FSM", log.Fields{
678 "device-id": onuTP.deviceID, "gem-id": onuTP.mapRemoveGemEntry[uniTPKey].removeGemID, "uniTPKey": uniTPKey})
mpagenko73143992021-04-09 15:17:10 +0000679 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530680 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000681 // remove the removeEntry
682 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000683 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000684 } else { //if cResourceTcont == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000685 logger.Debugw(ctx, "reset TCont with AllocId", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000686 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID})
687
mpagenko73143992021-04-09 15:17:10 +0000688 //ensure read protection for access to mapPonAniConfig
689 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000690 // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM
691 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
692 if pLocAniConfigOnUni == nil {
693 // No relevant entry exists anymore - acknowledge success
mpagenko73143992021-04-09 15:17:10 +0000694 onuTP.mutexTPState.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000695 logger.Debugw(ctx, "AniConfig or TCont entry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000696 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
697 return
698 }
mpagenko73143992021-04-09 15:17:10 +0000699 onuTP.mutexTPState.RUnlock()
700
mpagenko8b07c1b2020-11-26 10:36:31 +0000701 if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000702 logger.Errorw(ctx, "TCont removal aborted - indicated AllocId not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000703 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID})
704 /* Do not set some error indication to the outside system interface on delete
705 assume there is nothing to be deleted internally and hope a new config request will recover the situation
706 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s",
707 aEntryID, aUniID, onuTP.deviceID)
708 */
709 return
710 }
711 //T-Cont to be reset found
dbainbri4d3a0dc2020-12-02 00:33:42 +0000712 logger.Debugw(ctx, "Reset-T-Cont AllocId found - valid", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000713 "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID})
714 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000715 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000716 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
717 /* Do not set some error indication to the outside system interface on delete (see above)
718 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s",
719 aUniID, onuTP.deviceID)
720 */
mpagenko8b07c1b2020-11-26 10:36:31 +0000721 return
722 }
723 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000724 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000725 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
726 //even if the FSM invocation did not work we don't indicate a problem within procResult
727 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
728 //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 +0000729 return
730 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000731 if onuTP.baseDeviceHandler.isReadyForOmciConfig() {
mpagenko8b07c1b2020-11-26 10:36:31 +0000732 // check that the TpConfigRequest was done before
733 // -> that is implicitly done using the AniConfigFsm,
734 // which must be in the according state to remove something
mpagenko73143992021-04-09 15:17:10 +0000735 if onuTP.getProfileResetting(uniTPKey) {
736 logger.Debugw(ctx, "aborting TCont removal on FSM, reset requested in parallel", log.Fields{
737 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
738 return
739 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000740 // initiate OMCI TCont related cleanup
741 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
742 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000743 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemTcontPath, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000744 //even if the FSM invocation did not work we don't indicate a problem within procResult
745 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
746 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
747 return
748 }
749 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000750 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
751 logger.Warnw(ctx, "TCont cleanup aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000752 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
753 //even if the FSM delete execution did not work we don't indicate a problem within procResult
754 //we should never respond to delete with error ...
755 //this issue here means that the AniConfigFsm has not finished successfully
756 //which requires to reset it to allow for new usage, e.g. also on a different UNI
757 //(without that it would be reset on device down indication latest)
mpagenko73143992021-04-09 15:17:10 +0000758 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok {
759 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
760 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000761 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
762 return
763 }
764 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000765 //see gemPort comments
dbainbri4d3a0dc2020-12-02 00:33:42 +0000766 logger.Debugw(ctx, "uniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000767 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000768 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000769 }
Mahir Gunyel9545be22021-07-04 15:53:16 -0700770
771}
772
773func (onuTP *onuUniTechProf) isTechProfileConfigCleared(ctx context.Context, uniID uint8, tpID uint8) bool {
774 uniTPKey := uniTP{uniID: uniID, tpID: tpID}
775 logger.Debugw(ctx, "isTechProfileConfigCleared", log.Fields{"device-id": onuTP.deviceID})
776 if onuTP.mapPonAniConfig[uniTPKey] != nil {
777 mapGemPortParams := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams
778 unicastGemCount := 0
779 for _, gemEntry := range mapGemPortParams {
780 if !gemEntry.isMulticast {
781 unicastGemCount++
782 }
783 }
784 if unicastGemCount == 0 || onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID == 0 {
785 logger.Debugw(ctx, "clearing-ani-side-config", log.Fields{
786 "device-id": onuTP.deviceID, "uniTpKey": uniTPKey})
787 onuTP.clearAniSideConfig(ctx, uniID, tpID)
788 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok {
789 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
790 }
791 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(ctx, OmciAniResourceRemoved)
792 return true
793 }
mpagenko7d6bb022021-03-11 15:07:55 +0000794 }
Mahir Gunyel9545be22021-07-04 15:53:16 -0700795 return false
mpagenko3dbcdd22020-07-22 07:38:45 +0000796}
797
Himani Chawla6d2ae152020-09-02 13:11:20 +0530798func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000799 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000800 select {
801 case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000802 logger.Warnw(ctx, "processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000803 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000804 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000805 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000806 if rxStep == aProcessingStep {
807 return true
808 }
809 //all other values are not accepted - including 0 for error indication
dbainbri4d3a0dc2020-12-02 00:33:42 +0000810 logger.Warnw(ctx, "Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000811 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000812 "wantedStep": aProcessingStep, "haveStep": rxStep})
813 return false
814 }
815}
816
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000817// createAniConfigFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000818func (onuTP *onuUniTechProf) createAniConfigFsm(ctx context.Context, aUniID uint8, aTpID uint8,
mpagenko8b07c1b2020-11-26 10:36:31 +0000819 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000820 logger.Debugw(ctx, "createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000821 chAniConfigFsm := make(chan Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800822 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000823 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(ctx, true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000824 if pDevEntry == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000825 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000826 return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000827 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000828 pAniCfgFsm := newUniPonAniConfigFsm(ctx, pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800829 pDevEntry.pOnuDB, aTpID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000830 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko8b07c1b2020-11-26 10:36:31 +0000831 if pAniCfgFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000832 logger.Errorw(ctx, "AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000833 return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000834 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000835 if onuTP.pAniConfigFsm == nil {
836 onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800837 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000838 onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm
dbainbri4d3a0dc2020-12-02 00:33:42 +0000839 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000840}
841
mpagenko3dbcdd22020-07-22 07:38:45 +0000842// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000843func (onuTP *onuUniTechProf) runAniConfigFsm(ctx context.Context, aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000844 /* Uni related ANI config procedure -
845 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
846 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800847 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
848
849 pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000850 if pACStatemachine != nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000851 if aEvent == aniEvStart {
852 if !pACStatemachine.Is(aniStDisabled) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000853 logger.Errorw(ctx, "wrong state of AniConfigFSM to start - want: Disabled", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000854 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000855 // maybe try a FSM reset and then again ... - TODO!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000856 return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000857 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000858 } else if !pACStatemachine.Is(aniStConfigDone) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000859 logger.Errorw(ctx, "wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000860 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000861 return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000862 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000863 //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config)
864 onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
865 if err := pACStatemachine.Event(aEvent); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000866 logger.Errorw(ctx, "AniConfigFSM: can't trigger event", log.Fields{"err": err})
mpagenko8b07c1b2020-11-26 10:36:31 +0000867 return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID)
868 }
869 /***** AniConfigFSM event notified */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000870 logger.Debugw(ctx, "AniConfigFSM event notified", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000871 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent})
872 return nil
mpagenko3dbcdd22020-07-22 07:38:45 +0000873 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000874 logger.Errorw(ctx, "AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000875 // maybe try a FSM reset and then again ... - TODO!!!
876 return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID)
mpagenkoaf801632020-07-03 10:00:42 +0000877}
mpagenkodff5dda2020-08-28 11:52:01 +0000878
Girish Gowdra041dcb32020-11-16 16:54:30 -0800879// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000880func (onuTP *onuUniTechProf) clearAniSideConfig(ctx context.Context, aUniID uint8, aTpID uint8) {
881 logger.Debugw(ctx, "removing TpIndication and PonAniConfig data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000882 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800883 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
884
885 onuTP.mutexTPState.Lock()
886 defer onuTP.mutexTPState.Unlock()
mpagenko73143992021-04-09 15:17:10 +0000887 //deleting a map entry should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800888 delete(onuTP.mapUniTpIndication, uniTpKey)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800889 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko73143992021-04-09 15:17:10 +0000890 delete(onuTP.procResult, uniTpKey)
891 delete(onuTP.tpProfileExists, uniTpKey)
892 delete(onuTP.tpProfileResetting, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000893}
894
mpagenkodff5dda2020-08-28 11:52:01 +0000895// setConfigDone sets the requested techProfile config state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800896func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
897 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
898 onuTP.mutexTPState.Lock()
899 defer onuTP.mutexTPState.Unlock()
900 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
901 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000902 } //else: the state is just ignored (does not exist)
903}
904
905// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
dbainbri4d3a0dc2020-12-02 00:33:42 +0000906func (onuTP *onuUniTechProf) getTechProfileDone(ctx context.Context, aUniID uint8, aTpID uint8) bool {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800907 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000908 onuTP.mutexTPState.RLock()
909 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800910 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
911 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
912 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000913 logger.Debugw(ctx, "TechProfile not relevant for requested flow config - waiting on delete",
mpagenko2418ab02020-11-12 12:58:06 +0000914 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
915 return false //still waiting for removal of this techProfile first
916 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800917 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000918 }
919 }
920 //for all other constellations indicate false = Config not done
921 return false
922}
mpagenko2418ab02020-11-12 12:58:06 +0000923
924// setProfileToDelete sets the requested techProfile toDelete state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800925func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
926 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
927 onuTP.mutexTPState.Lock()
928 defer onuTP.mutexTPState.Unlock()
929 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
930 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000931 } //else: the state is just ignored (does not exist)
932}
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300933
934// setProfileToDelete sets the requested techProfile toDelete state (if possible)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000935func (onuTP *onuUniTechProf) getMulticastGemPorts(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300936 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000937 onuTP.mutexTPState.RLock()
938 defer onuTP.mutexTPState.RUnlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300939 gemPortIds := make([]uint16, 0)
940 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
941 for _, gemPortParam := range techProfile.mapGemPortParams {
942 if gemPortParam.isMulticast {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000943 logger.Debugw(ctx, "Detected multicast gemPort", log.Fields{"device-id": onuTP.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300944 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
945 "mcastGemId": gemPortParam.multicastGemPortID})
946 gemPortIds = append(gemPortIds, gemPortParam.multicastGemPortID)
947 }
948 }
949 } //else: the state is just ignored (does not exist)
950 return gemPortIds
951}
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800952
ozgecanetsia82b91a62021-05-21 18:54:49 +0300953func (onuTP *onuUniTechProf) getBidirectionalGemPortIDsForTP(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
954 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
955 onuTP.mutexTPState.RLock()
956 defer onuTP.mutexTPState.RUnlock()
957 gemPortIds := make([]uint16, 0)
958 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
959 logger.Debugw(ctx, "TechProfile exist", log.Fields{"device-id": onuTP.deviceID})
960 for _, gemPortParam := range techProfile.mapGemPortParams {
961 if !gemPortParam.isMulticast {
962 logger.Debugw(ctx, "Detected unicast gemPort", log.Fields{"device-id": onuTP.deviceID,
963 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
964 "GemId": gemPortParam.multicastGemPortID})
965 gemPortIds = append(gemPortIds, gemPortParam.gemPortID)
966 }
967 }
968 } else {
969 logger.Debugw(ctx, "TechProfile doesn't exist", log.Fields{"device-id": onuTP.deviceID})
970 } //else: the state is just ignored (does not exist)
971 logger.Debugw(ctx, "Gem PortID list", log.Fields{"device-id": onuTP.deviceID, "gemportList": gemPortIds})
972 return gemPortIds
973}
974
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800975func (onuTP *onuUniTechProf) GetAllBidirectionalGemPortIDsForOnu() []uint16 {
976 var gemPortInstIDs []uint16
977 onuTP.mutexTPState.RLock()
978 defer onuTP.mutexTPState.RUnlock()
979 for _, tcontGemList := range onuTP.mapPonAniConfig {
980 for gemPortID, gemPortData := range tcontGemList.mapGemPortParams {
981 if gemPortData != nil && !gemPortData.isMulticast { // only if not multicast gem port
982 gemPortInstIDs = append(gemPortInstIDs, gemPortID)
983 }
984 }
985 }
986 return gemPortInstIDs
987}
mpagenko73143992021-04-09 15:17:10 +0000988
989// setProfileResetting sets/resets the indication, that a reset of the TechProfileConfig/Removal is ongoing
990func (onuTP *onuUniTechProf) setProfileResetting(ctx context.Context, aUniID uint8, aTpID uint8, aState bool) {
991 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
992 onuTP.mutexTPState.Lock()
993 defer onuTP.mutexTPState.Unlock()
994 onuTP.tpProfileResetting[uniTpKey] = aState
995}
996
997// getProfileResetting returns true, if the the according indication for started reset procedure is set
998func (onuTP *onuUniTechProf) getProfileResetting(aUniTpKey uniTP) bool {
999 onuTP.mutexTPState.RLock()
1000 defer onuTP.mutexTPState.RUnlock()
1001 if isResetting, exist := onuTP.tpProfileResetting[aUniTpKey]; exist {
1002 return isResetting
1003 }
1004 return false
1005}