blob: 3fdbe19b1535ce7f6eee22de2eeb715e039c97f5 [file] [log] [blame]
mpagenkoaf801632020-07-03 10:00:42 +00001/*
2 * Copyright 2020-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
19
20import (
21 "context"
22 "encoding/json"
mpagenko1cc3cb42020-07-27 15:24:38 +000023 "errors"
Andrea Campanella6515c582020-10-05 11:25:00 +020024 "fmt"
ozgecanetsia4b232302020-11-11 10:58:10 +030025 "strconv"
mpagenko3dbcdd22020-07-22 07:38:45 +000026 "strings"
mpagenkoaf801632020-07-03 10:00:42 +000027 "sync"
28
dbainbri4d3a0dc2020-12-02 00:33:42 +000029 "github.com/opencord/voltha-lib-go/v4/pkg/db"
30 "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore"
31 "github.com/opencord/voltha-lib-go/v4/pkg/log"
32 tp "github.com/opencord/voltha-lib-go/v4/pkg/techprofile"
mpagenkoaf801632020-07-03 10:00:42 +000033)
34
Matteo Scandolof1f39a72020-11-24 12:08:11 -080035const cBasePathTechProfileKVStore = "%s/technology_profiles"
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000036
37//definitions for TechProfileProcessing - copied from OltAdapter:openolt_flowmgr.go
38// could perhaps be defined more globally
39const (
Himani Chawla6d2ae152020-09-02 13:11:20 +053040 // binaryStringPrefix is binary string prefix
41 binaryStringPrefix = "0b"
42 // binaryBit1 is binary bit 1 expressed as a character
43 //binaryBit1 = '1'
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000044)
mpagenkoaf801632020-07-03 10:00:42 +000045
46type resourceEntry int
47
48const (
49 cResourceGemPort resourceEntry = 1
50 cResourceTcont resourceEntry = 2
51)
52
mpagenko3dbcdd22020-07-22 07:38:45 +000053type tTechProfileIndication struct {
mpagenkodff5dda2020-08-28 11:52:01 +000054 techProfileType string
Girish Gowdra041dcb32020-11-16 16:54:30 -080055 techProfileID uint8
mpagenkodff5dda2020-08-28 11:52:01 +000056 techProfileConfigDone bool
mpagenko2418ab02020-11-12 12:58:06 +000057 techProfileToDelete bool
mpagenko3dbcdd22020-07-22 07:38:45 +000058}
59
60type tcontParamStruct struct {
61 allocID uint16
62 schedPolicy uint8
63}
64type gemPortParamStruct struct {
Himani Chawla4d908332020-08-31 12:30:20 +053065 //ponOmciCC bool
mpagenko3dbcdd22020-07-22 07:38:45 +000066 gemPortID uint16
67 direction uint8
68 gemPortEncState uint8
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000069 prioQueueIndex uint8
70 pbitString string
mpagenko3dbcdd22020-07-22 07:38:45 +000071 discardPolicy string
Himani Chawla4d908332020-08-31 12:30:20 +053072 //could also be a queue specific parameter, not used that way here
73 //maxQueueSize uint16
mpagenko3dbcdd22020-07-22 07:38:45 +000074 queueSchedPolicy string
75 queueWeight uint8
Himani Chawla1c136902020-12-10 16:30:59 +053076 removeGemID uint16
ozgecanetsia4b232302020-11-11 10:58:10 +030077 isMulticast bool
78 //TODO check if this has any value/difference from gemPortId
79 multicastGemPortID uint16
80 staticACL string
81 dynamicACL string
mpagenko3dbcdd22020-07-22 07:38:45 +000082}
83
84//refers to one tcont and its properties and all assigned GemPorts and their properties
85type tcontGemList struct {
86 tcontParams tcontParamStruct
87 mapGemPortParams map[uint16]*gemPortParamStruct
88}
89
Girish Gowdra041dcb32020-11-16 16:54:30 -080090// refers a unique combination of uniID and tpID for a given ONU.
91type uniTP struct {
92 uniID uint8
93 tpID uint8
94}
mpagenko3dbcdd22020-07-22 07:38:45 +000095
Himani Chawla6d2ae152020-09-02 13:11:20 +053096//onuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU
97type onuUniTechProf struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053098 baseDeviceHandler *deviceHandler
mpagenko01e726e2020-10-23 09:45:29 +000099 deviceID string
mpagenkodff5dda2020-08-28 11:52:01 +0000100 tpProcMutex sync.RWMutex
mpagenkodff5dda2020-08-28 11:52:01 +0000101 techProfileKVStore *db.Backend
mpagenkodff5dda2020-08-28 11:52:01 +0000102 chTpConfigProcessingStep chan uint8
Girish Gowdra041dcb32020-11-16 16:54:30 -0800103 mapUniTpIndication map[uniTP]*tTechProfileIndication //use pointer values to ease assignments to the map
104 mapPonAniConfig map[uniTP]*tcontGemList //per UNI: use pointer values to ease assignments to the map
105 pAniConfigFsm map[uniTP]*uniPonAniConfigFsm
106 procResult map[uniTP]error //error indication of processing
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800107 mutexTPState sync.RWMutex
Girish Gowdra041dcb32020-11-16 16:54:30 -0800108 tpProfileExists map[uniTP]bool
mpagenko8b07c1b2020-11-26 10:36:31 +0000109 mapRemoveGemEntry map[uniTP]*gemPortParamStruct //per UNI: pointer to GemEntry to be removed
mpagenkoaf801632020-07-03 10:00:42 +0000110}
111
Himani Chawla6d2ae152020-09-02 13:11:20 +0530112//newOnuUniTechProf returns the instance of a OnuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000113//(one instance per ONU/deviceHandler for all possible UNI's)
mpagenko01e726e2020-10-23 09:45:29 +0000114func newOnuUniTechProf(ctx context.Context, aDeviceHandler *deviceHandler) *onuUniTechProf {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000115 logger.Debugw(ctx, "init-OnuUniTechProf", log.Fields{"device-id": aDeviceHandler.deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530116 var onuTP onuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000117 onuTP.baseDeviceHandler = aDeviceHandler
mpagenko01e726e2020-10-23 09:45:29 +0000118 onuTP.deviceID = aDeviceHandler.deviceID
mpagenkoaf801632020-07-03 10:00:42 +0000119 onuTP.tpProcMutex = sync.RWMutex{}
mpagenkodff5dda2020-08-28 11:52:01 +0000120 onuTP.chTpConfigProcessingStep = make(chan uint8)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800121 onuTP.mapUniTpIndication = make(map[uniTP]*tTechProfileIndication)
122 onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList)
123 onuTP.procResult = make(map[uniTP]error)
124 onuTP.tpProfileExists = make(map[uniTP]bool)
mpagenko8b07c1b2020-11-26 10:36:31 +0000125 onuTP.mapRemoveGemEntry = make(map[uniTP]*gemPortParamStruct)
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800126 baseKvStorePath := fmt.Sprintf(cBasePathTechProfileKVStore, aDeviceHandler.pOpenOnuAc.cm.Backend.PathPrefix)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000127 onuTP.techProfileKVStore = aDeviceHandler.setBackend(ctx, baseKvStorePath)
mpagenkoaf801632020-07-03 10:00:42 +0000128 if onuTP.techProfileKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000129 logger.Errorw(ctx, "Can't access techProfileKVStore - no backend connection to service",
Matteo Scandolof1f39a72020-11-24 12:08:11 -0800130 log.Fields{"device-id": aDeviceHandler.deviceID, "service": baseKvStorePath})
mpagenkoaf801632020-07-03 10:00:42 +0000131 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000132
mpagenkoaf801632020-07-03 10:00:42 +0000133 return &onuTP
134}
135
136// lockTpProcMutex locks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530137func (onuTP *onuUniTechProf) lockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000138 onuTP.tpProcMutex.Lock()
139}
140
141// unlockTpProcMutex unlocks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530142func (onuTP *onuUniTechProf) unlockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000143 onuTP.tpProcMutex.Unlock()
144}
145
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000146// resetTpProcessingErrorIndication resets the internal error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000147// need to be called before evaluation of any subsequent processing (given by waitForTpCompletion())
Girish Gowdra041dcb32020-11-16 16:54:30 -0800148func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) {
149 onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000150}
151
Girish Gowdra041dcb32020-11-16 16:54:30 -0800152func (onuTP *onuUniTechProf) getTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error {
153 return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}]
mpagenko3dbcdd22020-07-22 07:38:45 +0000154}
155
mpagenko8b07c1b2020-11-26 10:36:31 +0000156// configureUniTp checks existing tp resources to configure and starts the corresponding OMCI configuation of the UNI port
mpagenko3dbcdd22020-07-22 07:38:45 +0000157// all possibly blocking processing must be run in background to allow for deadline supervision!
158// but take care on sequential background processing when needed (logical dependencies)
Himani Chawla4d908332020-08-31 12:30:20 +0530159// use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization
Himani Chawla6d2ae152020-09-02 13:11:20 +0530160func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context,
mpagenkodff5dda2020-08-28 11:52:01 +0000161 aUniID uint8, aPathString string, wg *sync.WaitGroup) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000162 defer wg.Done() //always decrement the waitGroup on return
dbainbri4d3a0dc2020-12-02 00:33:42 +0000163 logger.Debugw(ctx, "configure the Uni according to TpPath", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000164 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800165 tpID, err := GetTpIDFromTpPath(aPathString)
166 uniTpKey := uniTP{uniID: aUniID, tpID: tpID}
167 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000168 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 -0800169 return
170 }
mpagenkoaf801632020-07-03 10:00:42 +0000171 if onuTP.techProfileKVStore == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000172 logger.Errorw(ctx, "techProfileKVStore not set - abort",
mpagenko8b07c1b2020-11-26 10:36:31 +0000173 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800174 onuTP.procResult[uniTpKey] = errors.New("techProfile config aborted: techProfileKVStore not set")
mpagenkoaf801632020-07-03 10:00:42 +0000175 return
176 }
177
mpagenko3dbcdd22020-07-22 07:38:45 +0000178 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530179 var pCurrentUniPort *onuUniPort
mpagenko3dbcdd22020-07-22 07:38:45 +0000180 for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap {
181 // only if this port is validated for operState transfer
Girish Gowdra041dcb32020-11-16 16:54:30 -0800182 if uniPort.uniID == aUniID {
mpagenko3dbcdd22020-07-22 07:38:45 +0000183 pCurrentUniPort = uniPort
184 break //found - end search loop
185 }
186 }
187 if pCurrentUniPort == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000188 logger.Errorw(ctx, "TechProfile configuration aborted: requested uniID not found in PortDB",
mpagenko01e726e2020-10-23 09:45:29 +0000189 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800190 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200191 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000192 return
193 }
mpagenkoaf801632020-07-03 10:00:42 +0000194
mpagenkodff5dda2020-08-28 11:52:01 +0000195 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
mpagenkoaf801632020-07-03 10:00:42 +0000196
mpagenko3dbcdd22020-07-22 07:38:45 +0000197 //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called
198 // in case the KVPath has changed for the given UNI,
199 // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
200 // (ANI) configuration of this port has to be removed first
201 // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
202 // existence of configuration can be detected based on tp stored TCONT's
Andrea Campanella6515c582020-10-05 11:25:00 +0200203 //TODO:
mpagenko3dbcdd22020-07-22 07:38:45 +0000204 /* if tcontMap not empty {
205 go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000206 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000207 //timeout or error detected
208 return
209 }
210 clear tcontMap
211 }
212
213 processingStep++
214 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800215 go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000216 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000217 //timeout or error detected
Girish Gowdra041dcb32020-11-16 16:54:30 -0800218 if onuTP.tpProfileExists[uniTpKey] {
mpagenko01e726e2020-10-23 09:45:29 +0000219 //ignore the internal error in case the new profile is already configured
220 // and abort the processing here
221 return
222 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000223 logger.Errorw(ctx, "tech-profile related configuration aborted on read",
mpagenko01e726e2020-10-23 09:45:29 +0000224 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800225 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200226 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000227 return
228 }
229
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000230 if onuTP.baseDeviceHandler.isSkipOnuConfigReconciling() {
231 logger.Debugw(ctx, "reconciling - skip omci-config of ANI side ", log.Fields{"uni-id": aUniID, "device-id": onuTP.deviceID})
232 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
233 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = true
234 }
235 return
236 }
237
mpagenko3dbcdd22020-07-22 07:38:45 +0000238 processingStep++
Girish Gowdra041dcb32020-11-16 16:54:30 -0800239
240 valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey]
241
242 if existPA {
243 if valuePA != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000244 //Config data for this uni and and at least TCont Index 0 exist
mpagenko8b07c1b2020-11-26 10:36:31 +0000245 if err := onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000246 logger.Errorw(ctx, "tech-profile related FSM could not be started",
mpagenko8b07c1b2020-11-26 10:36:31 +0000247 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
248 onuTP.procResult[uniTpKey] = err
249 return
250 }
mpagenkodff5dda2020-08-28 11:52:01 +0000251 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000252 //timeout or error detected
dbainbri4d3a0dc2020-12-02 00:33:42 +0000253 logger.Errorw(ctx, "tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000254 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800255
256 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200257 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530258 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000259 //which requires to reset it to allow for new usage, e.g. also on a different UNI
260 //(without that it would be reset on device down indication latest)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800261 _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +0000262 return
mpagenkoaf801632020-07-03 10:00:42 +0000263 }
264 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000265 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000266 logger.Errorw(ctx, "no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000267 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800268
269 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 +0200270 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000271 return
mpagenkoaf801632020-07-03 10:00:42 +0000272 }
273 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000274 logger.Errorw(ctx, "no PonAni data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000275 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800276
277 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 +0200278 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000279 return
mpagenkoaf801632020-07-03 10:00:42 +0000280 }
281}
282
mpagenko3dbcdd22020-07-22 07:38:45 +0000283/* internal methods *********************/
ozgecanetsia4b232302020-11-11 10:58:10 +0300284// nolint: gocyclo
Himani Chawla6d2ae152020-09-02 13:11:20 +0530285func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile(
Girish Gowdra041dcb32020-11-16 16:54:30 -0800286 ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000287 var tpInst tp.TechProfile
288
Girish Gowdra041dcb32020-11-16 16:54:30 -0800289 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
290
291 onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false
292
mpagenko3dbcdd22020-07-22 07:38:45 +0000293 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
294 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
295 subStringSlice := strings.Split(aPathString, "/")
296 if len(subStringSlice) <= 2 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000297 logger.Errorw(ctx, "invalid path name format",
mpagenko3dbcdd22020-07-22 07:38:45 +0000298 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000299 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000300 return
301 }
302
mpagenko3dbcdd22020-07-22 07:38:45 +0000303 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000304 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
305 // then we throw a warning, set an internal error and abort with error,
306 // which is later re-defined to success response to OLT adapter
307 // if TPId has changed, current data is removed (note that the ONU config state may be
308 // ambivalent in such a case)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800309 if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000310 logger.Warnw(ctx, "Some active profile entry at reading new TechProfile",
mpagenko3dbcdd22020-07-22 07:38:45 +0000311 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800312 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
313 if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID {
mpagenko01e726e2020-10-23 09:45:29 +0000314 // ProfId not changed - assume profile to be still the same
315 // anyway this should not appear after full support of profile (Gem/TCont) removal
dbainbri4d3a0dc2020-12-02 00:33:42 +0000316 logger.Warnw(ctx, "New TechProfile already exists - aborting configuration",
mpagenko01e726e2020-10-23 09:45:29 +0000317 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800318 onuTP.tpProfileExists[uniTPKey] = true
mpagenko01e726e2020-10-23 09:45:29 +0000319 onuTP.chTpConfigProcessingStep <- 0 //error indication
320 return
321 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000322 //delete on the mapUniTpIndication map not needed, just overwritten later
323 //delete on the PonAniConfig map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800324 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenko3dbcdd22020-07-22 07:38:45 +0000325 } else {
326 // this is normal processing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800327 onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
mpagenko3dbcdd22020-07-22 07:38:45 +0000328 }
329
Girish Gowdra041dcb32020-11-16 16:54:30 -0800330 onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000331 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
Girish Gowdra041dcb32020-11-16 16:54:30 -0800332 onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID
333 onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false
334 onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000335 logger.Debugw(ctx, "tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000336 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800337 "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType,
338 "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000339
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000340 Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString)
mpagenko3dbcdd22020-07-22 07:38:45 +0000341 if err == nil {
342 if Value != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000343 logger.Debugw(ctx, "tech-profile read",
mpagenko3dbcdd22020-07-22 07:38:45 +0000344 log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID})
345 tpTmpBytes, _ := kvstore.ToByte(Value.Value)
346
347 if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000348 logger.Errorw(ctx, "TechProf - Failed to unmarshal tech-profile into tpInst",
mpagenko3dbcdd22020-07-22 07:38:45 +0000349 log.Fields{"error": err, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000350 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000351 return
352 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000353 logger.Debugw(ctx, "TechProf - tpInst", log.Fields{"tpInst": tpInst})
mpagenko3dbcdd22020-07-22 07:38:45 +0000354 // access examples
dbainbri4d3a0dc2020-12-02 00:33:42 +0000355 logger.Debugw(ctx, "TechProf content", log.Fields{"Name": tpInst.Name,
mpagenko3dbcdd22020-07-22 07:38:45 +0000356 "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize,
357 "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
358 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000359 logger.Errorw(ctx, "No tech-profile found",
mpagenko3dbcdd22020-07-22 07:38:45 +0000360 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000361 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000362 return
363 }
364 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000365 logger.Errorw(ctx, "kvstore-get failed for path",
mpagenko3dbcdd22020-07-22 07:38:45 +0000366 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000367 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000368 return
369 }
370
mpagenko01e726e2020-10-23 09:45:29 +0000371 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000372 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800373 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000374
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000375 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000376 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra041dcb32020-11-16 16:54:30 -0800377 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID)
Himani Chawla4d908332020-08-31 12:30:20 +0530378 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000379 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
380 if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800381 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000382 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000383 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800384 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000385 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000386 loNumGemPorts := tpInst.NumGemPorts
387 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000388 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000389 if uint32(pos) == loNumGemPorts {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000390 logger.Debugw(ctx, "PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
mpagenko1cc3cb42020-07-27 15:24:38 +0000391 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000392 break
393 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000394 if pos == 0 {
395 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
396 loGemPortRead = true
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000397 }
Himani Chawla1c136902020-12-10 16:30:59 +0530398 //for all GemPorts we need to extend the mapGemPortParams
399 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)] = &gemPortParamStruct{}
400
401 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortID =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000402 uint16(content.GemportID)
403 //direction can be correlated later with Downstream list,
404 // for now just assume bidirectional (upstream never exists alone)
Himani Chawla1c136902020-12-10 16:30:59 +0530405 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000406 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
ozgecanetsia4b232302020-11-11 10:58:10 +0300407 if content.PriorityQueue > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000408 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000409 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue})
410 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800411 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000412 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000413 return
414 }
Himani Chawla1c136902020-12-10 16:30:59 +0530415 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].prioQueueIndex =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000416 uint8(content.PriorityQueue)
Himani Chawla1c136902020-12-10 16:30:59 +0530417 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530418 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000419 if content.AesEncryption == "True" {
Himani Chawla1c136902020-12-10 16:30:59 +0530420 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000421 } else {
Himani Chawla1c136902020-12-10 16:30:59 +0530422 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000423 }
Himani Chawla1c136902020-12-10 16:30:59 +0530424 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].discardPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000425 content.DiscardPolicy
Himani Chawla1c136902020-12-10 16:30:59 +0530426 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].queueSchedPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000427 content.SchedulingPolicy
mpagenko3dbcdd22020-07-22 07:38:45 +0000428 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Himani Chawla1c136902020-12-10 16:30:59 +0530429 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000430 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000431 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300432
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300433 for _, downstreamContent := range tpInst.DownstreamGemPortAttributeList {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000434 logger.Debugw(ctx, "Operating on Downstream Gem Port", log.Fields{"downstream-gem": downstreamContent})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300435 //Commenting this out due to faliure, needs investigation
436 //if uint32(pos) == loNumGemPorts {
437 // logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
438 // log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
439 // break
440 //}
441 isMulticast := false
ozgecanetsia4b232302020-11-11 10:58:10 +0300442 //Flag is defined as string in the TP in voltha-lib-go, parsing it from string
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300443 if downstreamContent.IsMulticast != "" {
444 isMulticast, err = strconv.ParseBool(downstreamContent.IsMulticast)
445 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000446 logger.Errorw(ctx, "multicast-error-config-unknown-flag-in-technology-profile",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300447 log.Fields{"UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "error": err})
448 continue
449 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300450 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000451 logger.Infow(ctx, "Gem Port is multicast", log.Fields{"isMulticast": isMulticast})
ozgecanetsia4b232302020-11-11 10:58:10 +0300452 if isMulticast {
453 mcastGemID := uint16(downstreamContent.McastGemID)
454 _, existing := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID]
455 if existing {
456 //GEM port was previously configured, avoid setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000457 logger.Errorw(ctx, "multicast-error-config-existing-gem-port-config", log.Fields{"UniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300458 "downstream-gem": downstreamContent, "key": mcastGemID})
459 continue
460 } else {
461 //GEM port is not configured, setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000462 logger.Infow(ctx, "creating-multicast-gem-port", log.Fields{"uniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300463 "gemPortId": mcastGemID, "key": mcastGemID})
464
465 //for all further GemPorts we need to extend the mapGemPortParams
466 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID] = &gemPortParamStruct{}
467
468 //Separate McastGemId is derived from OMCI-lib-go, if not needed first needs to be removed there.
469 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortID = mcastGemID
470 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].direction = 2 // for ANI to UNI as defined in G.988
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300471
472 if downstreamContent.AesEncryption == "True" {
473 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 1
474 } else {
475 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 0
476 }
477
478 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
ozgecanetsia4b232302020-11-11 10:58:10 +0300479 if downstreamContent.PriorityQueue > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000480 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300481 log.Fields{"device-id": onuTP.deviceID, "index": mcastGemID, "PrioQueue": downstreamContent.PriorityQueue})
482 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
483 delete(onuTP.mapPonAniConfig, uniTPKey)
484 onuTP.chTpConfigProcessingStep <- 0 //error indication
485 return
ozgecanetsia4b232302020-11-11 10:58:10 +0300486 }
487 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].prioQueueIndex =
488 uint8(downstreamContent.PriorityQueue)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300489 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].pbitString =
490 strings.TrimPrefix(downstreamContent.PbitMap, binaryStringPrefix)
491
492 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].discardPolicy =
493 downstreamContent.DiscardPolicy
494 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueSchedPolicy =
495 downstreamContent.SchedulingPolicy
496 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
497 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueWeight =
498 uint8(downstreamContent.Weight)
499
ozgecanetsia4b232302020-11-11 10:58:10 +0300500 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].isMulticast = isMulticast
501 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].multicastGemPortID =
502 uint16(downstreamContent.McastGemID)
503 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].staticACL = downstreamContent.SControlList
504 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].dynamicACL = downstreamContent.DControlList
505 }
506 }
507 }
508
Himani Chawla4d908332020-08-31 12:30:20 +0530509 if !loGemPortRead {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000510 logger.Errorw(ctx, "PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000511 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000512 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800513 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000514 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000515 return
516 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000517 //logger does not simply output the given structures, just give some example debug values
dbainbri4d3a0dc2020-12-02 00:33:42 +0000518 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000519 "device-id": onuTP.deviceID, "uni-id": aUniID,
520 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
Himani Chawla1c136902020-12-10 16:30:59 +0530521 for gemPortID, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000522 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530523 "GemPort": gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000524 "QueueScheduling": gemEntry.queueSchedPolicy})
525 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000526
mpagenkodff5dda2020-08-28 11:52:01 +0000527 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000528}
529
Himani Chawla6d2ae152020-09-02 13:11:20 +0530530func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
mpagenko8b07c1b2020-11-26 10:36:31 +0000531 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000532
533 //OMCI transfer of ANI data acc. to mapPonAniConfig
534 // also the FSM's are running in background,
mpagenko8b07c1b2020-11-26 10:36:31 +0000535 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800536 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko3dbcdd22020-07-22 07:38:45 +0000537 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000538 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800539 } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000540 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000541 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000542 //AniConfigFsm already init
dbainbri4d3a0dc2020-12-02 00:33:42 +0000543 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000544}
545
546// deleteTpResource removes Resources from the ONU's specified Uni
547func (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
559 // check if the requested GemPort exists in the DB, indicate it to the FSM
560 // store locally to remove it from DB later on success
561 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
562 if pLocAniConfigOnUni == nil {
563 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000564 logger.Debugw(ctx, "AniConfig or GemEntry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000565 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
566 return
567 }
Himani Chawla1c136902020-12-10 16:30:59 +0530568 for gemPortID, gemEntry := range pLocAniConfigOnUni.mapGemPortParams {
569 if gemPortID == uint16(aEntryID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000570 //GemEntry to be deleted found
Himani Chawla1c136902020-12-10 16:30:59 +0530571 gemEntry.removeGemID = gemPortID //store the index for later removal
572 onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemPortID]
dbainbri4d3a0dc2020-12-02 00:33:42 +0000573 logger.Debugw(ctx, "Remove-GemEntry stored", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530574 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000575 break //abort loop, always only one GemPort to remove
576 }
577 }
578 if onuTP.mapRemoveGemEntry[uniTPKey] == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000579 logger.Errorw(ctx, "GemPort removal aborted - GemPort not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000580 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
581 /* Do not set some error indication to the outside system interface on delete
582 assume there is nothing to be deleted internally and hope a new config request will recover the situation
583 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s",
584 aEntryID, aUniID, onuTP.deviceID)
585 */
586 return
587 }
588 if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig {
589 // check that the TpConfigRequest was done before
590 // -> that is implicitly done using the AniConfigFsm,
591 // which must be in the according state to remove something
592 // initiate OMCI GemPort related removal
593 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
594 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
595 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000596 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000597 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
598 /* Do not set some error indication to the outside system interface on delete (see above)
599 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s",
600 aUniID, onuTP.deviceID)
601 */
602 //if the FSM is not valid, also TP related remove data should not be valid:
603 // remove GemPort from config DB
Himani Chawla1c136902020-12-10 16:30:59 +0530604 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000605 // remove the removeEntry
606 delete(onuTP.mapRemoveGemEntry, uniTPKey)
607 return
608 }
609 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000610 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000611 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
612 /* Do not set some error indication to the outside system interface on delete (see above)
613 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid",
614 aUniID, onuTP.deviceID, aTpID)
615 */
616 //if the FSM is not valid, also TP related remove data should not be valid:
617 // remove GemPort from config DB
Himani Chawla1c136902020-12-10 16:30:59 +0530618 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000619 // remove the removeEntry
620 delete(onuTP.mapRemoveGemEntry, uniTPKey)
621 return
622 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000623 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemGemiw, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000624 //even if the FSM invocation did not work we don't indicate a problem within procResult
625 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
626 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
627 return
628 }
629 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
630 //timeout or error detected
dbainbri4d3a0dc2020-12-02 00:33:42 +0000631 logger.Errorw(ctx, "GemPort removal aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000632 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
633 //even if the FSM delete execution did not work we don't indicate a problem within procResult
634 //we should never respond to delete with error ...
635 //this issue here means that the AniConfigFsm has not finished successfully
636 //which requires to reset it to allow for new usage, e.g. also on a different UNI
637 //(without that it would be reset on device down indication latest)
638 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
639 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
640 return
641 }
642 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000643 logger.Debugw(ctx, "uniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000644 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000645 }
646 // remove GemPort from config DB
Himani Chawla1c136902020-12-10 16:30:59 +0530647 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000648 // remove the removeEntry
649 delete(onuTP.mapRemoveGemEntry, uniTPKey)
650 // deviceHandler StatusEvent (reason update) (see end of function) is only generated in case some element really was removed
651 } else { //if cResourceTcont == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000652 logger.Debugw(ctx, "reset TCont with AllocId", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000653 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID})
654
655 // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM
656 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
657 if pLocAniConfigOnUni == nil {
658 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000659 logger.Debugw(ctx, "AniConfig or TCont entry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000660 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
661 return
662 }
663 if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000664 logger.Errorw(ctx, "TCont removal aborted - indicated AllocId not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000665 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID})
666 /* Do not set some error indication to the outside system interface on delete
667 assume there is nothing to be deleted internally and hope a new config request will recover the situation
668 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s",
669 aEntryID, aUniID, onuTP.deviceID)
670 */
671 return
672 }
673 //T-Cont to be reset found
dbainbri4d3a0dc2020-12-02 00:33:42 +0000674 logger.Debugw(ctx, "Reset-T-Cont AllocId found - valid", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000675 "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID})
676 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000677 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000678 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
679 /* Do not set some error indication to the outside system interface on delete (see above)
680 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s",
681 aUniID, onuTP.deviceID)
682 */
683 //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000684 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000685 return
686 }
687 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000688 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000689 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
690 //even if the FSM invocation did not work we don't indicate a problem within procResult
691 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
692 //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000693 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000694 return
695 }
696 if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig {
697 // check that the TpConfigRequest was done before
698 // -> that is implicitly done using the AniConfigFsm,
699 // which must be in the according state to remove something
700 // initiate OMCI TCont related cleanup
701 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
702 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000703 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemTcontPath, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000704 //even if the FSM invocation did not work we don't indicate a problem within procResult
705 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
706 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
707 return
708 }
709 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
710 //timeout or error detected
dbainbri4d3a0dc2020-12-02 00:33:42 +0000711 logger.Errorw(ctx, "TCont cleanup aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000712 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
713 //even if the FSM delete execution did not work we don't indicate a problem within procResult
714 //we should never respond to delete with error ...
715 //this issue here means that the AniConfigFsm has not finished successfully
716 //which requires to reset it to allow for new usage, e.g. also on a different UNI
717 //(without that it would be reset on device down indication latest)
718 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
719 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
720 return
721 }
722 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000723 logger.Debugw(ctx, "uniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000724 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000725 }
726 //clear the internal store profile data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000727 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000728 // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created
729 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
730 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
731 }
732 // generate deviceHandler StatusEvent in case the FSM was not invoked
dbainbri4d3a0dc2020-12-02 00:33:42 +0000733 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(ctx, OmciAniResourceRemoved)
mpagenko3dbcdd22020-07-22 07:38:45 +0000734}
735
Himani Chawla6d2ae152020-09-02 13:11:20 +0530736func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000737 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000738 select {
739 case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000740 logger.Warnw(ctx, "processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000741 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000742 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000743 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000744 if rxStep == aProcessingStep {
745 return true
746 }
747 //all other values are not accepted - including 0 for error indication
dbainbri4d3a0dc2020-12-02 00:33:42 +0000748 logger.Warnw(ctx, "Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000749 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000750 "wantedStep": aProcessingStep, "haveStep": rxStep})
751 return false
752 }
753}
754
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000755// createAniConfigFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000756func (onuTP *onuUniTechProf) createAniConfigFsm(ctx context.Context, aUniID uint8, aTpID uint8,
mpagenko8b07c1b2020-11-26 10:36:31 +0000757 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000758 logger.Debugw(ctx, "createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000759 chAniConfigFsm := make(chan Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800760 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000761 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(ctx, true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000762 if pDevEntry == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000763 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000764 return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000765 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000766 pAniCfgFsm := newUniPonAniConfigFsm(ctx, pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800767 pDevEntry.pOnuDB, aTpID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000768 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko8b07c1b2020-11-26 10:36:31 +0000769 if pAniCfgFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000770 logger.Errorw(ctx, "AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000771 return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000772 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000773 if onuTP.pAniConfigFsm == nil {
774 onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800775 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000776 onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm
dbainbri4d3a0dc2020-12-02 00:33:42 +0000777 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000778}
779
mpagenko3dbcdd22020-07-22 07:38:45 +0000780// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000781func (onuTP *onuUniTechProf) runAniConfigFsm(ctx context.Context, aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000782 /* Uni related ANI config procedure -
783 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
784 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800785 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
786
787 pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000788 if pACStatemachine != nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000789 if aEvent == aniEvStart {
790 if !pACStatemachine.Is(aniStDisabled) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000791 logger.Errorw(ctx, "wrong state of AniConfigFSM to start - want: Disabled", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000792 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000793 // maybe try a FSM reset and then again ... - TODO!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000794 return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000795 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000796 } else if !pACStatemachine.Is(aniStConfigDone) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000797 logger.Errorw(ctx, "wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000798 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000799 return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000800 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000801 //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config)
802 onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
803 if err := pACStatemachine.Event(aEvent); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000804 logger.Errorw(ctx, "AniConfigFSM: can't trigger event", log.Fields{"err": err})
mpagenko8b07c1b2020-11-26 10:36:31 +0000805 return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID)
806 }
807 /***** AniConfigFSM event notified */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000808 logger.Debugw(ctx, "AniConfigFSM event notified", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000809 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent})
810 return nil
mpagenko3dbcdd22020-07-22 07:38:45 +0000811 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000812 logger.Errorw(ctx, "AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000813 // maybe try a FSM reset and then again ... - TODO!!!
814 return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID)
mpagenkoaf801632020-07-03 10:00:42 +0000815}
mpagenkodff5dda2020-08-28 11:52:01 +0000816
Girish Gowdra041dcb32020-11-16 16:54:30 -0800817// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000818func (onuTP *onuUniTechProf) clearAniSideConfig(ctx context.Context, aUniID uint8, aTpID uint8) {
819 logger.Debugw(ctx, "removing TpIndication and PonAniConfig data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000820 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800821 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
822
823 onuTP.mutexTPState.Lock()
824 defer onuTP.mutexTPState.Unlock()
825 delete(onuTP.mapUniTpIndication, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000826 //delete on the PonAniConfig map of this UNI should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800827 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000828}
829
mpagenkodff5dda2020-08-28 11:52:01 +0000830// setConfigDone sets the requested techProfile config state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800831func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
832 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
833 onuTP.mutexTPState.Lock()
834 defer onuTP.mutexTPState.Unlock()
835 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
836 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000837 } //else: the state is just ignored (does not exist)
838}
839
840// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
dbainbri4d3a0dc2020-12-02 00:33:42 +0000841func (onuTP *onuUniTechProf) getTechProfileDone(ctx context.Context, aUniID uint8, aTpID uint8) bool {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800842 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
843 onuTP.mutexTPState.Lock()
844 defer onuTP.mutexTPState.Unlock()
845 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
846 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
847 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000848 logger.Debugw(ctx, "TechProfile not relevant for requested flow config - waiting on delete",
mpagenko2418ab02020-11-12 12:58:06 +0000849 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
850 return false //still waiting for removal of this techProfile first
851 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800852 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000853 }
854 }
855 //for all other constellations indicate false = Config not done
856 return false
857}
mpagenko2418ab02020-11-12 12:58:06 +0000858
859// setProfileToDelete sets the requested techProfile toDelete state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800860func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
861 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
862 onuTP.mutexTPState.Lock()
863 defer onuTP.mutexTPState.Unlock()
864 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
865 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000866 } //else: the state is just ignored (does not exist)
867}
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300868
869// setProfileToDelete sets the requested techProfile toDelete state (if possible)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000870func (onuTP *onuUniTechProf) getMulticastGemPorts(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300871 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
872 onuTP.mutexTPState.Lock()
873 defer onuTP.mutexTPState.Unlock()
874 gemPortIds := make([]uint16, 0)
875 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
876 for _, gemPortParam := range techProfile.mapGemPortParams {
877 if gemPortParam.isMulticast {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000878 logger.Debugw(ctx, "Detected multicast gemPort", log.Fields{"device-id": onuTP.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300879 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
880 "mcastGemId": gemPortParam.multicastGemPortID})
881 gemPortIds = append(gemPortIds, gemPortParam.multicastGemPortID)
882 }
883 }
884 } //else: the state is just ignored (does not exist)
885 return gemPortIds
886}
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800887
888func (onuTP *onuUniTechProf) GetAllBidirectionalGemPortIDsForOnu() []uint16 {
889 var gemPortInstIDs []uint16
890 onuTP.mutexTPState.RLock()
891 defer onuTP.mutexTPState.RUnlock()
892 for _, tcontGemList := range onuTP.mapPonAniConfig {
893 for gemPortID, gemPortData := range tcontGemList.mapGemPortParams {
894 if gemPortData != nil && !gemPortData.isMulticast { // only if not multicast gem port
895 gemPortInstIDs = append(gemPortInstIDs, gemPortID)
896 }
897 }
898 }
899 return gemPortInstIDs
900}