blob: 0ab368e6ad2d88538b63bbf17fdcd7d91522063a [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
230 processingStep++
Girish Gowdra041dcb32020-11-16 16:54:30 -0800231
232 valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey]
233
234 if existPA {
235 if valuePA != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000236 //Config data for this uni and and at least TCont Index 0 exist
mpagenko8b07c1b2020-11-26 10:36:31 +0000237 if err := onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000238 logger.Errorw(ctx, "tech-profile related FSM could not be started",
mpagenko8b07c1b2020-11-26 10:36:31 +0000239 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
240 onuTP.procResult[uniTpKey] = err
241 return
242 }
mpagenkodff5dda2020-08-28 11:52:01 +0000243 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000244 //timeout or error detected
dbainbri4d3a0dc2020-12-02 00:33:42 +0000245 logger.Errorw(ctx, "tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000246 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800247
248 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200249 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530250 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000251 //which requires to reset it to allow for new usage, e.g. also on a different UNI
252 //(without that it would be reset on device down indication latest)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800253 _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +0000254 return
mpagenkoaf801632020-07-03 10:00:42 +0000255 }
256 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000257 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000258 logger.Errorw(ctx, "no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000259 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800260
261 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 +0200262 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000263 return
mpagenkoaf801632020-07-03 10:00:42 +0000264 }
265 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000266 logger.Errorw(ctx, "no PonAni 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 AniSide 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}
274
mpagenko3dbcdd22020-07-22 07:38:45 +0000275/* internal methods *********************/
ozgecanetsia4b232302020-11-11 10:58:10 +0300276// nolint: gocyclo
Himani Chawla6d2ae152020-09-02 13:11:20 +0530277func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile(
Girish Gowdra041dcb32020-11-16 16:54:30 -0800278 ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000279 var tpInst tp.TechProfile
280
Girish Gowdra041dcb32020-11-16 16:54:30 -0800281 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
282
283 onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false
284
mpagenko3dbcdd22020-07-22 07:38:45 +0000285 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
286 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
287 subStringSlice := strings.Split(aPathString, "/")
288 if len(subStringSlice) <= 2 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000289 logger.Errorw(ctx, "invalid path name format",
mpagenko3dbcdd22020-07-22 07:38:45 +0000290 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000291 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000292 return
293 }
294
mpagenko3dbcdd22020-07-22 07:38:45 +0000295 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000296 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
297 // then we throw a warning, set an internal error and abort with error,
298 // which is later re-defined to success response to OLT adapter
299 // if TPId has changed, current data is removed (note that the ONU config state may be
300 // ambivalent in such a case)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800301 if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000302 logger.Warnw(ctx, "Some active profile entry at reading new TechProfile",
mpagenko3dbcdd22020-07-22 07:38:45 +0000303 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800304 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
305 if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID {
mpagenko01e726e2020-10-23 09:45:29 +0000306 // ProfId not changed - assume profile to be still the same
307 // anyway this should not appear after full support of profile (Gem/TCont) removal
dbainbri4d3a0dc2020-12-02 00:33:42 +0000308 logger.Warnw(ctx, "New TechProfile already exists - aborting configuration",
mpagenko01e726e2020-10-23 09:45:29 +0000309 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800310 onuTP.tpProfileExists[uniTPKey] = true
mpagenko01e726e2020-10-23 09:45:29 +0000311 onuTP.chTpConfigProcessingStep <- 0 //error indication
312 return
313 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000314 //delete on the mapUniTpIndication map not needed, just overwritten later
315 //delete on the PonAniConfig map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800316 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenko3dbcdd22020-07-22 07:38:45 +0000317 } else {
318 // this is normal processing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800319 onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
mpagenko3dbcdd22020-07-22 07:38:45 +0000320 }
321
Girish Gowdra041dcb32020-11-16 16:54:30 -0800322 onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000323 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
Girish Gowdra041dcb32020-11-16 16:54:30 -0800324 onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID
325 onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false
326 onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000327 logger.Debugw(ctx, "tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000328 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800329 "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType,
330 "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000331
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000332 Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString)
mpagenko3dbcdd22020-07-22 07:38:45 +0000333 if err == nil {
334 if Value != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000335 logger.Debugw(ctx, "tech-profile read",
mpagenko3dbcdd22020-07-22 07:38:45 +0000336 log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID})
337 tpTmpBytes, _ := kvstore.ToByte(Value.Value)
338
339 if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000340 logger.Errorw(ctx, "TechProf - Failed to unmarshal tech-profile into tpInst",
mpagenko3dbcdd22020-07-22 07:38:45 +0000341 log.Fields{"error": err, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000342 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000343 return
344 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000345 logger.Debugw(ctx, "TechProf - tpInst", log.Fields{"tpInst": tpInst})
mpagenko3dbcdd22020-07-22 07:38:45 +0000346 // access examples
dbainbri4d3a0dc2020-12-02 00:33:42 +0000347 logger.Debugw(ctx, "TechProf content", log.Fields{"Name": tpInst.Name,
mpagenko3dbcdd22020-07-22 07:38:45 +0000348 "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize,
349 "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
350 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000351 logger.Errorw(ctx, "No tech-profile found",
mpagenko3dbcdd22020-07-22 07:38:45 +0000352 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000353 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000354 return
355 }
356 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000357 logger.Errorw(ctx, "kvstore-get failed for path",
mpagenko3dbcdd22020-07-22 07:38:45 +0000358 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000359 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000360 return
361 }
362
mpagenko01e726e2020-10-23 09:45:29 +0000363 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000364 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800365 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000366
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000367 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000368 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra041dcb32020-11-16 16:54:30 -0800369 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID)
Himani Chawla4d908332020-08-31 12:30:20 +0530370 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000371 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
372 if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800373 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000374 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000375 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800376 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000377 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000378 loNumGemPorts := tpInst.NumGemPorts
379 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000380 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000381 if uint32(pos) == loNumGemPorts {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000382 logger.Debugw(ctx, "PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
mpagenko1cc3cb42020-07-27 15:24:38 +0000383 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000384 break
385 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000386 if pos == 0 {
387 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
388 loGemPortRead = true
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000389 }
Himani Chawla1c136902020-12-10 16:30:59 +0530390 //for all GemPorts we need to extend the mapGemPortParams
391 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)] = &gemPortParamStruct{}
392
393 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortID =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000394 uint16(content.GemportID)
395 //direction can be correlated later with Downstream list,
396 // for now just assume bidirectional (upstream never exists alone)
Himani Chawla1c136902020-12-10 16:30:59 +0530397 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000398 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
ozgecanetsia4b232302020-11-11 10:58:10 +0300399 if content.PriorityQueue > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000400 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000401 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue})
402 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800403 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000404 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000405 return
406 }
Himani Chawla1c136902020-12-10 16:30:59 +0530407 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].prioQueueIndex =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000408 uint8(content.PriorityQueue)
Himani Chawla1c136902020-12-10 16:30:59 +0530409 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530410 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000411 if content.AesEncryption == "True" {
Himani Chawla1c136902020-12-10 16:30:59 +0530412 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000413 } else {
Himani Chawla1c136902020-12-10 16:30:59 +0530414 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000415 }
Himani Chawla1c136902020-12-10 16:30:59 +0530416 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].discardPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000417 content.DiscardPolicy
Himani Chawla1c136902020-12-10 16:30:59 +0530418 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].queueSchedPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000419 content.SchedulingPolicy
mpagenko3dbcdd22020-07-22 07:38:45 +0000420 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Himani Chawla1c136902020-12-10 16:30:59 +0530421 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportID)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000422 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000423 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300424
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300425 for _, downstreamContent := range tpInst.DownstreamGemPortAttributeList {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000426 logger.Debugw(ctx, "Operating on Downstream Gem Port", log.Fields{"downstream-gem": downstreamContent})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300427 //Commenting this out due to faliure, needs investigation
428 //if uint32(pos) == loNumGemPorts {
429 // logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
430 // log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
431 // break
432 //}
433 isMulticast := false
ozgecanetsia4b232302020-11-11 10:58:10 +0300434 //Flag is defined as string in the TP in voltha-lib-go, parsing it from string
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300435 if downstreamContent.IsMulticast != "" {
436 isMulticast, err = strconv.ParseBool(downstreamContent.IsMulticast)
437 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000438 logger.Errorw(ctx, "multicast-error-config-unknown-flag-in-technology-profile",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300439 log.Fields{"UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "error": err})
440 continue
441 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300442 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000443 logger.Infow(ctx, "Gem Port is multicast", log.Fields{"isMulticast": isMulticast})
ozgecanetsia4b232302020-11-11 10:58:10 +0300444 if isMulticast {
445 mcastGemID := uint16(downstreamContent.McastGemID)
446 _, existing := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID]
447 if existing {
448 //GEM port was previously configured, avoid setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000449 logger.Errorw(ctx, "multicast-error-config-existing-gem-port-config", log.Fields{"UniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300450 "downstream-gem": downstreamContent, "key": mcastGemID})
451 continue
452 } else {
453 //GEM port is not configured, setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000454 logger.Infow(ctx, "creating-multicast-gem-port", log.Fields{"uniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300455 "gemPortId": mcastGemID, "key": mcastGemID})
456
457 //for all further GemPorts we need to extend the mapGemPortParams
458 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID] = &gemPortParamStruct{}
459
460 //Separate McastGemId is derived from OMCI-lib-go, if not needed first needs to be removed there.
461 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortID = mcastGemID
462 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].direction = 2 // for ANI to UNI as defined in G.988
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300463
464 if downstreamContent.AesEncryption == "True" {
465 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 1
466 } else {
467 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 0
468 }
469
470 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
ozgecanetsia4b232302020-11-11 10:58:10 +0300471 if downstreamContent.PriorityQueue > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000472 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300473 log.Fields{"device-id": onuTP.deviceID, "index": mcastGemID, "PrioQueue": downstreamContent.PriorityQueue})
474 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
475 delete(onuTP.mapPonAniConfig, uniTPKey)
476 onuTP.chTpConfigProcessingStep <- 0 //error indication
477 return
ozgecanetsia4b232302020-11-11 10:58:10 +0300478 }
479 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].prioQueueIndex =
480 uint8(downstreamContent.PriorityQueue)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300481 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].pbitString =
482 strings.TrimPrefix(downstreamContent.PbitMap, binaryStringPrefix)
483
484 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].discardPolicy =
485 downstreamContent.DiscardPolicy
486 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueSchedPolicy =
487 downstreamContent.SchedulingPolicy
488 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
489 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueWeight =
490 uint8(downstreamContent.Weight)
491
ozgecanetsia4b232302020-11-11 10:58:10 +0300492 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].isMulticast = isMulticast
493 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].multicastGemPortID =
494 uint16(downstreamContent.McastGemID)
495 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].staticACL = downstreamContent.SControlList
496 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].dynamicACL = downstreamContent.DControlList
497 }
498 }
499 }
500
Himani Chawla4d908332020-08-31 12:30:20 +0530501 if !loGemPortRead {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000502 logger.Errorw(ctx, "PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000503 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000504 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800505 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000506 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000507 return
508 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000509 //logger does not simply output the given structures, just give some example debug values
dbainbri4d3a0dc2020-12-02 00:33:42 +0000510 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000511 "device-id": onuTP.deviceID, "uni-id": aUniID,
512 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
Himani Chawla1c136902020-12-10 16:30:59 +0530513 for gemPortID, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000514 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530515 "GemPort": gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000516 "QueueScheduling": gemEntry.queueSchedPolicy})
517 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000518
mpagenkodff5dda2020-08-28 11:52:01 +0000519 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000520}
521
Himani Chawla6d2ae152020-09-02 13:11:20 +0530522func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
mpagenko8b07c1b2020-11-26 10:36:31 +0000523 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000524
525 //OMCI transfer of ANI data acc. to mapPonAniConfig
526 // also the FSM's are running in background,
mpagenko8b07c1b2020-11-26 10:36:31 +0000527 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800528 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko3dbcdd22020-07-22 07:38:45 +0000529 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000530 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800531 } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000532 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000533 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000534 //AniConfigFsm already init
dbainbri4d3a0dc2020-12-02 00:33:42 +0000535 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000536}
537
538// deleteTpResource removes Resources from the ONU's specified Uni
539func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context,
540 aUniID uint8, aTpID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
541 wg *sync.WaitGroup) {
542 defer wg.Done()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000543 logger.Debugw(ctx, "will remove TP resources from ONU's UNI", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000544 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "Resource": aResource})
545 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
546
547 if cResourceGemPort == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000548 logger.Debugw(ctx, "remove GemPort from the list of existing ones of the TP", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000549 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID})
550
551 // check if the requested GemPort exists in the DB, indicate it to the FSM
552 // store locally to remove it from DB later on success
553 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
554 if pLocAniConfigOnUni == nil {
555 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000556 logger.Debugw(ctx, "AniConfig or GemEntry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000557 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
558 return
559 }
Himani Chawla1c136902020-12-10 16:30:59 +0530560 for gemPortID, gemEntry := range pLocAniConfigOnUni.mapGemPortParams {
561 if gemPortID == uint16(aEntryID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000562 //GemEntry to be deleted found
Himani Chawla1c136902020-12-10 16:30:59 +0530563 gemEntry.removeGemID = gemPortID //store the index for later removal
564 onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemPortID]
dbainbri4d3a0dc2020-12-02 00:33:42 +0000565 logger.Debugw(ctx, "Remove-GemEntry stored", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530566 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000567 break //abort loop, always only one GemPort to remove
568 }
569 }
570 if onuTP.mapRemoveGemEntry[uniTPKey] == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000571 logger.Errorw(ctx, "GemPort removal aborted - GemPort not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000572 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
573 /* Do not set some error indication to the outside system interface on delete
574 assume there is nothing to be deleted internally and hope a new config request will recover the situation
575 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s",
576 aEntryID, aUniID, onuTP.deviceID)
577 */
578 return
579 }
580 if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig {
581 // check that the TpConfigRequest was done before
582 // -> that is implicitly done using the AniConfigFsm,
583 // which must be in the according state to remove something
584 // initiate OMCI GemPort related removal
585 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
586 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
587 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000588 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000589 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
590 /* Do not set some error indication to the outside system interface on delete (see above)
591 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s",
592 aUniID, onuTP.deviceID)
593 */
594 //if the FSM is not valid, also TP related remove data should not be valid:
595 // remove GemPort from config DB
Himani Chawla1c136902020-12-10 16:30:59 +0530596 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000597 // remove the removeEntry
598 delete(onuTP.mapRemoveGemEntry, uniTPKey)
599 return
600 }
601 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000602 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000603 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
604 /* Do not set some error indication to the outside system interface on delete (see above)
605 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid",
606 aUniID, onuTP.deviceID, aTpID)
607 */
608 //if the FSM is not valid, also TP related remove data should not be valid:
609 // remove GemPort from config DB
Himani Chawla1c136902020-12-10 16:30:59 +0530610 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000611 // remove the removeEntry
612 delete(onuTP.mapRemoveGemEntry, uniTPKey)
613 return
614 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000615 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemGemiw, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000616 //even if the FSM invocation did not work we don't indicate a problem within procResult
617 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
618 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
619 return
620 }
621 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
622 //timeout or error detected
dbainbri4d3a0dc2020-12-02 00:33:42 +0000623 logger.Errorw(ctx, "GemPort removal aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000624 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
625 //even if the FSM delete execution did not work we don't indicate a problem within procResult
626 //we should never respond to delete with error ...
627 //this issue here means that the AniConfigFsm has not finished successfully
628 //which requires to reset it to allow for new usage, e.g. also on a different UNI
629 //(without that it would be reset on device down indication latest)
630 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
631 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
632 return
633 }
634 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000635 logger.Debugw(ctx, "uniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000636 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.deviceReason})
637 }
638 // remove GemPort from config DB
Himani Chawla1c136902020-12-10 16:30:59 +0530639 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000640 // remove the removeEntry
641 delete(onuTP.mapRemoveGemEntry, uniTPKey)
642 // deviceHandler StatusEvent (reason update) (see end of function) is only generated in case some element really was removed
643 } else { //if cResourceTcont == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000644 logger.Debugw(ctx, "reset TCont with AllocId", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000645 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID})
646
647 // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM
648 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
649 if pLocAniConfigOnUni == nil {
650 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000651 logger.Debugw(ctx, "AniConfig or TCont entry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000652 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
653 return
654 }
655 if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000656 logger.Errorw(ctx, "TCont removal aborted - indicated AllocId not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000657 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID})
658 /* Do not set some error indication to the outside system interface on delete
659 assume there is nothing to be deleted internally and hope a new config request will recover the situation
660 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s",
661 aEntryID, aUniID, onuTP.deviceID)
662 */
663 return
664 }
665 //T-Cont to be reset found
dbainbri4d3a0dc2020-12-02 00:33:42 +0000666 logger.Debugw(ctx, "Reset-T-Cont AllocId found - valid", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000667 "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID})
668 if onuTP.pAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000669 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000670 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
671 /* Do not set some error indication to the outside system interface on delete (see above)
672 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s",
673 aUniID, onuTP.deviceID)
674 */
675 //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 +0000676 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000677 return
678 }
679 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000680 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000681 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
682 //even if the FSM invocation did not work we don't indicate a problem within procResult
683 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
684 //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 +0000685 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000686 return
687 }
688 if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig {
689 // check that the TpConfigRequest was done before
690 // -> that is implicitly done using the AniConfigFsm,
691 // which must be in the according state to remove something
692 // initiate OMCI TCont related cleanup
693 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
694 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000695 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemTcontPath, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000696 //even if the FSM invocation did not work we don't indicate a problem within procResult
697 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
698 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
699 return
700 }
701 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
702 //timeout or error detected
dbainbri4d3a0dc2020-12-02 00:33:42 +0000703 logger.Errorw(ctx, "TCont cleanup aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000704 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
705 //even if the FSM delete execution did not work we don't indicate a problem within procResult
706 //we should never respond to delete with error ...
707 //this issue here means that the AniConfigFsm has not finished successfully
708 //which requires to reset it to allow for new usage, e.g. also on a different UNI
709 //(without that it would be reset on device down indication latest)
710 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
711 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
712 return
713 }
714 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000715 logger.Debugw(ctx, "uniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000716 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.deviceReason})
717 }
718 //clear the internal store profile data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000719 onuTP.clearAniSideConfig(ctx, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000720 // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created
721 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
722 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
723 }
724 // generate deviceHandler StatusEvent in case the FSM was not invoked
dbainbri4d3a0dc2020-12-02 00:33:42 +0000725 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(ctx, OmciAniResourceRemoved)
mpagenko3dbcdd22020-07-22 07:38:45 +0000726}
727
Himani Chawla6d2ae152020-09-02 13:11:20 +0530728func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000729 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000730 select {
731 case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000732 logger.Warnw(ctx, "processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000733 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000734 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000735 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000736 if rxStep == aProcessingStep {
737 return true
738 }
739 //all other values are not accepted - including 0 for error indication
dbainbri4d3a0dc2020-12-02 00:33:42 +0000740 logger.Warnw(ctx, "Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000741 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000742 "wantedStep": aProcessingStep, "haveStep": rxStep})
743 return false
744 }
745}
746
Himani Chawla4d908332020-08-31 12:30:20 +0530747// createUniLockFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000748func (onuTP *onuUniTechProf) createAniConfigFsm(ctx context.Context, aUniID uint8, aTpID uint8,
mpagenko8b07c1b2020-11-26 10:36:31 +0000749 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000750 logger.Debugw(ctx, "createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000751 chAniConfigFsm := make(chan Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800752 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000753 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(ctx, true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000754 if pDevEntry == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000755 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000756 return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000757 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000758 pAniCfgFsm := newUniPonAniConfigFsm(ctx, pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800759 pDevEntry.pOnuDB, aTpID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000760 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko8b07c1b2020-11-26 10:36:31 +0000761 if pAniCfgFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000762 logger.Errorw(ctx, "AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000763 return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000764 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000765 if onuTP.pAniConfigFsm == nil {
766 onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800767 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000768 onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm
dbainbri4d3a0dc2020-12-02 00:33:42 +0000769 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000770}
771
mpagenko3dbcdd22020-07-22 07:38:45 +0000772// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000773func (onuTP *onuUniTechProf) runAniConfigFsm(ctx context.Context, aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000774 /* Uni related ANI config procedure -
775 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
776 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800777 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
778
779 pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000780 if pACStatemachine != nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000781 if aEvent == aniEvStart {
782 if !pACStatemachine.Is(aniStDisabled) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000783 logger.Errorw(ctx, "wrong state of AniConfigFSM to start - want: Disabled", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000784 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000785 // maybe try a FSM reset and then again ... - TODO!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000786 return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000787 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000788 } else if !pACStatemachine.Is(aniStConfigDone) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000789 logger.Errorw(ctx, "wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000790 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000791 return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000792 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000793 //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config)
794 onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
795 if err := pACStatemachine.Event(aEvent); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000796 logger.Errorw(ctx, "AniConfigFSM: can't trigger event", log.Fields{"err": err})
mpagenko8b07c1b2020-11-26 10:36:31 +0000797 return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID)
798 }
799 /***** AniConfigFSM event notified */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000800 logger.Debugw(ctx, "AniConfigFSM event notified", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000801 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent})
802 return nil
mpagenko3dbcdd22020-07-22 07:38:45 +0000803 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000804 logger.Errorw(ctx, "AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000805 // maybe try a FSM reset and then again ... - TODO!!!
806 return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID)
mpagenkoaf801632020-07-03 10:00:42 +0000807}
mpagenkodff5dda2020-08-28 11:52:01 +0000808
Girish Gowdra041dcb32020-11-16 16:54:30 -0800809// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000810func (onuTP *onuUniTechProf) clearAniSideConfig(ctx context.Context, aUniID uint8, aTpID uint8) {
811 logger.Debugw(ctx, "removing TpIndication and PonAniConfig data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000812 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800813 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
814
815 onuTP.mutexTPState.Lock()
816 defer onuTP.mutexTPState.Unlock()
817 delete(onuTP.mapUniTpIndication, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000818 //delete on the PonAniConfig map of this UNI should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800819 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000820}
821
mpagenkodff5dda2020-08-28 11:52:01 +0000822// setConfigDone sets the requested techProfile config state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800823func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
824 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
825 onuTP.mutexTPState.Lock()
826 defer onuTP.mutexTPState.Unlock()
827 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
828 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000829 } //else: the state is just ignored (does not exist)
830}
831
832// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
dbainbri4d3a0dc2020-12-02 00:33:42 +0000833func (onuTP *onuUniTechProf) getTechProfileDone(ctx context.Context, aUniID uint8, aTpID uint8) bool {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800834 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
835 onuTP.mutexTPState.Lock()
836 defer onuTP.mutexTPState.Unlock()
837 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
838 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
839 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000840 logger.Debugw(ctx, "TechProfile not relevant for requested flow config - waiting on delete",
mpagenko2418ab02020-11-12 12:58:06 +0000841 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
842 return false //still waiting for removal of this techProfile first
843 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800844 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000845 }
846 }
847 //for all other constellations indicate false = Config not done
848 return false
849}
mpagenko2418ab02020-11-12 12:58:06 +0000850
851// setProfileToDelete sets the requested techProfile toDelete state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800852func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
853 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
854 onuTP.mutexTPState.Lock()
855 defer onuTP.mutexTPState.Unlock()
856 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
857 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000858 } //else: the state is just ignored (does not exist)
859}
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300860
861// setProfileToDelete sets the requested techProfile toDelete state (if possible)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000862func (onuTP *onuUniTechProf) getMulticastGemPorts(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300863 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
864 onuTP.mutexTPState.Lock()
865 defer onuTP.mutexTPState.Unlock()
866 gemPortIds := make([]uint16, 0)
867 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
868 for _, gemPortParam := range techProfile.mapGemPortParams {
869 if gemPortParam.isMulticast {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000870 logger.Debugw(ctx, "Detected multicast gemPort", log.Fields{"device-id": onuTP.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300871 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
872 "mcastGemId": gemPortParam.multicastGemPortID})
873 gemPortIds = append(gemPortIds, gemPortParam.multicastGemPortID)
874 }
875 }
876 } //else: the state is just ignored (does not exist)
877 return gemPortIds
878}
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800879
880func (onuTP *onuUniTechProf) GetAllBidirectionalGemPortIDsForOnu() []uint16 {
881 var gemPortInstIDs []uint16
882 onuTP.mutexTPState.RLock()
883 defer onuTP.mutexTPState.RUnlock()
884 for _, tcontGemList := range onuTP.mapPonAniConfig {
885 for gemPortID, gemPortData := range tcontGemList.mapGemPortParams {
886 if gemPortData != nil && !gemPortData.isMulticast { // only if not multicast gem port
887 gemPortInstIDs = append(gemPortInstIDs, gemPortID)
888 }
889 }
890 }
891 return gemPortInstIDs
892}