blob: 767997b91689430bd054292ce62630128f87abdd [file] [log] [blame]
mpagenkoaf801632020-07-03 10:00:42 +00001/*
Joey Armstronge8c091f2023-01-17 16:56:26 -05002 * Copyright 2020-2023 Open Networking Foundation (ONF) and the ONF Contributors
mpagenkoaf801632020-07-03 10:00:42 +00003 *
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
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000017//Package avcfg provides anig and vlan configuration functionality
18package avcfg
mpagenkoaf801632020-07-03 10:00:42 +000019
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"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000028 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
khenaidoo7d3c5582021-08-11 18:09:44 -040029 "github.com/opencord/voltha-protos/v5/go/tech_profile"
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
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +000041//as defined in G.988
42const (
43 cGemDirUniToAni = 1
44 cGemDirAniToUni = 2
45 cGemDirBiDirect = 3
46)
47
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000048// ResourceEntry - TODO: add comment
49type ResourceEntry int
mpagenkoaf801632020-07-03 10:00:42 +000050
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000051// TODO: add comment
mpagenkoaf801632020-07-03 10:00:42 +000052const (
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000053 CResourceGemPort ResourceEntry = 1
54 CResourceTcont ResourceEntry = 2
mpagenkoaf801632020-07-03 10:00:42 +000055)
56
mpagenko3dbcdd22020-07-22 07:38:45 +000057type tTechProfileIndication struct {
mpagenkodff5dda2020-08-28 11:52:01 +000058 techProfileType string
Girish Gowdra041dcb32020-11-16 16:54:30 -080059 techProfileID uint8
mpagenkodff5dda2020-08-28 11:52:01 +000060 techProfileConfigDone bool
mpagenko2418ab02020-11-12 12:58:06 +000061 techProfileToDelete bool
mpagenko3dbcdd22020-07-22 07:38:45 +000062}
63
64type tcontParamStruct struct {
65 allocID uint16
66 schedPolicy uint8
67}
68type gemPortParamStruct struct {
Himani Chawla4d908332020-08-31 12:30:20 +053069 //ponOmciCC bool
mpagenko3dbcdd22020-07-22 07:38:45 +000070 gemPortID uint16
71 direction uint8
72 gemPortEncState uint8
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000073 prioQueueIndex uint8
74 pbitString string
mpagenko3dbcdd22020-07-22 07:38:45 +000075 discardPolicy string
Himani Chawla4d908332020-08-31 12:30:20 +053076 //could also be a queue specific parameter, not used that way here
77 //maxQueueSize uint16
mpagenko3dbcdd22020-07-22 07:38:45 +000078 queueSchedPolicy string
79 queueWeight uint8
Himani Chawla1c136902020-12-10 16:30:59 +053080 removeGemID uint16
ozgecanetsia4b232302020-11-11 10:58:10 +030081 isMulticast bool
82 //TODO check if this has any value/difference from gemPortId
83 multicastGemPortID uint16
84 staticACL string
85 dynamicACL string
mpagenko3dbcdd22020-07-22 07:38:45 +000086}
87
88//refers to one tcont and its properties and all assigned GemPorts and their properties
89type tcontGemList struct {
90 tcontParams tcontParamStruct
91 mapGemPortParams map[uint16]*gemPortParamStruct
92}
93
Girish Gowdra041dcb32020-11-16 16:54:30 -080094// refers a unique combination of uniID and tpID for a given ONU.
95type uniTP struct {
96 uniID uint8
97 tpID uint8
98}
mpagenko3dbcdd22020-07-22 07:38:45 +000099
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000100//OnuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU
101type OnuUniTechProf struct {
mpagenko01e726e2020-10-23 09:45:29 +0000102 deviceID string
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000103 baseDeviceHandler cmn.IdeviceHandler
104 onuDevice cmn.IonuDeviceEntry
mpagenkodff5dda2020-08-28 11:52:01 +0000105 tpProcMutex sync.RWMutex
mpagenkodff5dda2020-08-28 11:52:01 +0000106 chTpConfigProcessingStep chan uint8
Girish Gowdra041dcb32020-11-16 16:54:30 -0800107 mapUniTpIndication map[uniTP]*tTechProfileIndication //use pointer values to ease assignments to the map
108 mapPonAniConfig map[uniTP]*tcontGemList //per UNI: use pointer values to ease assignments to the map
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000109 PAniConfigFsm map[uniTP]*UniPonAniConfigFsm
Girish Gowdra041dcb32020-11-16 16:54:30 -0800110 procResult map[uniTP]error //error indication of processing
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800111 mutexTPState sync.RWMutex
Girish Gowdra041dcb32020-11-16 16:54:30 -0800112 tpProfileExists map[uniTP]bool
mpagenko73143992021-04-09 15:17:10 +0000113 tpProfileResetting map[uniTP]bool
mpagenko8b07c1b2020-11-26 10:36:31 +0000114 mapRemoveGemEntry map[uniTP]*gemPortParamStruct //per UNI: pointer to GemEntry to be removed
mpagenkoaf801632020-07-03 10:00:42 +0000115}
116
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000117func (onuTP *OnuUniTechProf) multicastConfiguredForOtherUniTps(ctx context.Context, uniTpKey uniTP) bool {
118 for _, aniFsm := range onuTP.PAniConfigFsm {
ozgecanetsia72e1c9f2021-05-26 17:26:29 +0300119 if aniFsm.uniTpKey.uniID == uniTpKey.uniID && aniFsm.uniTpKey.tpID == uniTpKey.tpID {
120 continue
121 }
122 if aniFsm.hasMulticastGem(ctx) {
123 return true
124 }
125 }
126 return false
127}
128
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000129//NewOnuUniTechProf returns the instance of a OnuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000130//(one instance per ONU/deviceHandler for all possible UNI's)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000131func NewOnuUniTechProf(ctx context.Context, aDeviceHandler cmn.IdeviceHandler, aOnuDev cmn.IonuDeviceEntry) *OnuUniTechProf {
132
133 var onuTP OnuUniTechProf
134 onuTP.deviceID = aDeviceHandler.GetDeviceID()
135 logger.Debugw(ctx, "init-OnuUniTechProf", log.Fields{"device-id": onuTP.deviceID})
mpagenkoaf801632020-07-03 10:00:42 +0000136 onuTP.baseDeviceHandler = aDeviceHandler
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000137 onuTP.onuDevice = aOnuDev
mpagenkodff5dda2020-08-28 11:52:01 +0000138 onuTP.chTpConfigProcessingStep = make(chan uint8)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800139 onuTP.mapUniTpIndication = make(map[uniTP]*tTechProfileIndication)
140 onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList)
141 onuTP.procResult = make(map[uniTP]error)
142 onuTP.tpProfileExists = make(map[uniTP]bool)
mpagenko73143992021-04-09 15:17:10 +0000143 onuTP.tpProfileResetting = make(map[uniTP]bool)
mpagenko8b07c1b2020-11-26 10:36:31 +0000144 onuTP.mapRemoveGemEntry = make(map[uniTP]*gemPortParamStruct)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000145
mpagenkoaf801632020-07-03 10:00:42 +0000146 return &onuTP
147}
148
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000149// LockTpProcMutex locks OnuUniTechProf processing mutex
150func (onuTP *OnuUniTechProf) LockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000151 onuTP.tpProcMutex.Lock()
152}
153
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000154// UnlockTpProcMutex unlocks OnuUniTechProf processing mutex
155func (onuTP *OnuUniTechProf) UnlockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000156 onuTP.tpProcMutex.Unlock()
157}
158
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000159// ResetTpProcessingErrorIndication resets the internal error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000160// need to be called before evaluation of any subsequent processing (given by waitForTpCompletion())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000161func (onuTP *OnuUniTechProf) ResetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) {
mpagenko73143992021-04-09 15:17:10 +0000162 onuTP.mutexTPState.Lock()
163 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800164 onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000165}
166
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000167// GetTpProcessingErrorIndication - TODO: add comment
168func (onuTP *OnuUniTechProf) GetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error {
mpagenko73143992021-04-09 15:17:10 +0000169 onuTP.mutexTPState.RLock()
170 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800171 return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}]
mpagenko3dbcdd22020-07-22 07:38:45 +0000172}
173
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000174// ConfigureUniTp checks existing tp resources to configure and starts the corresponding OMCI configuation of the UNI port
mpagenko3dbcdd22020-07-22 07:38:45 +0000175// all possibly blocking processing must be run in background to allow for deadline supervision!
176// but take care on sequential background processing when needed (logical dependencies)
Himani Chawla4d908332020-08-31 12:30:20 +0530177// use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000178func (onuTP *OnuUniTechProf) ConfigureUniTp(ctx context.Context,
Girish Gowdra50e56422021-06-01 16:46:04 -0700179 aUniID uint8, aPathString string, tpInst tech_profile.TechProfileInstance, wg *sync.WaitGroup) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000180 defer wg.Done() //always decrement the waitGroup on return
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530181 logger.Info(ctx, "configure the Uni according to TpPath", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000182 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000183 tpID, err := cmn.GetTpIDFromTpPath(aPathString)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800184 uniTpKey := uniTP{uniID: aUniID, tpID: tpID}
185 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000186 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 -0800187 return
188 }
mpagenkoaf801632020-07-03 10:00:42 +0000189
mpagenko3dbcdd22020-07-22 07:38:45 +0000190 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000191 var pCurrentUniPort *cmn.OnuUniPort
192 for _, uniPort := range *onuTP.baseDeviceHandler.GetUniEntityMap() {
mpagenko3dbcdd22020-07-22 07:38:45 +0000193 // only if this port is validated for operState transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000194 if uniPort.UniID == aUniID {
mpagenko3dbcdd22020-07-22 07:38:45 +0000195 pCurrentUniPort = uniPort
196 break //found - end search loop
197 }
198 }
199 if pCurrentUniPort == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000200 logger.Errorw(ctx, "TechProfile configuration aborted: requested uniID not found in PortDB",
mpagenko73143992021-04-09 15:17:10 +0000201 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
202 onuTP.mutexTPState.Lock()
203 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800204 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200205 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000206 return
207 }
mpagenkoaf801632020-07-03 10:00:42 +0000208
mpagenko73143992021-04-09 15:17:10 +0000209 if onuTP.getProfileResetting(uniTpKey) {
210 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
211 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
212 onuTP.mutexTPState.Lock()
213 defer onuTP.mutexTPState.Unlock()
214 onuTP.procResult[uniTpKey] = fmt.Errorf(
215 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
216 aUniID, onuTP.deviceID)
217 return
218 }
mpagenkodff5dda2020-08-28 11:52:01 +0000219 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
mpagenkoaf801632020-07-03 10:00:42 +0000220
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000221 //according to UpdateOnuUniTpPath() logic the assumption here is, that this configuration is only called
mpagenko3dbcdd22020-07-22 07:38:45 +0000222 // in case the KVPath has changed for the given UNI,
223 // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
224 // (ANI) configuration of this port has to be removed first
225 // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
226 // existence of configuration can be detected based on tp stored TCONT's
Andrea Campanella6515c582020-10-05 11:25:00 +0200227 //TODO:
mpagenko3dbcdd22020-07-22 07:38:45 +0000228 /* if tcontMap not empty {
229 go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000230 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000231 //timeout or error detected
232 return
233 }
234 clear tcontMap
235 }
236
237 processingStep++
238 */
Girish Gowdra50e56422021-06-01 16:46:04 -0700239 go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, tpInst, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000240 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000241 //timeout or error detected
mpagenko73143992021-04-09 15:17:10 +0000242 onuTP.mutexTPState.RLock()
Girish Gowdra24dd1132021-07-06 15:25:40 -0700243 ok := onuTP.tpProfileExists[uniTpKey]
244 onuTP.mutexTPState.RUnlock()
245 if ok {
mpagenko01e726e2020-10-23 09:45:29 +0000246 //ignore the internal error in case the new profile is already configured
247 // and abort the processing here
248 return
249 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000250 logger.Errorw(ctx, "tech-profile related configuration aborted on read",
mpagenko01e726e2020-10-23 09:45:29 +0000251 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000252 onuTP.mutexTPState.Lock()
253 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800254 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200255 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000256 return
257 }
mpagenko73143992021-04-09 15:17:10 +0000258 if onuTP.getProfileResetting(uniTpKey) {
259 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
260 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
261 onuTP.mutexTPState.Lock()
262 defer onuTP.mutexTPState.Unlock()
263 onuTP.procResult[uniTpKey] = fmt.Errorf(
264 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
265 aUniID, onuTP.deviceID)
266 return
267 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000268 processingStep++
Girish Gowdra041dcb32020-11-16 16:54:30 -0800269
mpagenko73143992021-04-09 15:17:10 +0000270 //ensure read protection for access to mapPonAniConfig
271 onuTP.mutexTPState.RLock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800272 valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey]
mpagenko73143992021-04-09 15:17:10 +0000273 onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800274 if existPA {
275 if valuePA != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000276 //Config data for this uni and and at least TCont Index 0 exist
mpagenko8b07c1b2020-11-26 10:36:31 +0000277 if err := onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000278 logger.Errorw(ctx, "tech-profile related FSM could not be started",
mpagenko8b07c1b2020-11-26 10:36:31 +0000279 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000280 onuTP.mutexTPState.Lock()
281 defer onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000282 onuTP.procResult[uniTpKey] = err
283 return
284 }
mpagenkodff5dda2020-08-28 11:52:01 +0000285 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000286 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
287 logger.Warnw(ctx, "tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000288 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800289
mpagenko73143992021-04-09 15:17:10 +0000290 onuTP.mutexTPState.Lock()
291 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800292 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200293 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530294 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000295 //which requires to reset it to allow for new usage, e.g. also on a different UNI
296 //(without that it would be reset on device down indication latest)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000297 if _, ok := onuTP.PAniConfigFsm[uniTpKey]; ok {
298 _ = onuTP.PAniConfigFsm[uniTpKey].PAdaptFsm.PFsm.Event(aniEvReset)
mpagenko73143992021-04-09 15:17:10 +0000299 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000300 return
mpagenkoaf801632020-07-03 10:00:42 +0000301 }
302 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000303 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000304 logger.Errorw(ctx, "no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000305 "device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000306 onuTP.mutexTPState.Lock()
307 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800308 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 +0200309 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000310 return
mpagenkoaf801632020-07-03 10:00:42 +0000311 }
312 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000313 logger.Errorw(ctx, "no PonAni data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000314 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800315
mpagenko73143992021-04-09 15:17:10 +0000316 onuTP.mutexTPState.Lock()
317 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800318 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 +0200319 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000320 return
mpagenkoaf801632020-07-03 10:00:42 +0000321 }
322}
323
mpagenko3dbcdd22020-07-22 07:38:45 +0000324/* internal methods *********************/
ozgecanetsia4b232302020-11-11 10:58:10 +0300325// nolint: gocyclo
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000326func (onuTP *OnuUniTechProf) readAniSideConfigFromTechProfile(
Girish Gowdra50e56422021-06-01 16:46:04 -0700327 ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, tpInst tech_profile.TechProfileInstance, aProcessingStep uint8) {
328 var err error
mpagenko3dbcdd22020-07-22 07:38:45 +0000329 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
330 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
331 subStringSlice := strings.Split(aPathString, "/")
332 if len(subStringSlice) <= 2 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000333 logger.Errorw(ctx, "invalid path name format",
mpagenko3dbcdd22020-07-22 07:38:45 +0000334 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000335 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000336 return
337 }
338
mpagenko73143992021-04-09 15:17:10 +0000339 //ensure write protection for access to used maps
340 onuTP.mutexTPState.Lock()
341 defer onuTP.mutexTPState.Unlock()
342
343 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
344 onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false
345
mpagenko3dbcdd22020-07-22 07:38:45 +0000346 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000347 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
348 // then we throw a warning, set an internal error and abort with error,
349 // which is later re-defined to success response to OLT adapter
350 // if TPId has changed, current data is removed (note that the ONU config state may be
351 // ambivalent in such a case)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800352 if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000353 logger.Warnw(ctx, "Some active profile entry at reading new TechProfile",
mpagenko3dbcdd22020-07-22 07:38:45 +0000354 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800355 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
356 if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID {
mpagenko01e726e2020-10-23 09:45:29 +0000357 // ProfId not changed - assume profile to be still the same
358 // anyway this should not appear after full support of profile (Gem/TCont) removal
dbainbri4d3a0dc2020-12-02 00:33:42 +0000359 logger.Warnw(ctx, "New TechProfile already exists - aborting configuration",
mpagenko01e726e2020-10-23 09:45:29 +0000360 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800361 onuTP.tpProfileExists[uniTPKey] = true
mpagenko01e726e2020-10-23 09:45:29 +0000362 onuTP.chTpConfigProcessingStep <- 0 //error indication
363 return
364 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000365 //delete on the mapUniTpIndication map not needed, just overwritten later
366 //delete on the PonAniConfig map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800367 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenko3dbcdd22020-07-22 07:38:45 +0000368 } else {
369 // this is normal processing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800370 onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
mpagenko3dbcdd22020-07-22 07:38:45 +0000371 }
372
Girish Gowdra041dcb32020-11-16 16:54:30 -0800373 onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000374 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
Girish Gowdra041dcb32020-11-16 16:54:30 -0800375 onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID
376 onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false
377 onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000378 logger.Debugw(ctx, "tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000379 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800380 "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType,
381 "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000382
mpagenko01e726e2020-10-23 09:45:29 +0000383 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000384 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800385 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000386
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000387 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000388 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra50e56422021-06-01 16:46:04 -0700389 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocId)
Himani Chawla4d908332020-08-31 12:30:20 +0530390 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000391 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
Girish Gowdra50e56422021-06-01 16:46:04 -0700392 if tpInst.UsScheduler.QSchedPolicy == tech_profile.SchedulingPolicy_StrictPriority {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800393 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000394 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000395 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800396 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000397 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000398 loNumGemPorts := tpInst.NumGemPorts
399 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000400 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000401 if uint32(pos) == loNumGemPorts {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000402 logger.Debugw(ctx, "PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
mpagenko1cc3cb42020-07-27 15:24:38 +0000403 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000404 break
405 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000406 if pos == 0 {
407 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
408 loGemPortRead = true
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000409 }
Himani Chawla1c136902020-12-10 16:30:59 +0530410 //for all GemPorts we need to extend the mapGemPortParams
Girish Gowdra50e56422021-06-01 16:46:04 -0700411 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)] = &gemPortParamStruct{}
Himani Chawla1c136902020-12-10 16:30:59 +0530412
Girish Gowdra50e56422021-06-01 16:46:04 -0700413 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortID =
414 uint16(content.GemportId)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000415 //direction can be correlated later with Downstream list,
416 // for now just assume bidirectional (upstream never exists alone)
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +0000417 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].direction = cGemDirBiDirect
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000418 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
Girish Gowdra50e56422021-06-01 16:46:04 -0700419 if content.PriorityQ > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000420 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Girish Gowdra50e56422021-06-01 16:46:04 -0700421 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQ})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000422 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800423 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000424 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000425 return
426 }
Girish Gowdra50e56422021-06-01 16:46:04 -0700427 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].prioQueueIndex =
428 uint8(content.PriorityQ)
429 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530430 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000431 if content.AesEncryption == "True" {
Girish Gowdra50e56422021-06-01 16:46:04 -0700432 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000433 } else {
Girish Gowdra50e56422021-06-01 16:46:04 -0700434 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000435 }
Girish Gowdra50e56422021-06-01 16:46:04 -0700436 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].discardPolicy =
437 content.DiscardPolicy.String()
438 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].queueSchedPolicy =
439 content.SchedulingPolicy.String()
mpagenko3dbcdd22020-07-22 07:38:45 +0000440 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Girish Gowdra50e56422021-06-01 16:46:04 -0700441 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000442 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000443 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300444
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300445 for _, downstreamContent := range tpInst.DownstreamGemPortAttributeList {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000446 logger.Debugw(ctx, "Operating on Downstream Gem Port", log.Fields{"downstream-gem": downstreamContent})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300447 //Commenting this out due to faliure, needs investigation
448 //if uint32(pos) == loNumGemPorts {
449 // logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
450 // log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
451 // break
452 //}
453 isMulticast := false
ozgecanetsia4b232302020-11-11 10:58:10 +0300454 //Flag is defined as string in the TP in voltha-lib-go, parsing it from string
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300455 if downstreamContent.IsMulticast != "" {
456 isMulticast, err = strconv.ParseBool(downstreamContent.IsMulticast)
457 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000458 logger.Errorw(ctx, "multicast-error-config-unknown-flag-in-technology-profile",
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000459 log.Fields{"device-id": onuTP.deviceID, "UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "error": err})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300460 continue
461 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300462 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000463 logger.Infow(ctx, "Gem Port is multicast", log.Fields{"isMulticast": isMulticast})
ozgecanetsia4b232302020-11-11 10:58:10 +0300464 if isMulticast {
Girish Gowdra50e56422021-06-01 16:46:04 -0700465 mcastGemID := uint16(downstreamContent.MulticastGemId)
ozgecanetsia4b232302020-11-11 10:58:10 +0300466 _, existing := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID]
467 if existing {
468 //GEM port was previously configured, avoid setting multicast attributes
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000469 logger.Errorw(ctx, "multicast-error-config-existing-gem-port-config", log.Fields{"device-id": onuTP.deviceID,
470 "UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "key": mcastGemID})
ozgecanetsia4b232302020-11-11 10:58:10 +0300471 continue
472 } else {
473 //GEM port is not configured, setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000474 logger.Infow(ctx, "creating-multicast-gem-port", log.Fields{"uniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300475 "gemPortId": mcastGemID, "key": mcastGemID})
476
477 //for all further GemPorts we need to extend the mapGemPortParams
478 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID] = &gemPortParamStruct{}
479
480 //Separate McastGemId is derived from OMCI-lib-go, if not needed first needs to be removed there.
481 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortID = mcastGemID
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +0000482 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].direction = cGemDirAniToUni
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300483
484 if downstreamContent.AesEncryption == "True" {
485 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 1
486 } else {
487 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 0
488 }
489
490 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
Girish Gowdra50e56422021-06-01 16:46:04 -0700491 if downstreamContent.PriorityQ > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000492 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Girish Gowdra50e56422021-06-01 16:46:04 -0700493 log.Fields{"device-id": onuTP.deviceID, "index": mcastGemID, "PrioQueue": downstreamContent.PriorityQ})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300494 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
495 delete(onuTP.mapPonAniConfig, uniTPKey)
496 onuTP.chTpConfigProcessingStep <- 0 //error indication
497 return
ozgecanetsia4b232302020-11-11 10:58:10 +0300498 }
499 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].prioQueueIndex =
Girish Gowdra50e56422021-06-01 16:46:04 -0700500 uint8(downstreamContent.PriorityQ)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300501 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].pbitString =
502 strings.TrimPrefix(downstreamContent.PbitMap, binaryStringPrefix)
503
504 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].discardPolicy =
Girish Gowdra50e56422021-06-01 16:46:04 -0700505 downstreamContent.DiscardPolicy.String()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300506 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueSchedPolicy =
Girish Gowdra50e56422021-06-01 16:46:04 -0700507 downstreamContent.SchedulingPolicy.String()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300508 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
509 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueWeight =
510 uint8(downstreamContent.Weight)
511
ozgecanetsia4b232302020-11-11 10:58:10 +0300512 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].isMulticast = isMulticast
513 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].multicastGemPortID =
Girish Gowdra50e56422021-06-01 16:46:04 -0700514 uint16(downstreamContent.MulticastGemId)
515 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].staticACL = downstreamContent.StaticAccessControlList
516 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].dynamicACL = downstreamContent.DynamicAccessControlList
ozgecanetsia4b232302020-11-11 10:58:10 +0300517 }
518 }
519 }
520
Himani Chawla4d908332020-08-31 12:30:20 +0530521 if !loGemPortRead {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000522 logger.Errorw(ctx, "PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000523 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000524 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800525 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000526 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000527 return
528 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000529 //logger does not simply output the given structures, just give some example debug values
dbainbri4d3a0dc2020-12-02 00:33:42 +0000530 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000531 "device-id": onuTP.deviceID, "uni-id": aUniID,
532 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
Himani Chawla1c136902020-12-10 16:30:59 +0530533 for gemPortID, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000534 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530535 "GemPort": gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000536 "QueueScheduling": gemEntry.queueSchedPolicy})
537 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000538
mpagenkodff5dda2020-08-28 11:52:01 +0000539 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000540}
541
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000542func (onuTP *OnuUniTechProf) setAniSideConfigFromTechProfile(
543 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *cmn.OnuUniPort, aProcessingStep uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000544
545 //OMCI transfer of ANI data acc. to mapPonAniConfig
546 // also the FSM's are running in background,
mpagenko8b07c1b2020-11-26 10:36:31 +0000547 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800548 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000549 if onuTP.PAniConfigFsm == nil {
550 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, cmn.OmciAniConfigDone, aProcessingStep)
551 } else if _, ok := onuTP.PAniConfigFsm[uniTPKey]; !ok {
552 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, cmn.OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000553 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000554 //AniConfigFsm already init
dbainbri4d3a0dc2020-12-02 00:33:42 +0000555 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000556}
557
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000558// DeleteTpResource removes Resources from the ONU's specified Uni
mpagenko73143992021-04-09 15:17:10 +0000559// nolint: gocyclo
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000560func (onuTP *OnuUniTechProf) DeleteTpResource(ctx context.Context,
561 aUniID uint8, aTpID uint8, aPathString string, aResource ResourceEntry, aEntryID uint32,
mpagenko8b07c1b2020-11-26 10:36:31 +0000562 wg *sync.WaitGroup) {
563 defer wg.Done()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000564 logger.Debugw(ctx, "will remove TP resources from ONU's UNI", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000565 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "Resource": aResource})
566 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
567
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000568 if CResourceGemPort == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000569 logger.Debugw(ctx, "remove GemPort from the list of existing ones of the TP", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000570 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID})
571
mpagenko73143992021-04-09 15:17:10 +0000572 //ensure read protection for access to mapPonAniConfig
573 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000574 // check if the requested GemPort exists in the DB, indicate it to the FSM
575 // store locally to remove it from DB later on success
576 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
577 if pLocAniConfigOnUni == nil {
mpagenko73143992021-04-09 15:17:10 +0000578 onuTP.mutexTPState.RUnlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000579 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000580 logger.Debugw(ctx, "AniConfig or GemEntry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000581 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
582 return
583 }
mpagenko73143992021-04-09 15:17:10 +0000584 onuTP.mutexTPState.RUnlock()
585
Himani Chawla1c136902020-12-10 16:30:59 +0530586 for gemPortID, gemEntry := range pLocAniConfigOnUni.mapGemPortParams {
587 if gemPortID == uint16(aEntryID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000588 //GemEntry to be deleted found
Himani Chawla1c136902020-12-10 16:30:59 +0530589 gemEntry.removeGemID = gemPortID //store the index for later removal
590 onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemPortID]
dbainbri4d3a0dc2020-12-02 00:33:42 +0000591 logger.Debugw(ctx, "Remove-GemEntry stored", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530592 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000593 break //abort loop, always only one GemPort to remove
594 }
595 }
596 if onuTP.mapRemoveGemEntry[uniTPKey] == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000597 logger.Errorw(ctx, "GemPort removal aborted - GemPort not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000598 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
599 /* Do not set some error indication to the outside system interface on delete
600 assume there is nothing to be deleted internally and hope a new config request will recover the situation
601 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s",
602 aEntryID, aUniID, onuTP.deviceID)
603 */
604 return
605 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000606 if onuTP.baseDeviceHandler.IsReadyForOmciConfig() {
mpagenko8b07c1b2020-11-26 10:36:31 +0000607 // check that the TpConfigRequest was done before
608 // -> that is implicitly done using the AniConfigFsm,
609 // which must be in the according state to remove something
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000610 if onuTP.PAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000611 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000612 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
613 /* Do not set some error indication to the outside system interface on delete (see above)
614 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s",
615 aUniID, onuTP.deviceID)
616 */
617 //if the FSM is not valid, also TP related remove data should not be valid:
618 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000619 //ensure write protection for access to mapPonAniConfig
620 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530621 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000622 // remove the removeEntry
623 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000624 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000625 return
626 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000627 if _, ok := onuTP.PAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000628 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000629 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
630 /* Do not set some error indication to the outside system interface on delete (see above)
631 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid",
632 aUniID, onuTP.deviceID, aTpID)
633 */
634 //if the FSM is not valid, also TP related remove data should not be valid:
635 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000636 //ensure write protection for access to mapPonAniConfig
637 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530638 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000639 // remove the removeEntry
640 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000641 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000642 return
643 }
mpagenko73143992021-04-09 15:17:10 +0000644 if onuTP.getProfileResetting(uniTPKey) {
645 logger.Debugw(ctx, "aborting GemRemoval on FSM, reset requested in parallel", log.Fields{
646 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
647 //ensure write protection for access to mapPonAniConfig
648 onuTP.mutexTPState.Lock()
649 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
650 // remove the removeEntry
651 delete(onuTP.mapRemoveGemEntry, uniTPKey)
652 onuTP.mutexTPState.Unlock()
653 return
654 }
655 // initiate OMCI GemPort related removal
656 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
657 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000658 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemGemiw, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000659 //even if the FSM invocation did not work we don't indicate a problem within procResult
660 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
661 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
662 return
663 }
664 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000665 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
666 logger.Warnw(ctx, "GemPort removal aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000667 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
668 //even if the FSM delete execution did not work we don't indicate a problem within procResult
669 //we should never respond to delete with error ...
670 //this issue here means that the AniConfigFsm has not finished successfully
671 //which requires to reset it to allow for new usage, e.g. also on a different UNI
672 //(without that it would be reset on device down indication latest)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000673 if _, ok := onuTP.PAniConfigFsm[uniTPKey]; ok {
674 _ = onuTP.PAniConfigFsm[uniTPKey].PAdaptFsm.PFsm.Event(aniEvReset)
mpagenko73143992021-04-09 15:17:10 +0000675 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000676 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
677 return
678 }
679 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000680 //if we can't do the OMCI processing we also suppress the ProcStatusUpdate
681 //this is needed as in the device-down case where all FSM's are getting reset and internal data gets cleared
682 //as a consequence a possible remove-flow does not see any dependency on the TechProfile anymore and is executed (pro forma) directly
683 //a later TechProfile removal would cause the device-reason to be updated to 'techProfile-delete-success' which is not the expected state
684 // and anyway is no real useful information at that stage
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000685 logger.Debugw(ctx, "UniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{
686 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.GetDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000687 }
688 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000689 //ensure write protection for access to mapPonAniConfig
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000690 logger.Debugw(ctx, "UniPonAniConfigFsm removing gem from config data and clearing ani FSM", log.Fields{
Mahir Gunyel9545be22021-07-04 15:53:16 -0700691 "device-id": onuTP.deviceID, "gem-id": onuTP.mapRemoveGemEntry[uniTPKey].removeGemID, "uniTPKey": uniTPKey})
mpagenko73143992021-04-09 15:17:10 +0000692 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530693 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000694 // remove the removeEntry
695 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000696 onuTP.mutexTPState.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000697 } else { //if CResourceTcont == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000698 logger.Debugw(ctx, "reset TCont with AllocId", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000699 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID})
700
mpagenko73143992021-04-09 15:17:10 +0000701 //ensure read protection for access to mapPonAniConfig
702 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000703 // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM
704 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
705 if pLocAniConfigOnUni == nil {
706 // No relevant entry exists anymore - acknowledge success
mpagenko73143992021-04-09 15:17:10 +0000707 onuTP.mutexTPState.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000708 logger.Debugw(ctx, "AniConfig or TCont entry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000709 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
710 return
711 }
mpagenko73143992021-04-09 15:17:10 +0000712 onuTP.mutexTPState.RUnlock()
713
mpagenko8b07c1b2020-11-26 10:36:31 +0000714 if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000715 logger.Errorw(ctx, "TCont removal aborted - indicated AllocId not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000716 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID})
717 /* Do not set some error indication to the outside system interface on delete
718 assume there is nothing to be deleted internally and hope a new config request will recover the situation
719 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s",
720 aEntryID, aUniID, onuTP.deviceID)
721 */
722 return
723 }
724 //T-Cont to be reset found
dbainbri4d3a0dc2020-12-02 00:33:42 +0000725 logger.Debugw(ctx, "Reset-T-Cont AllocId found - valid", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000726 "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000727 if onuTP.PAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000728 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000729 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
730 /* Do not set some error indication to the outside system interface on delete (see above)
731 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s",
732 aUniID, onuTP.deviceID)
733 */
mpagenko8b07c1b2020-11-26 10:36:31 +0000734 return
735 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000736 if _, ok := onuTP.PAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000737 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000738 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
739 //even if the FSM invocation did not work we don't indicate a problem within procResult
740 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
741 //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 +0000742 return
743 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000744 if onuTP.baseDeviceHandler.IsReadyForOmciConfig() {
mpagenko8b07c1b2020-11-26 10:36:31 +0000745 // check that the TpConfigRequest was done before
746 // -> that is implicitly done using the AniConfigFsm,
747 // which must be in the according state to remove something
mpagenko73143992021-04-09 15:17:10 +0000748 if onuTP.getProfileResetting(uniTPKey) {
749 logger.Debugw(ctx, "aborting TCont removal on FSM, reset requested in parallel", log.Fields{
750 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
751 return
752 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000753 // initiate OMCI TCont related cleanup
754 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
755 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000756 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemTcontPath, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000757 //even if the FSM invocation did not work we don't indicate a problem within procResult
758 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
759 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
760 return
761 }
762 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000763 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
764 logger.Warnw(ctx, "TCont cleanup aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000765 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
766 //even if the FSM delete execution did not work we don't indicate a problem within procResult
767 //we should never respond to delete with error ...
768 //this issue here means that the AniConfigFsm has not finished successfully
769 //which requires to reset it to allow for new usage, e.g. also on a different UNI
770 //(without that it would be reset on device down indication latest)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000771 if _, ok := onuTP.PAniConfigFsm[uniTPKey]; ok {
772 _ = onuTP.PAniConfigFsm[uniTPKey].PAdaptFsm.PFsm.Event(aniEvReset)
mpagenko73143992021-04-09 15:17:10 +0000773 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000774 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
775 return
776 }
777 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000778 //see gemPort comments
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000779 logger.Debugw(ctx, "UniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{
780 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.GetDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000781 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000782 }
Mahir Gunyel9545be22021-07-04 15:53:16 -0700783
784}
785
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000786// IsTechProfileConfigCleared - TODO: add comment
787func (onuTP *OnuUniTechProf) IsTechProfileConfigCleared(ctx context.Context, uniID uint8, tpID uint8) bool {
Mahir Gunyel9545be22021-07-04 15:53:16 -0700788 uniTPKey := uniTP{uniID: uniID, tpID: tpID}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000789 logger.Debugw(ctx, "IsTechProfileConfigCleared", log.Fields{"device-id": onuTP.deviceID})
Mahir Gunyel9545be22021-07-04 15:53:16 -0700790 if onuTP.mapPonAniConfig[uniTPKey] != nil {
791 mapGemPortParams := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams
792 unicastGemCount := 0
793 for _, gemEntry := range mapGemPortParams {
794 if !gemEntry.isMulticast {
795 unicastGemCount++
796 }
797 }
798 if unicastGemCount == 0 || onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID == 0 {
799 logger.Debugw(ctx, "clearing-ani-side-config", log.Fields{
800 "device-id": onuTP.deviceID, "uniTpKey": uniTPKey})
801 onuTP.clearAniSideConfig(ctx, uniID, tpID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000802 if _, ok := onuTP.PAniConfigFsm[uniTPKey]; ok {
803 _ = onuTP.PAniConfigFsm[uniTPKey].PAdaptFsm.PFsm.Event(aniEvReset)
Mahir Gunyel9545be22021-07-04 15:53:16 -0700804 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000805 go onuTP.baseDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OmciAniResourceRemoved)
Mahir Gunyel9545be22021-07-04 15:53:16 -0700806 return true
807 }
mpagenko7d6bb022021-03-11 15:07:55 +0000808 }
Mahir Gunyel9545be22021-07-04 15:53:16 -0700809 return false
mpagenko3dbcdd22020-07-22 07:38:45 +0000810}
811
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000812func (onuTP *OnuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000813 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000814 select {
815 case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000816 logger.Warnw(ctx, "processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000817 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000818 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000819 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000820 if rxStep == aProcessingStep {
821 return true
822 }
823 //all other values are not accepted - including 0 for error indication
dbainbri4d3a0dc2020-12-02 00:33:42 +0000824 logger.Warnw(ctx, "Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000825 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000826 "wantedStep": aProcessingStep, "haveStep": rxStep})
827 return false
828 }
829}
830
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000831// createAniConfigFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000832func (onuTP *OnuUniTechProf) createAniConfigFsm(ctx context.Context, aUniID uint8, aTpID uint8,
833 apCurrentUniPort *cmn.OnuUniPort, devEvent cmn.OnuDeviceEvent, aProcessingStep uint8) error {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530834 logger.Info(ctx, "createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000835 chAniConfigFsm := make(chan cmn.Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800836 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000837 if onuTP.onuDevice == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000838 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000839 return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000840 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000841 pAniCfgFsm := NewUniPonAniConfigFsm(ctx, onuTP.onuDevice.GetDevOmciCC(), apCurrentUniPort, onuTP,
Holger Hildebrandtc408f492022-07-14 08:39:24 +0000842 onuTP.onuDevice.GetOnuDB(), aTpID, onuTP.mapUniTpIndication[uniTPKey].techProfileType, devEvent,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000843 "AniConfigFsm", onuTP.baseDeviceHandler, onuTP.onuDevice, chAniConfigFsm)
mpagenko8b07c1b2020-11-26 10:36:31 +0000844 if pAniCfgFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000845 logger.Errorw(ctx, "AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000846 return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000847 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000848 if onuTP.PAniConfigFsm == nil {
849 onuTP.PAniConfigFsm = make(map[uniTP]*UniPonAniConfigFsm)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800850 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000851 onuTP.PAniConfigFsm[uniTPKey] = pAniCfgFsm
dbainbri4d3a0dc2020-12-02 00:33:42 +0000852 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000853}
854
mpagenko3dbcdd22020-07-22 07:38:45 +0000855// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000856func (onuTP *OnuUniTechProf) runAniConfigFsm(ctx context.Context, aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000857 /* Uni related ANI config procedure -
858 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
859 */
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530860 logger.Info(ctx, "Run AniConfigFSM with", log.Fields{
861 "ProcessingStep": aProcessingStep, "device-id": onuTP.deviceID, "UniId": aUniID, "TpID": aTpID, "event": aEvent})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800862 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
863
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000864 pACStatemachine := onuTP.PAniConfigFsm[uniTpKey].PAdaptFsm.PFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000865 if pACStatemachine != nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000866 if aEvent == aniEvStart {
867 if !pACStatemachine.Is(aniStDisabled) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000868 logger.Errorw(ctx, "wrong state of AniConfigFSM to start - want: Disabled", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000869 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000870 // maybe try a FSM reset and then again ... - TODO: add comment!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000871 return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000872 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000873 } else if !pACStatemachine.Is(aniStConfigDone) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000874 logger.Errorw(ctx, "wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000875 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000876 return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000877 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000878 //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000879 onuTP.PAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
mpagenko8b07c1b2020-11-26 10:36:31 +0000880 if err := pACStatemachine.Event(aEvent); err != nil {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000881 logger.Errorw(ctx, "AniConfigFSM: can't trigger event", log.Fields{"device-id": onuTP.deviceID, "err": err})
mpagenko8b07c1b2020-11-26 10:36:31 +0000882 return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID)
883 }
884 /***** AniConfigFSM event notified */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000885 logger.Debugw(ctx, "AniConfigFSM event notified", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000886 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent})
887 return nil
mpagenko3dbcdd22020-07-22 07:38:45 +0000888 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000889 logger.Errorw(ctx, "AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000890 // maybe try a FSM reset and then again ... - TODO: add comment!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000891 return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID)
mpagenkoaf801632020-07-03 10:00:42 +0000892}
mpagenkodff5dda2020-08-28 11:52:01 +0000893
Girish Gowdra041dcb32020-11-16 16:54:30 -0800894// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000895func (onuTP *OnuUniTechProf) clearAniSideConfig(ctx context.Context, aUniID uint8, aTpID uint8) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000896 logger.Debugw(ctx, "removing TpIndication and PonAniConfig data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000897 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800898 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
899
900 onuTP.mutexTPState.Lock()
901 defer onuTP.mutexTPState.Unlock()
mpagenko73143992021-04-09 15:17:10 +0000902 //deleting a map entry should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800903 delete(onuTP.mapUniTpIndication, uniTpKey)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800904 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko73143992021-04-09 15:17:10 +0000905 delete(onuTP.procResult, uniTpKey)
906 delete(onuTP.tpProfileExists, uniTpKey)
907 delete(onuTP.tpProfileResetting, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000908}
909
mpagenkodff5dda2020-08-28 11:52:01 +0000910// setConfigDone sets the requested techProfile config state (if possible)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000911func (onuTP *OnuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800912 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
913 onuTP.mutexTPState.Lock()
914 defer onuTP.mutexTPState.Unlock()
915 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
916 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000917 } //else: the state is just ignored (does not exist)
918}
919
920// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000921func (onuTP *OnuUniTechProf) getTechProfileDone(ctx context.Context, aUniID uint8, aTpID uint8) bool {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800922 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000923 onuTP.mutexTPState.RLock()
924 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800925 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
926 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
927 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000928 logger.Debugw(ctx, "TechProfile not relevant for requested flow config - waiting on delete",
mpagenko2418ab02020-11-12 12:58:06 +0000929 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
930 return false //still waiting for removal of this techProfile first
931 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800932 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000933 }
934 }
935 //for all other constellations indicate false = Config not done
936 return false
937}
mpagenko2418ab02020-11-12 12:58:06 +0000938
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000939// SetProfileToDelete sets the requested techProfile toDelete state (if possible)
940func (onuTP *OnuUniTechProf) SetProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800941 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
942 onuTP.mutexTPState.Lock()
943 defer onuTP.mutexTPState.Unlock()
944 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
945 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000946 } //else: the state is just ignored (does not exist)
947}
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300948
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000949func (onuTP *OnuUniTechProf) getMulticastGemPorts(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300950 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000951 onuTP.mutexTPState.RLock()
952 defer onuTP.mutexTPState.RUnlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300953 gemPortIds := make([]uint16, 0)
954 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
955 for _, gemPortParam := range techProfile.mapGemPortParams {
956 if gemPortParam.isMulticast {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000957 logger.Debugw(ctx, "Detected multicast gemPort", log.Fields{"device-id": onuTP.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300958 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
959 "mcastGemId": gemPortParam.multicastGemPortID})
960 gemPortIds = append(gemPortIds, gemPortParam.multicastGemPortID)
961 }
962 }
963 } //else: the state is just ignored (does not exist)
964 return gemPortIds
965}
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800966
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000967func (onuTP *OnuUniTechProf) getBidirectionalGemPortIDsForTP(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
ozgecanetsia82b91a62021-05-21 18:54:49 +0300968 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
969 onuTP.mutexTPState.RLock()
970 defer onuTP.mutexTPState.RUnlock()
971 gemPortIds := make([]uint16, 0)
972 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
973 logger.Debugw(ctx, "TechProfile exist", log.Fields{"device-id": onuTP.deviceID})
974 for _, gemPortParam := range techProfile.mapGemPortParams {
975 if !gemPortParam.isMulticast {
976 logger.Debugw(ctx, "Detected unicast gemPort", log.Fields{"device-id": onuTP.deviceID,
977 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
978 "GemId": gemPortParam.multicastGemPortID})
979 gemPortIds = append(gemPortIds, gemPortParam.gemPortID)
980 }
981 }
982 } else {
983 logger.Debugw(ctx, "TechProfile doesn't exist", log.Fields{"device-id": onuTP.deviceID})
984 } //else: the state is just ignored (does not exist)
985 logger.Debugw(ctx, "Gem PortID list", log.Fields{"device-id": onuTP.deviceID, "gemportList": gemPortIds})
986 return gemPortIds
987}
988
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000989// GetAllBidirectionalGemPortIDsForOnu - TODO: add comment
990func (onuTP *OnuUniTechProf) GetAllBidirectionalGemPortIDsForOnu() []uint16 {
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800991 var gemPortInstIDs []uint16
992 onuTP.mutexTPState.RLock()
993 defer onuTP.mutexTPState.RUnlock()
994 for _, tcontGemList := range onuTP.mapPonAniConfig {
995 for gemPortID, gemPortData := range tcontGemList.mapGemPortParams {
996 if gemPortData != nil && !gemPortData.isMulticast { // only if not multicast gem port
997 gemPortInstIDs = append(gemPortInstIDs, gemPortID)
998 }
999 }
1000 }
1001 return gemPortInstIDs
1002}
mpagenko73143992021-04-09 15:17:10 +00001003
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +00001004// GetNumberOfConfiguredUsGemPorts - provides the number of Gem ports for each UNI/TP combination
1005func (onuTP *OnuUniTechProf) GetNumberOfConfiguredUsGemPorts(ctx context.Context) int {
1006 onuTP.mutexTPState.RLock()
1007 defer onuTP.mutexTPState.RUnlock()
1008 usGemPorts := make([]uint16, 0)
1009 for _, tcontGemList := range onuTP.mapPonAniConfig {
1010 for gemPortID, gemPortParams := range tcontGemList.mapGemPortParams {
1011 if gemPortParams.direction == cGemDirBiDirect || gemPortParams.direction == cGemDirUniToAni {
1012 alreadyConfigured := false
1013 for _, foundUsGemPortID := range usGemPorts {
1014 if foundUsGemPortID == gemPortID {
1015 alreadyConfigured = true
1016 break
1017 }
1018 }
1019 if !alreadyConfigured {
1020 usGemPorts = append(usGemPorts, gemPortID)
1021 }
1022 }
1023 }
1024 }
1025 return len(usGemPorts)
1026}
1027
mpagenko73143992021-04-09 15:17:10 +00001028// setProfileResetting sets/resets the indication, that a reset of the TechProfileConfig/Removal is ongoing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001029func (onuTP *OnuUniTechProf) setProfileResetting(ctx context.Context, aUniID uint8, aTpID uint8, aState bool) {
mpagenko73143992021-04-09 15:17:10 +00001030 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
1031 onuTP.mutexTPState.Lock()
1032 defer onuTP.mutexTPState.Unlock()
1033 onuTP.tpProfileResetting[uniTpKey] = aState
1034}
1035
1036// getProfileResetting returns true, if the the according indication for started reset procedure is set
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001037func (onuTP *OnuUniTechProf) getProfileResetting(aUniTpKey uniTP) bool {
mpagenko73143992021-04-09 15:17:10 +00001038 onuTP.mutexTPState.RLock()
1039 defer onuTP.mutexTPState.RUnlock()
1040 if isResetting, exist := onuTP.tpProfileResetting[aUniTpKey]; exist {
1041 return isResetting
1042 }
1043 return false
1044}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001045
1046// PrepareForGarbageCollection - remove references to prepare for garbage collection
1047func (onuTP *OnuUniTechProf) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
1048 logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
1049 onuTP.baseDeviceHandler = nil
1050 onuTP.onuDevice = nil
1051 for k, v := range onuTP.PAniConfigFsm {
1052 v.PrepareForGarbageCollection(ctx, aDeviceID)
1053 delete(onuTP.PAniConfigFsm, k)
1054 }
1055}