blob: ac59445b27f75f8ef0d6690a51d6e044905ccb58 [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
mpagenko7d6bb022021-03-11 15:07:55 +0000555 bDeviceProcStatusUpdate := true
mpagenko8b07c1b2020-11-26 10:36:31 +0000556 if cResourceGemPort == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000557 logger.Debugw(ctx, "remove GemPort from the list of existing ones of the TP", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000558 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID})
559
560 // check if the requested GemPort exists in the DB, indicate it to the FSM
561 // store locally to remove it from DB later on success
562 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
563 if pLocAniConfigOnUni == nil {
564 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000565 logger.Debugw(ctx, "AniConfig or GemEntry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000566 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
567 return
568 }
Himani Chawla1c136902020-12-10 16:30:59 +0530569 for gemPortID, gemEntry := range pLocAniConfigOnUni.mapGemPortParams {
570 if gemPortID == uint16(aEntryID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000571 //GemEntry to be deleted found
Himani Chawla1c136902020-12-10 16:30:59 +0530572 gemEntry.removeGemID = gemPortID //store the index for later removal
573 onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemPortID]
dbainbri4d3a0dc2020-12-02 00:33:42 +0000574 logger.Debugw(ctx, "Remove-GemEntry stored", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530575 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000576 break //abort loop, always only one GemPort to remove
577 }
578 }
579 if onuTP.mapRemoveGemEntry[uniTPKey] == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000580 logger.Errorw(ctx, "GemPort removal aborted - GemPort not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000581 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
582 /* Do not set some error indication to the outside system interface on delete
583 assume there is nothing to be deleted internally and hope a new config request will recover the situation
584 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s",
585 aEntryID, aUniID, onuTP.deviceID)
586 */
587 return
588 }
589 if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig {
590 // check that the TpConfigRequest was done before
591 // -> that is implicitly done using the AniConfigFsm,
592 // which must be in the according state to remove something
593 // initiate OMCI GemPort related removal
594 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
595 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
596 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000597 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000598 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
599 /* Do not set some error indication to the outside system interface on delete (see above)
600 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s",
601 aUniID, onuTP.deviceID)
602 */
603 //if the FSM is not valid, also TP related remove data should not be valid:
604 // remove GemPort from config DB
Himani Chawla1c136902020-12-10 16:30:59 +0530605 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000606 // remove the removeEntry
607 delete(onuTP.mapRemoveGemEntry, uniTPKey)
608 return
609 }
610 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000611 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000612 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
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 for tpid",
615 aUniID, onuTP.deviceID, aTpID)
616 */
617 //if the FSM is not valid, also TP related remove data should not be valid:
618 // remove GemPort from config DB
Himani Chawla1c136902020-12-10 16:30:59 +0530619 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000620 // remove the removeEntry
621 delete(onuTP.mapRemoveGemEntry, uniTPKey)
622 return
623 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000624 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemGemiw, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000625 //even if the FSM invocation did not work we don't indicate a problem within procResult
626 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
627 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
628 return
629 }
630 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
631 //timeout or error detected
dbainbri4d3a0dc2020-12-02 00:33:42 +0000632 logger.Errorw(ctx, "GemPort removal aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000633 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
634 //even if the FSM delete execution did not work we don't indicate a problem within procResult
635 //we should never respond to delete with error ...
636 //this issue here means that the AniConfigFsm has not finished successfully
637 //which requires to reset it to allow for new usage, e.g. also on a different UNI
638 //(without that it would be reset on device down indication latest)
639 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
640 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
641 return
642 }
643 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000644 //if we can't do the OMCI processing we also suppress the ProcStatusUpdate
645 //this is needed as in the device-down case where all FSM's are getting reset and internal data gets cleared
646 //as a consequence a possible remove-flow does not see any dependency on the TechProfile anymore and is executed (pro forma) directly
647 //a later TechProfile removal would cause the device-reason to be updated to 'techProfile-delete-success' which is not the expected state
648 // and anyway is no real useful information at that stage
649 bDeviceProcStatusUpdate = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000650 logger.Debugw(ctx, "uniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000651 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000652 }
653 // remove GemPort from config DB
Himani Chawla1c136902020-12-10 16:30:59 +0530654 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000655 // remove the removeEntry
656 delete(onuTP.mapRemoveGemEntry, uniTPKey)
657 // deviceHandler StatusEvent (reason update) (see end of function) is only generated in case some element really was removed
658 } else { //if cResourceTcont == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000659 logger.Debugw(ctx, "reset TCont with AllocId", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000660 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID})
661
662 // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM
663 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
664 if pLocAniConfigOnUni == nil {
665 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000666 logger.Debugw(ctx, "AniConfig or TCont entry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000667 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
668 return
669 }
670 if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000671 logger.Errorw(ctx, "TCont removal aborted - indicated AllocId not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000672 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID})
673 /* Do not set some error indication to the outside system interface on delete
674 assume there is nothing to be deleted internally and hope a new config request will recover the situation
675 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s",
676 aEntryID, aUniID, onuTP.deviceID)
677 */
678 return
679 }
680 //T-Cont to be reset found
dbainbri4d3a0dc2020-12-02 00:33:42 +0000681 logger.Debugw(ctx, "Reset-T-Cont AllocId found - valid", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000682 "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID})
683 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000684 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000685 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
686 /* Do not set some error indication to the outside system interface on delete (see above)
687 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s",
688 aUniID, onuTP.deviceID)
689 */
690 //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 +0000691 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000692 return
693 }
694 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000695 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000696 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
697 //even if the FSM invocation did not work we don't indicate a problem within procResult
698 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
699 //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 +0000700 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000701 return
702 }
703 if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig {
704 // check that the TpConfigRequest was done before
705 // -> that is implicitly done using the AniConfigFsm,
706 // which must be in the according state to remove something
707 // initiate OMCI TCont related cleanup
708 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
709 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000710 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemTcontPath, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000711 //even if the FSM invocation did not work we don't indicate a problem within procResult
712 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
713 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
714 return
715 }
716 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
717 //timeout or error detected
dbainbri4d3a0dc2020-12-02 00:33:42 +0000718 logger.Errorw(ctx, "TCont cleanup aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000719 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
720 //even if the FSM delete execution did not work we don't indicate a problem within procResult
721 //we should never respond to delete with error ...
722 //this issue here means that the AniConfigFsm has not finished successfully
723 //which requires to reset it to allow for new usage, e.g. also on a different UNI
724 //(without that it would be reset on device down indication latest)
725 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
726 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
727 return
728 }
729 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000730 //see gemPort comments
731 bDeviceProcStatusUpdate = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000732 logger.Debugw(ctx, "uniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000733 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000734 }
735 //clear the internal store profile data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000736 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000737 // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created
738 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
739 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
740 }
mpagenko7d6bb022021-03-11 15:07:55 +0000741 if bDeviceProcStatusUpdate {
742 // generate deviceHandler StatusEvent in case the FSM was not invoked and OMCI processing not locked due to device state
743 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(ctx, OmciAniResourceRemoved)
744 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000745}
746
Himani Chawla6d2ae152020-09-02 13:11:20 +0530747func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000748 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000749 select {
750 case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000751 logger.Warnw(ctx, "processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000752 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000753 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000754 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000755 if rxStep == aProcessingStep {
756 return true
757 }
758 //all other values are not accepted - including 0 for error indication
dbainbri4d3a0dc2020-12-02 00:33:42 +0000759 logger.Warnw(ctx, "Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000760 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000761 "wantedStep": aProcessingStep, "haveStep": rxStep})
762 return false
763 }
764}
765
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000766// createAniConfigFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000767func (onuTP *onuUniTechProf) createAniConfigFsm(ctx context.Context, aUniID uint8, aTpID uint8,
mpagenko8b07c1b2020-11-26 10:36:31 +0000768 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000769 logger.Debugw(ctx, "createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000770 chAniConfigFsm := make(chan Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800771 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000772 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(ctx, true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000773 if pDevEntry == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000774 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000775 return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000776 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000777 pAniCfgFsm := newUniPonAniConfigFsm(ctx, pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800778 pDevEntry.pOnuDB, aTpID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000779 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko8b07c1b2020-11-26 10:36:31 +0000780 if pAniCfgFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000781 logger.Errorw(ctx, "AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000782 return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000783 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000784 if onuTP.pAniConfigFsm == nil {
785 onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800786 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000787 onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm
dbainbri4d3a0dc2020-12-02 00:33:42 +0000788 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000789}
790
mpagenko3dbcdd22020-07-22 07:38:45 +0000791// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000792func (onuTP *onuUniTechProf) runAniConfigFsm(ctx context.Context, aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000793 /* Uni related ANI config procedure -
794 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
795 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800796 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
797
798 pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000799 if pACStatemachine != nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000800 if aEvent == aniEvStart {
801 if !pACStatemachine.Is(aniStDisabled) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000802 logger.Errorw(ctx, "wrong state of AniConfigFSM to start - want: Disabled", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000803 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000804 // maybe try a FSM reset and then again ... - TODO!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000805 return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000806 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000807 } else if !pACStatemachine.Is(aniStConfigDone) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000808 logger.Errorw(ctx, "wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000809 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000810 return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000811 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000812 //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config)
813 onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
814 if err := pACStatemachine.Event(aEvent); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000815 logger.Errorw(ctx, "AniConfigFSM: can't trigger event", log.Fields{"err": err})
mpagenko8b07c1b2020-11-26 10:36:31 +0000816 return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID)
817 }
818 /***** AniConfigFSM event notified */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000819 logger.Debugw(ctx, "AniConfigFSM event notified", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000820 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent})
821 return nil
mpagenko3dbcdd22020-07-22 07:38:45 +0000822 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000823 logger.Errorw(ctx, "AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000824 // maybe try a FSM reset and then again ... - TODO!!!
825 return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID)
mpagenkoaf801632020-07-03 10:00:42 +0000826}
mpagenkodff5dda2020-08-28 11:52:01 +0000827
Girish Gowdra041dcb32020-11-16 16:54:30 -0800828// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000829func (onuTP *onuUniTechProf) clearAniSideConfig(ctx context.Context, aUniID uint8, aTpID uint8) {
830 logger.Debugw(ctx, "removing TpIndication and PonAniConfig data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000831 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800832 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
833
834 onuTP.mutexTPState.Lock()
835 defer onuTP.mutexTPState.Unlock()
836 delete(onuTP.mapUniTpIndication, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000837 //delete on the PonAniConfig map of this UNI should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800838 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000839}
840
mpagenkodff5dda2020-08-28 11:52:01 +0000841// setConfigDone sets the requested techProfile config state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800842func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
843 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
844 onuTP.mutexTPState.Lock()
845 defer onuTP.mutexTPState.Unlock()
846 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
847 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000848 } //else: the state is just ignored (does not exist)
849}
850
851// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
dbainbri4d3a0dc2020-12-02 00:33:42 +0000852func (onuTP *onuUniTechProf) getTechProfileDone(ctx context.Context, aUniID uint8, aTpID uint8) bool {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800853 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
854 onuTP.mutexTPState.Lock()
855 defer onuTP.mutexTPState.Unlock()
856 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
857 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
858 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000859 logger.Debugw(ctx, "TechProfile not relevant for requested flow config - waiting on delete",
mpagenko2418ab02020-11-12 12:58:06 +0000860 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
861 return false //still waiting for removal of this techProfile first
862 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800863 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000864 }
865 }
866 //for all other constellations indicate false = Config not done
867 return false
868}
mpagenko2418ab02020-11-12 12:58:06 +0000869
870// setProfileToDelete sets the requested techProfile toDelete state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800871func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
872 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
873 onuTP.mutexTPState.Lock()
874 defer onuTP.mutexTPState.Unlock()
875 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
876 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000877 } //else: the state is just ignored (does not exist)
878}
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300879
880// setProfileToDelete sets the requested techProfile toDelete state (if possible)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000881func (onuTP *onuUniTechProf) getMulticastGemPorts(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300882 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
883 onuTP.mutexTPState.Lock()
884 defer onuTP.mutexTPState.Unlock()
885 gemPortIds := make([]uint16, 0)
886 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
887 for _, gemPortParam := range techProfile.mapGemPortParams {
888 if gemPortParam.isMulticast {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000889 logger.Debugw(ctx, "Detected multicast gemPort", log.Fields{"device-id": onuTP.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300890 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
891 "mcastGemId": gemPortParam.multicastGemPortID})
892 gemPortIds = append(gemPortIds, gemPortParam.multicastGemPortID)
893 }
894 }
895 } //else: the state is just ignored (does not exist)
896 return gemPortIds
897}
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800898
899func (onuTP *onuUniTechProf) GetAllBidirectionalGemPortIDsForOnu() []uint16 {
900 var gemPortInstIDs []uint16
901 onuTP.mutexTPState.RLock()
902 defer onuTP.mutexTPState.RUnlock()
903 for _, tcontGemList := range onuTP.mapPonAniConfig {
904 for gemPortID, gemPortData := range tcontGemList.mapGemPortParams {
905 if gemPortData != nil && !gemPortData.isMulticast { // only if not multicast gem port
906 gemPortInstIDs = append(gemPortInstIDs, gemPortID)
907 }
908 }
909 }
910 return gemPortInstIDs
911}