blob: 442d0a2aa5f0271e9d84c47f838a1effaa121947 [file] [log] [blame]
mpagenkoaf801632020-07-03 10:00:42 +00001/*
Joey Armstrong89c812c2024-01-12 19:00:20 -05002 * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors
mpagenkoaf801632020-07-03 10:00:42 +00003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Joey Armstrong89c812c2024-01-12 19:00:20 -050017// Package avcfg provides anig and vlan configuration functionality
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000018package avcfg
mpagenkoaf801632020-07-03 10:00:42 +000019
20import (
21 "context"
Andrea Campanella6515c582020-10-05 11:25:00 +020022 "fmt"
ozgecanetsia4b232302020-11-11 10:58:10 +030023 "strconv"
mpagenko3dbcdd22020-07-22 07:38:45 +000024 "strings"
mpagenkoaf801632020-07-03 10:00:42 +000025 "sync"
26
khenaidoo7d3c5582021-08-11 18:09:44 -040027 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000028 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
khenaidoo7d3c5582021-08-11 18:09:44 -040029 "github.com/opencord/voltha-protos/v5/go/tech_profile"
mpagenkoaf801632020-07-03 10:00:42 +000030)
31
Joey Armstrong89c812c2024-01-12 19:00:20 -050032// definitions for TechProfileProcessing - copied from OltAdapter:openolt_flowmgr.go
33//
34// could perhaps be defined more globally
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000035const (
Himani Chawla6d2ae152020-09-02 13:11:20 +053036 // binaryStringPrefix is binary string prefix
37 binaryStringPrefix = "0b"
38 // binaryBit1 is binary bit 1 expressed as a character
39 //binaryBit1 = '1'
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000040)
mpagenkoaf801632020-07-03 10:00:42 +000041
Joey Armstrong89c812c2024-01-12 19:00:20 -050042// as defined in G.988
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +000043const (
44 cGemDirUniToAni = 1
45 cGemDirAniToUni = 2
46 cGemDirBiDirect = 3
47)
48
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000049// ResourceEntry - TODO: add comment
50type ResourceEntry int
mpagenkoaf801632020-07-03 10:00:42 +000051
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000052// TODO: add comment
mpagenkoaf801632020-07-03 10:00:42 +000053const (
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000054 CResourceGemPort ResourceEntry = 1
55 CResourceTcont ResourceEntry = 2
mpagenkoaf801632020-07-03 10:00:42 +000056)
57
mpagenko3dbcdd22020-07-22 07:38:45 +000058type tTechProfileIndication struct {
mpagenkodff5dda2020-08-28 11:52:01 +000059 techProfileType string
Girish Gowdra041dcb32020-11-16 16:54:30 -080060 techProfileID uint8
mpagenkodff5dda2020-08-28 11:52:01 +000061 techProfileConfigDone bool
mpagenko2418ab02020-11-12 12:58:06 +000062 techProfileToDelete bool
mpagenko3dbcdd22020-07-22 07:38:45 +000063}
64
65type tcontParamStruct struct {
66 allocID uint16
67 schedPolicy uint8
68}
69type gemPortParamStruct struct {
Himani Chawla4d908332020-08-31 12:30:20 +053070 //ponOmciCC bool
mpagenko3dbcdd22020-07-22 07:38:45 +000071 gemPortID uint16
72 direction uint8
73 gemPortEncState uint8
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000074 prioQueueIndex uint8
75 pbitString string
mpagenko3dbcdd22020-07-22 07:38:45 +000076 discardPolicy string
Himani Chawla4d908332020-08-31 12:30:20 +053077 //could also be a queue specific parameter, not used that way here
78 //maxQueueSize uint16
mpagenko3dbcdd22020-07-22 07:38:45 +000079 queueSchedPolicy string
80 queueWeight uint8
Himani Chawla1c136902020-12-10 16:30:59 +053081 removeGemID uint16
ozgecanetsia4b232302020-11-11 10:58:10 +030082 isMulticast bool
83 //TODO check if this has any value/difference from gemPortId
84 multicastGemPortID uint16
85 staticACL string
86 dynamicACL string
mpagenko3dbcdd22020-07-22 07:38:45 +000087}
88
Joey Armstrong89c812c2024-01-12 19:00:20 -050089// refers to one tcont and its properties and all assigned GemPorts and their properties
mpagenko3dbcdd22020-07-22 07:38:45 +000090type tcontGemList struct {
91 tcontParams tcontParamStruct
92 mapGemPortParams map[uint16]*gemPortParamStruct
93}
94
Girish Gowdra041dcb32020-11-16 16:54:30 -080095// refers a unique combination of uniID and tpID for a given ONU.
96type uniTP struct {
97 uniID uint8
98 tpID uint8
99}
mpagenko3dbcdd22020-07-22 07:38:45 +0000100
Joey Armstrong89c812c2024-01-12 19:00:20 -0500101// OnuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000102type OnuUniTechProf struct {
mpagenko01e726e2020-10-23 09:45:29 +0000103 deviceID string
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000104 baseDeviceHandler cmn.IdeviceHandler
105 onuDevice cmn.IonuDeviceEntry
mpagenkodff5dda2020-08-28 11:52:01 +0000106 tpProcMutex sync.RWMutex
mpagenkodff5dda2020-08-28 11:52:01 +0000107 chTpConfigProcessingStep chan uint8
Girish Gowdra041dcb32020-11-16 16:54:30 -0800108 mapUniTpIndication map[uniTP]*tTechProfileIndication //use pointer values to ease assignments to the map
109 mapPonAniConfig map[uniTP]*tcontGemList //per UNI: use pointer values to ease assignments to the map
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000110 PAniConfigFsm map[uniTP]*UniPonAniConfigFsm
Girish Gowdra041dcb32020-11-16 16:54:30 -0800111 procResult map[uniTP]error //error indication of processing
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800112 mutexTPState sync.RWMutex
Girish Gowdra041dcb32020-11-16 16:54:30 -0800113 tpProfileExists map[uniTP]bool
mpagenko73143992021-04-09 15:17:10 +0000114 tpProfileResetting map[uniTP]bool
mpagenko8b07c1b2020-11-26 10:36:31 +0000115 mapRemoveGemEntry map[uniTP]*gemPortParamStruct //per UNI: pointer to GemEntry to be removed
mpagenkoaf801632020-07-03 10:00:42 +0000116}
117
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000118func (onuTP *OnuUniTechProf) multicastConfiguredForOtherUniTps(ctx context.Context, uniTpKey uniTP) bool {
119 for _, aniFsm := range onuTP.PAniConfigFsm {
ozgecanetsia72e1c9f2021-05-26 17:26:29 +0300120 if aniFsm.uniTpKey.uniID == uniTpKey.uniID && aniFsm.uniTpKey.tpID == uniTpKey.tpID {
121 continue
122 }
123 if aniFsm.hasMulticastGem(ctx) {
124 return true
125 }
126 }
127 return false
128}
129
Joey Armstrong89c812c2024-01-12 19:00:20 -0500130// NewOnuUniTechProf returns the instance of a OnuUniTechProf
131// (one instance per ONU/deviceHandler for all possible UNI's)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000132func NewOnuUniTechProf(ctx context.Context, aDeviceHandler cmn.IdeviceHandler, aOnuDev cmn.IonuDeviceEntry) *OnuUniTechProf {
133
134 var onuTP OnuUniTechProf
135 onuTP.deviceID = aDeviceHandler.GetDeviceID()
136 logger.Debugw(ctx, "init-OnuUniTechProf", log.Fields{"device-id": onuTP.deviceID})
mpagenkoaf801632020-07-03 10:00:42 +0000137 onuTP.baseDeviceHandler = aDeviceHandler
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000138 onuTP.onuDevice = aOnuDev
mpagenkodff5dda2020-08-28 11:52:01 +0000139 onuTP.chTpConfigProcessingStep = make(chan uint8)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800140 onuTP.mapUniTpIndication = make(map[uniTP]*tTechProfileIndication)
141 onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList)
142 onuTP.procResult = make(map[uniTP]error)
143 onuTP.tpProfileExists = make(map[uniTP]bool)
mpagenko73143992021-04-09 15:17:10 +0000144 onuTP.tpProfileResetting = make(map[uniTP]bool)
mpagenko8b07c1b2020-11-26 10:36:31 +0000145 onuTP.mapRemoveGemEntry = make(map[uniTP]*gemPortParamStruct)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000146
mpagenkoaf801632020-07-03 10:00:42 +0000147 return &onuTP
148}
149
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000150// LockTpProcMutex locks OnuUniTechProf processing mutex
151func (onuTP *OnuUniTechProf) LockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000152 onuTP.tpProcMutex.Lock()
153}
154
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000155// UnlockTpProcMutex unlocks OnuUniTechProf processing mutex
156func (onuTP *OnuUniTechProf) UnlockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000157 onuTP.tpProcMutex.Unlock()
158}
159
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000160// ResetTpProcessingErrorIndication resets the internal error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000161// need to be called before evaluation of any subsequent processing (given by waitForTpCompletion())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000162func (onuTP *OnuUniTechProf) ResetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) {
mpagenko73143992021-04-09 15:17:10 +0000163 onuTP.mutexTPState.Lock()
164 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800165 onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000166}
167
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000168// GetTpProcessingErrorIndication - TODO: add comment
169func (onuTP *OnuUniTechProf) GetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error {
mpagenko73143992021-04-09 15:17:10 +0000170 onuTP.mutexTPState.RLock()
171 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800172 return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}]
mpagenko3dbcdd22020-07-22 07:38:45 +0000173}
174
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000175// ConfigureUniTp checks existing tp resources to configure and starts the corresponding OMCI configuation of the UNI port
mpagenko3dbcdd22020-07-22 07:38:45 +0000176// all possibly blocking processing must be run in background to allow for deadline supervision!
177// but take care on sequential background processing when needed (logical dependencies)
Joey Armstrong89c812c2024-01-12 19:00:20 -0500178//
179// use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000180func (onuTP *OnuUniTechProf) ConfigureUniTp(ctx context.Context,
Girish Gowdra50e56422021-06-01 16:46:04 -0700181 aUniID uint8, aPathString string, tpInst tech_profile.TechProfileInstance, wg *sync.WaitGroup) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000182 defer wg.Done() //always decrement the waitGroup on return
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530183 logger.Info(ctx, "configure the Uni according to TpPath", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000184 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000185 tpID, err := cmn.GetTpIDFromTpPath(aPathString)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800186 uniTpKey := uniTP{uniID: aUniID, tpID: tpID}
187 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000188 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 -0800189 return
190 }
mpagenkoaf801632020-07-03 10:00:42 +0000191
mpagenko3dbcdd22020-07-22 07:38:45 +0000192 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000193 var pCurrentUniPort *cmn.OnuUniPort
194 for _, uniPort := range *onuTP.baseDeviceHandler.GetUniEntityMap() {
mpagenko3dbcdd22020-07-22 07:38:45 +0000195 // only if this port is validated for operState transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000196 if uniPort.UniID == aUniID {
mpagenko3dbcdd22020-07-22 07:38:45 +0000197 pCurrentUniPort = uniPort
198 break //found - end search loop
199 }
200 }
201 if pCurrentUniPort == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000202 logger.Errorw(ctx, "TechProfile configuration aborted: requested uniID not found in PortDB",
mpagenko73143992021-04-09 15:17:10 +0000203 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
204 onuTP.mutexTPState.Lock()
205 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800206 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200207 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000208 return
209 }
mpagenkoaf801632020-07-03 10:00:42 +0000210
mpagenko73143992021-04-09 15:17:10 +0000211 if onuTP.getProfileResetting(uniTpKey) {
212 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
213 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
214 onuTP.mutexTPState.Lock()
215 defer onuTP.mutexTPState.Unlock()
216 onuTP.procResult[uniTpKey] = fmt.Errorf(
217 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
218 aUniID, onuTP.deviceID)
219 return
220 }
mpagenkodff5dda2020-08-28 11:52:01 +0000221 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
mpagenkoaf801632020-07-03 10:00:42 +0000222
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000223 //according to UpdateOnuUniTpPath() logic the assumption here is, that this configuration is only called
mpagenko3dbcdd22020-07-22 07:38:45 +0000224 // in case the KVPath has changed for the given UNI,
225 // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
226 // (ANI) configuration of this port has to be removed first
227 // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
228 // existence of configuration can be detected based on tp stored TCONT's
Andrea Campanella6515c582020-10-05 11:25:00 +0200229 //TODO:
mpagenko3dbcdd22020-07-22 07:38:45 +0000230 /* if tcontMap not empty {
231 go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000232 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000233 //timeout or error detected
234 return
235 }
236 clear tcontMap
237 }
238
239 processingStep++
240 */
Girish Gowdra50e56422021-06-01 16:46:04 -0700241 go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, tpInst, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000242 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000243 //timeout or error detected
mpagenko73143992021-04-09 15:17:10 +0000244 onuTP.mutexTPState.RLock()
Girish Gowdra24dd1132021-07-06 15:25:40 -0700245 ok := onuTP.tpProfileExists[uniTpKey]
246 onuTP.mutexTPState.RUnlock()
247 if ok {
mpagenko01e726e2020-10-23 09:45:29 +0000248 //ignore the internal error in case the new profile is already configured
249 // and abort the processing here
250 return
251 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000252 logger.Errorw(ctx, "tech-profile related configuration aborted on read",
mpagenko01e726e2020-10-23 09:45:29 +0000253 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000254 onuTP.mutexTPState.Lock()
255 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800256 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200257 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000258 return
259 }
mpagenko73143992021-04-09 15:17:10 +0000260 if onuTP.getProfileResetting(uniTpKey) {
261 logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{
262 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID})
263 onuTP.mutexTPState.Lock()
264 defer onuTP.mutexTPState.Unlock()
265 onuTP.procResult[uniTpKey] = fmt.Errorf(
266 "techProfile config aborted - reset requested in parallel - for uniID %d on %s",
267 aUniID, onuTP.deviceID)
268 return
269 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000270 processingStep++
Girish Gowdra041dcb32020-11-16 16:54:30 -0800271
mpagenko73143992021-04-09 15:17:10 +0000272 //ensure read protection for access to mapPonAniConfig
273 onuTP.mutexTPState.RLock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800274 valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey]
mpagenko73143992021-04-09 15:17:10 +0000275 onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800276 if existPA {
277 if valuePA != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000278 //Config data for this uni and and at least TCont Index 0 exist
mpagenko8b07c1b2020-11-26 10:36:31 +0000279 if err := onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000280 logger.Errorw(ctx, "tech-profile related FSM could not be started",
mpagenko8b07c1b2020-11-26 10:36:31 +0000281 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000282 onuTP.mutexTPState.Lock()
283 defer onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000284 onuTP.procResult[uniTpKey] = err
285 return
286 }
mpagenkodff5dda2020-08-28 11:52:01 +0000287 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000288 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
289 logger.Warnw(ctx, "tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000290 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800291
mpagenko73143992021-04-09 15:17:10 +0000292 onuTP.mutexTPState.Lock()
293 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800294 onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
Andrea Campanella6515c582020-10-05 11:25:00 +0200295 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530296 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000297 //which requires to reset it to allow for new usage, e.g. also on a different UNI
298 //(without that it would be reset on device down indication latest)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000299 if _, ok := onuTP.PAniConfigFsm[uniTpKey]; ok {
300 _ = onuTP.PAniConfigFsm[uniTpKey].PAdaptFsm.PFsm.Event(aniEvReset)
mpagenko73143992021-04-09 15:17:10 +0000301 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000302 return
mpagenkoaf801632020-07-03 10:00:42 +0000303 }
304 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000305 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000306 logger.Errorw(ctx, "no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000307 "device-id": onuTP.deviceID, "uni-id": aUniID})
mpagenko73143992021-04-09 15:17:10 +0000308 onuTP.mutexTPState.Lock()
309 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800310 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 +0200311 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000312 return
mpagenkoaf801632020-07-03 10:00:42 +0000313 }
314 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000315 logger.Errorw(ctx, "no PonAni data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000316 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800317
mpagenko73143992021-04-09 15:17:10 +0000318 onuTP.mutexTPState.Lock()
319 defer onuTP.mutexTPState.Unlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800320 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 +0200321 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000322 return
mpagenkoaf801632020-07-03 10:00:42 +0000323 }
324}
325
mpagenko3dbcdd22020-07-22 07:38:45 +0000326/* internal methods *********************/
ozgecanetsia4b232302020-11-11 10:58:10 +0300327// nolint: gocyclo
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000328func (onuTP *OnuUniTechProf) readAniSideConfigFromTechProfile(
Girish Gowdra50e56422021-06-01 16:46:04 -0700329 ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, tpInst tech_profile.TechProfileInstance, aProcessingStep uint8) {
330 var err error
mpagenko3dbcdd22020-07-22 07:38:45 +0000331 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
332 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
333 subStringSlice := strings.Split(aPathString, "/")
334 if len(subStringSlice) <= 2 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000335 logger.Errorw(ctx, "invalid path name format",
mpagenko3dbcdd22020-07-22 07:38:45 +0000336 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000337 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000338 return
339 }
340
mpagenko73143992021-04-09 15:17:10 +0000341 //ensure write protection for access to used maps
342 onuTP.mutexTPState.Lock()
343 defer onuTP.mutexTPState.Unlock()
344
345 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
346 onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false
347
mpagenko3dbcdd22020-07-22 07:38:45 +0000348 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000349 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
350 // then we throw a warning, set an internal error and abort with error,
351 // which is later re-defined to success response to OLT adapter
352 // if TPId has changed, current data is removed (note that the ONU config state may be
353 // ambivalent in such a case)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800354 if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000355 logger.Warnw(ctx, "Some active profile entry at reading new TechProfile",
mpagenko3dbcdd22020-07-22 07:38:45 +0000356 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800357 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
358 if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID {
mpagenko01e726e2020-10-23 09:45:29 +0000359 // ProfId not changed - assume profile to be still the same
360 // anyway this should not appear after full support of profile (Gem/TCont) removal
dbainbri4d3a0dc2020-12-02 00:33:42 +0000361 logger.Warnw(ctx, "New TechProfile already exists - aborting configuration",
mpagenko01e726e2020-10-23 09:45:29 +0000362 log.Fields{"device-id": onuTP.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800363 onuTP.tpProfileExists[uniTPKey] = true
mpagenko01e726e2020-10-23 09:45:29 +0000364 onuTP.chTpConfigProcessingStep <- 0 //error indication
365 return
366 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000367 //delete on the mapUniTpIndication map not needed, just overwritten later
368 //delete on the PonAniConfig map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800369 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenko3dbcdd22020-07-22 07:38:45 +0000370 } else {
371 // this is normal processing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800372 onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
mpagenko3dbcdd22020-07-22 07:38:45 +0000373 }
374
Girish Gowdra041dcb32020-11-16 16:54:30 -0800375 onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000376 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
Girish Gowdra041dcb32020-11-16 16:54:30 -0800377 onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID
378 onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false
379 onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false
dbainbri4d3a0dc2020-12-02 00:33:42 +0000380 logger.Debugw(ctx, "tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000381 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800382 "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType,
383 "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000384
mpagenko01e726e2020-10-23 09:45:29 +0000385 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000386 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800387 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000388
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000389 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000390 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra50e56422021-06-01 16:46:04 -0700391 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocId)
Himani Chawla4d908332020-08-31 12:30:20 +0530392 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000393 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
Girish Gowdra50e56422021-06-01 16:46:04 -0700394 if tpInst.UsScheduler.QSchedPolicy == tech_profile.SchedulingPolicy_StrictPriority {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800395 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000396 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000397 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800398 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000399 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000400 loNumGemPorts := tpInst.NumGemPorts
401 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000402 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000403 if uint32(pos) == loNumGemPorts {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000404 logger.Debugw(ctx, "PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
mpagenko1cc3cb42020-07-27 15:24:38 +0000405 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000406 break
407 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000408 if pos == 0 {
409 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
410 loGemPortRead = true
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000411 }
Himani Chawla1c136902020-12-10 16:30:59 +0530412 //for all GemPorts we need to extend the mapGemPortParams
Girish Gowdra50e56422021-06-01 16:46:04 -0700413 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)] = &gemPortParamStruct{}
Himani Chawla1c136902020-12-10 16:30:59 +0530414
Girish Gowdra50e56422021-06-01 16:46:04 -0700415 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortID =
416 uint16(content.GemportId)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000417 //direction can be correlated later with Downstream list,
418 // for now just assume bidirectional (upstream never exists alone)
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +0000419 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].direction = cGemDirBiDirect
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000420 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
Girish Gowdra50e56422021-06-01 16:46:04 -0700421 if content.PriorityQ > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000422 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Girish Gowdra50e56422021-06-01 16:46:04 -0700423 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQ})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000424 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800425 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000426 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000427 return
428 }
Girish Gowdra50e56422021-06-01 16:46:04 -0700429 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].prioQueueIndex =
430 uint8(content.PriorityQ)
431 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530432 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000433 if content.AesEncryption == "True" {
Girish Gowdra50e56422021-06-01 16:46:04 -0700434 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000435 } else {
Girish Gowdra50e56422021-06-01 16:46:04 -0700436 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000437 }
Girish Gowdra50e56422021-06-01 16:46:04 -0700438 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].discardPolicy =
439 content.DiscardPolicy.String()
440 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].queueSchedPolicy =
441 content.SchedulingPolicy.String()
mpagenko3dbcdd22020-07-22 07:38:45 +0000442 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Girish Gowdra50e56422021-06-01 16:46:04 -0700443 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000444 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000445 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300446
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300447 for _, downstreamContent := range tpInst.DownstreamGemPortAttributeList {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000448 logger.Debugw(ctx, "Operating on Downstream Gem Port", log.Fields{"downstream-gem": downstreamContent})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300449 //Commenting this out due to faliure, needs investigation
450 //if uint32(pos) == loNumGemPorts {
451 // logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
452 // log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
453 // break
454 //}
455 isMulticast := false
ozgecanetsia4b232302020-11-11 10:58:10 +0300456 //Flag is defined as string in the TP in voltha-lib-go, parsing it from string
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300457 if downstreamContent.IsMulticast != "" {
458 isMulticast, err = strconv.ParseBool(downstreamContent.IsMulticast)
459 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000460 logger.Errorw(ctx, "multicast-error-config-unknown-flag-in-technology-profile",
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000461 log.Fields{"device-id": onuTP.deviceID, "UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "error": err})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300462 continue
463 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300464 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000465 logger.Infow(ctx, "Gem Port is multicast", log.Fields{"isMulticast": isMulticast})
ozgecanetsia4b232302020-11-11 10:58:10 +0300466 if isMulticast {
Girish Gowdra50e56422021-06-01 16:46:04 -0700467 mcastGemID := uint16(downstreamContent.MulticastGemId)
ozgecanetsia4b232302020-11-11 10:58:10 +0300468 _, existing := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID]
469 if existing {
470 //GEM port was previously configured, avoid setting multicast attributes
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000471 logger.Errorw(ctx, "multicast-error-config-existing-gem-port-config", log.Fields{"device-id": onuTP.deviceID,
472 "UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "key": mcastGemID})
ozgecanetsia4b232302020-11-11 10:58:10 +0300473 continue
474 } else {
475 //GEM port is not configured, setting multicast attributes
dbainbri4d3a0dc2020-12-02 00:33:42 +0000476 logger.Infow(ctx, "creating-multicast-gem-port", log.Fields{"uniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300477 "gemPortId": mcastGemID, "key": mcastGemID})
478
479 //for all further GemPorts we need to extend the mapGemPortParams
480 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID] = &gemPortParamStruct{}
481
482 //Separate McastGemId is derived from OMCI-lib-go, if not needed first needs to be removed there.
483 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortID = mcastGemID
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +0000484 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].direction = cGemDirAniToUni
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300485
486 if downstreamContent.AesEncryption == "True" {
487 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 1
488 } else {
489 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 0
490 }
491
492 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
Girish Gowdra50e56422021-06-01 16:46:04 -0700493 if downstreamContent.PriorityQ > 7 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000494 logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid",
Girish Gowdra50e56422021-06-01 16:46:04 -0700495 log.Fields{"device-id": onuTP.deviceID, "index": mcastGemID, "PrioQueue": downstreamContent.PriorityQ})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300496 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
497 delete(onuTP.mapPonAniConfig, uniTPKey)
498 onuTP.chTpConfigProcessingStep <- 0 //error indication
499 return
ozgecanetsia4b232302020-11-11 10:58:10 +0300500 }
501 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].prioQueueIndex =
Girish Gowdra50e56422021-06-01 16:46:04 -0700502 uint8(downstreamContent.PriorityQ)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300503 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].pbitString =
504 strings.TrimPrefix(downstreamContent.PbitMap, binaryStringPrefix)
505
506 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].discardPolicy =
Girish Gowdra50e56422021-06-01 16:46:04 -0700507 downstreamContent.DiscardPolicy.String()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300508 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueSchedPolicy =
Girish Gowdra50e56422021-06-01 16:46:04 -0700509 downstreamContent.SchedulingPolicy.String()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300510 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
511 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueWeight =
512 uint8(downstreamContent.Weight)
513
ozgecanetsia4b232302020-11-11 10:58:10 +0300514 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].isMulticast = isMulticast
515 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].multicastGemPortID =
Girish Gowdra50e56422021-06-01 16:46:04 -0700516 uint16(downstreamContent.MulticastGemId)
517 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].staticACL = downstreamContent.StaticAccessControlList
518 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].dynamicACL = downstreamContent.DynamicAccessControlList
ozgecanetsia4b232302020-11-11 10:58:10 +0300519 }
520 }
521 }
522
Himani Chawla4d908332020-08-31 12:30:20 +0530523 if !loGemPortRead {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000524 logger.Errorw(ctx, "PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000525 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000526 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800527 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000528 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000529 return
530 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000531 //logger does not simply output the given structures, just give some example debug values
dbainbri4d3a0dc2020-12-02 00:33:42 +0000532 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000533 "device-id": onuTP.deviceID, "uni-id": aUniID,
534 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
Himani Chawla1c136902020-12-10 16:30:59 +0530535 for gemPortID, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000536 logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530537 "GemPort": gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000538 "QueueScheduling": gemEntry.queueSchedPolicy})
539 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000540
mpagenkodff5dda2020-08-28 11:52:01 +0000541 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000542}
543
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000544func (onuTP *OnuUniTechProf) setAniSideConfigFromTechProfile(
545 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *cmn.OnuUniPort, aProcessingStep uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000546
547 //OMCI transfer of ANI data acc. to mapPonAniConfig
548 // also the FSM's are running in background,
mpagenko8b07c1b2020-11-26 10:36:31 +0000549 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800550 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000551 if onuTP.PAniConfigFsm == nil {
552 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, cmn.OmciAniConfigDone, aProcessingStep)
553 } else if _, ok := onuTP.PAniConfigFsm[uniTPKey]; !ok {
554 return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, cmn.OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000555 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000556 //AniConfigFsm already init
dbainbri4d3a0dc2020-12-02 00:33:42 +0000557 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000558}
559
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000560// DeleteTpResource removes Resources from the ONU's specified Uni
mpagenko73143992021-04-09 15:17:10 +0000561// nolint: gocyclo
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000562func (onuTP *OnuUniTechProf) DeleteTpResource(ctx context.Context,
563 aUniID uint8, aTpID uint8, aPathString string, aResource ResourceEntry, aEntryID uint32,
mpagenko8b07c1b2020-11-26 10:36:31 +0000564 wg *sync.WaitGroup) {
565 defer wg.Done()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000566 logger.Debugw(ctx, "will remove TP resources from ONU's UNI", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000567 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "Resource": aResource})
568 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
569
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000570 if CResourceGemPort == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000571 logger.Debugw(ctx, "remove GemPort from the list of existing ones of the TP", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000572 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID})
573
mpagenko73143992021-04-09 15:17:10 +0000574 //ensure read protection for access to mapPonAniConfig
575 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000576 // check if the requested GemPort exists in the DB, indicate it to the FSM
577 // store locally to remove it from DB later on success
578 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
579 if pLocAniConfigOnUni == nil {
mpagenko73143992021-04-09 15:17:10 +0000580 onuTP.mutexTPState.RUnlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000581 // No relevant entry exists anymore - acknowledge success
dbainbri4d3a0dc2020-12-02 00:33:42 +0000582 logger.Debugw(ctx, "AniConfig or GemEntry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000583 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
584 return
585 }
mpagenko73143992021-04-09 15:17:10 +0000586 onuTP.mutexTPState.RUnlock()
587
Himani Chawla1c136902020-12-10 16:30:59 +0530588 for gemPortID, gemEntry := range pLocAniConfigOnUni.mapGemPortParams {
589 if gemPortID == uint16(aEntryID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000590 //GemEntry to be deleted found
Himani Chawla1c136902020-12-10 16:30:59 +0530591 gemEntry.removeGemID = gemPortID //store the index for later removal
592 onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemPortID]
dbainbri4d3a0dc2020-12-02 00:33:42 +0000593 logger.Debugw(ctx, "Remove-GemEntry stored", log.Fields{
Himani Chawla1c136902020-12-10 16:30:59 +0530594 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000595 break //abort loop, always only one GemPort to remove
596 }
597 }
598 if onuTP.mapRemoveGemEntry[uniTPKey] == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000599 logger.Errorw(ctx, "GemPort removal aborted - GemPort not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000600 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
601 /* Do not set some error indication to the outside system interface on delete
602 assume there is nothing to be deleted internally and hope a new config request will recover the situation
603 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s",
604 aEntryID, aUniID, onuTP.deviceID)
605 */
606 return
607 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000608 if onuTP.baseDeviceHandler.IsReadyForOmciConfig() {
mpagenko8b07c1b2020-11-26 10:36:31 +0000609 // check that the TpConfigRequest was done before
610 // -> that is implicitly done using the AniConfigFsm,
611 // which must be in the according state to remove something
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000612 if onuTP.PAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000613 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000614 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
615 /* Do not set some error indication to the outside system interface on delete (see above)
616 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s",
617 aUniID, onuTP.deviceID)
618 */
619 //if the FSM is not valid, also TP related remove data should not be valid:
620 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000621 //ensure write protection for access to mapPonAniConfig
622 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530623 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000624 // remove the removeEntry
625 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000626 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000627 return
628 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000629 if _, ok := onuTP.PAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000630 logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000631 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
632 /* Do not set some error indication to the outside system interface on delete (see above)
633 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid",
634 aUniID, onuTP.deviceID, aTpID)
635 */
636 //if the FSM is not valid, also TP related remove data should not be valid:
637 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000638 //ensure write protection for access to mapPonAniConfig
639 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530640 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000641 // remove the removeEntry
642 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000643 onuTP.mutexTPState.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000644 return
645 }
mpagenko73143992021-04-09 15:17:10 +0000646 if onuTP.getProfileResetting(uniTPKey) {
647 logger.Debugw(ctx, "aborting GemRemoval on FSM, reset requested in parallel", log.Fields{
648 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
649 //ensure write protection for access to mapPonAniConfig
650 onuTP.mutexTPState.Lock()
651 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
652 // remove the removeEntry
653 delete(onuTP.mapRemoveGemEntry, uniTPKey)
654 onuTP.mutexTPState.Unlock()
655 return
656 }
657 // initiate OMCI GemPort related removal
658 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
659 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000660 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemGemiw, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000661 //even if the FSM invocation did not work we don't indicate a problem within procResult
662 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
663 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
664 return
665 }
666 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000667 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
668 logger.Warnw(ctx, "GemPort removal aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000669 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
670 //even if the FSM delete execution did not work we don't indicate a problem within procResult
671 //we should never respond to delete with error ...
672 //this issue here means that the AniConfigFsm has not finished successfully
673 //which requires to reset it to allow for new usage, e.g. also on a different UNI
674 //(without that it would be reset on device down indication latest)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000675 if _, ok := onuTP.PAniConfigFsm[uniTPKey]; ok {
676 _ = onuTP.PAniConfigFsm[uniTPKey].PAdaptFsm.PFsm.Event(aniEvReset)
mpagenko73143992021-04-09 15:17:10 +0000677 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000678 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
679 return
680 }
681 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000682 //if we can't do the OMCI processing we also suppress the ProcStatusUpdate
683 //this is needed as in the device-down case where all FSM's are getting reset and internal data gets cleared
684 //as a consequence a possible remove-flow does not see any dependency on the TechProfile anymore and is executed (pro forma) directly
685 //a later TechProfile removal would cause the device-reason to be updated to 'techProfile-delete-success' which is not the expected state
686 // and anyway is no real useful information at that stage
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000687 logger.Debugw(ctx, "UniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{
688 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.GetDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000689 }
690 // remove GemPort from config DB
mpagenko73143992021-04-09 15:17:10 +0000691 //ensure write protection for access to mapPonAniConfig
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000692 logger.Debugw(ctx, "UniPonAniConfigFsm removing gem from config data and clearing ani FSM", log.Fields{
Mahir Gunyel9545be22021-07-04 15:53:16 -0700693 "device-id": onuTP.deviceID, "gem-id": onuTP.mapRemoveGemEntry[uniTPKey].removeGemID, "uniTPKey": uniTPKey})
mpagenko73143992021-04-09 15:17:10 +0000694 onuTP.mutexTPState.Lock()
Himani Chawla1c136902020-12-10 16:30:59 +0530695 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000696 // remove the removeEntry
697 delete(onuTP.mapRemoveGemEntry, uniTPKey)
mpagenko73143992021-04-09 15:17:10 +0000698 onuTP.mutexTPState.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000699 } else { //if CResourceTcont == aResource {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000700 logger.Debugw(ctx, "reset TCont with AllocId", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000701 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID})
702
mpagenko73143992021-04-09 15:17:10 +0000703 //ensure read protection for access to mapPonAniConfig
704 onuTP.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000705 // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM
706 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
707 if pLocAniConfigOnUni == nil {
708 // No relevant entry exists anymore - acknowledge success
mpagenko73143992021-04-09 15:17:10 +0000709 onuTP.mutexTPState.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000710 logger.Debugw(ctx, "AniConfig or TCont entry do not exists in DB", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000711 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
712 return
713 }
mpagenko73143992021-04-09 15:17:10 +0000714 onuTP.mutexTPState.RUnlock()
715
mpagenko8b07c1b2020-11-26 10:36:31 +0000716 if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000717 logger.Errorw(ctx, "TCont removal aborted - indicated AllocId not found",
mpagenko8b07c1b2020-11-26 10:36:31 +0000718 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID})
719 /* Do not set some error indication to the outside system interface on delete
720 assume there is nothing to be deleted internally and hope a new config request will recover the situation
721 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s",
722 aEntryID, aUniID, onuTP.deviceID)
723 */
724 return
725 }
726 //T-Cont to be reset found
dbainbri4d3a0dc2020-12-02 00:33:42 +0000727 logger.Debugw(ctx, "Reset-T-Cont AllocId found - valid", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000728 "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000729 if onuTP.PAniConfigFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000730 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available",
mpagenko8b07c1b2020-11-26 10:36:31 +0000731 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
732 /* Do not set some error indication to the outside system interface on delete (see above)
733 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s",
734 aUniID, onuTP.deviceID)
735 */
mpagenko8b07c1b2020-11-26 10:36:31 +0000736 return
737 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000738 if _, ok := onuTP.PAniConfigFsm[uniTPKey]; !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000739 logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available for this uni/tp",
mpagenko8b07c1b2020-11-26 10:36:31 +0000740 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
741 //even if the FSM invocation did not work we don't indicate a problem within procResult
742 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
743 //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data
mpagenko8b07c1b2020-11-26 10:36:31 +0000744 return
745 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000746 if onuTP.baseDeviceHandler.IsReadyForOmciConfig() {
mpagenko8b07c1b2020-11-26 10:36:31 +0000747 // check that the TpConfigRequest was done before
748 // -> that is implicitly done using the AniConfigFsm,
749 // which must be in the according state to remove something
mpagenko73143992021-04-09 15:17:10 +0000750 if onuTP.getProfileResetting(uniTPKey) {
751 logger.Debugw(ctx, "aborting TCont removal on FSM, reset requested in parallel", log.Fields{
752 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
753 return
754 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000755 // initiate OMCI TCont related cleanup
756 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
757 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
dbainbri4d3a0dc2020-12-02 00:33:42 +0000758 if nil != onuTP.runAniConfigFsm(ctx, aniEvRemTcontPath, processingStep, aUniID, aTpID) {
mpagenko8b07c1b2020-11-26 10:36:31 +0000759 //even if the FSM invocation did not work we don't indicate a problem within procResult
760 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
761 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
762 return
763 }
764 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko73143992021-04-09 15:17:10 +0000765 //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset))
766 logger.Warnw(ctx, "TCont cleanup aborted - Omci AniSideConfig failed",
mpagenko8b07c1b2020-11-26 10:36:31 +0000767 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
768 //even if the FSM delete execution did not work we don't indicate a problem within procResult
769 //we should never respond to delete with error ...
770 //this issue here means that the AniConfigFsm has not finished successfully
771 //which requires to reset it to allow for new usage, e.g. also on a different UNI
772 //(without that it would be reset on device down indication latest)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000773 if _, ok := onuTP.PAniConfigFsm[uniTPKey]; ok {
774 _ = onuTP.PAniConfigFsm[uniTPKey].PAdaptFsm.PFsm.Event(aniEvReset)
mpagenko73143992021-04-09 15:17:10 +0000775 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000776 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
777 return
778 }
779 } else {
mpagenko7d6bb022021-03-11 15:07:55 +0000780 //see gemPort comments
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000781 logger.Debugw(ctx, "UniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{
782 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.GetDeviceReasonString()})
mpagenko8b07c1b2020-11-26 10:36:31 +0000783 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000784 }
Mahir Gunyel9545be22021-07-04 15:53:16 -0700785
786}
787
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000788// IsTechProfileConfigCleared - TODO: add comment
789func (onuTP *OnuUniTechProf) IsTechProfileConfigCleared(ctx context.Context, uniID uint8, tpID uint8) bool {
Mahir Gunyel9545be22021-07-04 15:53:16 -0700790 uniTPKey := uniTP{uniID: uniID, tpID: tpID}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000791 logger.Debugw(ctx, "IsTechProfileConfigCleared", log.Fields{"device-id": onuTP.deviceID})
Mahir Gunyel9545be22021-07-04 15:53:16 -0700792 if onuTP.mapPonAniConfig[uniTPKey] != nil {
793 mapGemPortParams := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams
794 unicastGemCount := 0
795 for _, gemEntry := range mapGemPortParams {
796 if !gemEntry.isMulticast {
797 unicastGemCount++
798 }
799 }
800 if unicastGemCount == 0 || onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID == 0 {
801 logger.Debugw(ctx, "clearing-ani-side-config", log.Fields{
802 "device-id": onuTP.deviceID, "uniTpKey": uniTPKey})
803 onuTP.clearAniSideConfig(ctx, uniID, tpID)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000804 if _, ok := onuTP.PAniConfigFsm[uniTPKey]; ok {
805 _ = onuTP.PAniConfigFsm[uniTPKey].PAdaptFsm.PFsm.Event(aniEvReset)
Mahir Gunyel9545be22021-07-04 15:53:16 -0700806 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000807 go onuTP.baseDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OmciAniResourceRemoved)
Mahir Gunyel9545be22021-07-04 15:53:16 -0700808 return true
809 }
mpagenko7d6bb022021-03-11 15:07:55 +0000810 }
Mahir Gunyel9545be22021-07-04 15:53:16 -0700811 return false
mpagenko3dbcdd22020-07-22 07:38:45 +0000812}
813
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000814func (onuTP *OnuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000815 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000816 select {
817 case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000818 logger.Warnw(ctx, "processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000819 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000820 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000821 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000822 if rxStep == aProcessingStep {
823 return true
824 }
825 //all other values are not accepted - including 0 for error indication
dbainbri4d3a0dc2020-12-02 00:33:42 +0000826 logger.Warnw(ctx, "Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000827 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000828 "wantedStep": aProcessingStep, "haveStep": rxStep})
829 return false
830 }
831}
832
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000833// createAniConfigFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000834func (onuTP *OnuUniTechProf) createAniConfigFsm(ctx context.Context, aUniID uint8, aTpID uint8,
835 apCurrentUniPort *cmn.OnuUniPort, devEvent cmn.OnuDeviceEvent, aProcessingStep uint8) error {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530836 logger.Info(ctx, "createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000837 chAniConfigFsm := make(chan cmn.Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800838 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000839 if onuTP.onuDevice == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000840 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000841 return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000842 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000843 pAniCfgFsm := NewUniPonAniConfigFsm(ctx, onuTP.onuDevice.GetDevOmciCC(), apCurrentUniPort, onuTP,
Holger Hildebrandtc408f492022-07-14 08:39:24 +0000844 onuTP.onuDevice.GetOnuDB(), aTpID, onuTP.mapUniTpIndication[uniTPKey].techProfileType, devEvent,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000845 "AniConfigFsm", onuTP.baseDeviceHandler, onuTP.onuDevice, chAniConfigFsm)
mpagenko8b07c1b2020-11-26 10:36:31 +0000846 if pAniCfgFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000847 logger.Errorw(ctx, "AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000848 return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000849 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000850 if onuTP.PAniConfigFsm == nil {
851 onuTP.PAniConfigFsm = make(map[uniTP]*UniPonAniConfigFsm)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800852 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000853 onuTP.PAniConfigFsm[uniTPKey] = pAniCfgFsm
dbainbri4d3a0dc2020-12-02 00:33:42 +0000854 return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000855}
856
mpagenko3dbcdd22020-07-22 07:38:45 +0000857// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000858func (onuTP *OnuUniTechProf) runAniConfigFsm(ctx context.Context, aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000859 /* Uni related ANI config procedure -
860 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
861 */
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530862 logger.Info(ctx, "Run AniConfigFSM with", log.Fields{
863 "ProcessingStep": aProcessingStep, "device-id": onuTP.deviceID, "UniId": aUniID, "TpID": aTpID, "event": aEvent})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800864 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
865
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000866 pACStatemachine := onuTP.PAniConfigFsm[uniTpKey].PAdaptFsm.PFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000867 if pACStatemachine != nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000868 if aEvent == aniEvStart {
869 if !pACStatemachine.Is(aniStDisabled) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000870 logger.Errorw(ctx, "wrong state of AniConfigFSM to start - want: Disabled", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000871 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000872 // maybe try a FSM reset and then again ... - TODO: add comment!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000873 return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000874 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000875 } else if !pACStatemachine.Is(aniStConfigDone) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000876 logger.Errorw(ctx, "wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000877 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000878 return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000879 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000880 //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000881 onuTP.PAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
mpagenko8b07c1b2020-11-26 10:36:31 +0000882 if err := pACStatemachine.Event(aEvent); err != nil {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000883 logger.Errorw(ctx, "AniConfigFSM: can't trigger event", log.Fields{"device-id": onuTP.deviceID, "err": err})
mpagenko8b07c1b2020-11-26 10:36:31 +0000884 return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID)
885 }
886 /***** AniConfigFSM event notified */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000887 logger.Debugw(ctx, "AniConfigFSM event notified", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000888 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent})
889 return nil
mpagenko3dbcdd22020-07-22 07:38:45 +0000890 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000891 logger.Errorw(ctx, "AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000892 // maybe try a FSM reset and then again ... - TODO: add comment!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000893 return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID)
mpagenkoaf801632020-07-03 10:00:42 +0000894}
mpagenkodff5dda2020-08-28 11:52:01 +0000895
Girish Gowdra041dcb32020-11-16 16:54:30 -0800896// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000897func (onuTP *OnuUniTechProf) clearAniSideConfig(ctx context.Context, aUniID uint8, aTpID uint8) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000898 logger.Debugw(ctx, "removing TpIndication and PonAniConfig data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000899 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800900 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
901
902 onuTP.mutexTPState.Lock()
903 defer onuTP.mutexTPState.Unlock()
mpagenko73143992021-04-09 15:17:10 +0000904 //deleting a map entry should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800905 delete(onuTP.mapUniTpIndication, uniTpKey)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800906 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko73143992021-04-09 15:17:10 +0000907 delete(onuTP.procResult, uniTpKey)
908 delete(onuTP.tpProfileExists, uniTpKey)
909 delete(onuTP.tpProfileResetting, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000910}
911
mpagenkodff5dda2020-08-28 11:52:01 +0000912// setConfigDone sets the requested techProfile config state (if possible)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000913func (onuTP *OnuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800914 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
915 onuTP.mutexTPState.Lock()
916 defer onuTP.mutexTPState.Unlock()
917 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
918 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000919 } //else: the state is just ignored (does not exist)
920}
921
922// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000923func (onuTP *OnuUniTechProf) getTechProfileDone(ctx context.Context, aUniID uint8, aTpID uint8) bool {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800924 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000925 onuTP.mutexTPState.RLock()
926 defer onuTP.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800927 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
928 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
929 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000930 logger.Debugw(ctx, "TechProfile not relevant for requested flow config - waiting on delete",
mpagenko2418ab02020-11-12 12:58:06 +0000931 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
932 return false //still waiting for removal of this techProfile first
933 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800934 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000935 }
936 }
937 //for all other constellations indicate false = Config not done
938 return false
939}
mpagenko2418ab02020-11-12 12:58:06 +0000940
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000941// SetProfileToDelete sets the requested techProfile toDelete state (if possible)
942func (onuTP *OnuUniTechProf) SetProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800943 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
944 onuTP.mutexTPState.Lock()
945 defer onuTP.mutexTPState.Unlock()
946 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
947 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000948 } //else: the state is just ignored (does not exist)
949}
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300950
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000951func (onuTP *OnuUniTechProf) getMulticastGemPorts(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300952 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko73143992021-04-09 15:17:10 +0000953 onuTP.mutexTPState.RLock()
954 defer onuTP.mutexTPState.RUnlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300955 gemPortIds := make([]uint16, 0)
956 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
957 for _, gemPortParam := range techProfile.mapGemPortParams {
958 if gemPortParam.isMulticast {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000959 logger.Debugw(ctx, "Detected multicast gemPort", log.Fields{"device-id": onuTP.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300960 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
961 "mcastGemId": gemPortParam.multicastGemPortID})
962 gemPortIds = append(gemPortIds, gemPortParam.multicastGemPortID)
963 }
964 }
965 } //else: the state is just ignored (does not exist)
966 return gemPortIds
967}
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800968
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000969func (onuTP *OnuUniTechProf) getBidirectionalGemPortIDsForTP(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 {
ozgecanetsia82b91a62021-05-21 18:54:49 +0300970 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
971 onuTP.mutexTPState.RLock()
972 defer onuTP.mutexTPState.RUnlock()
973 gemPortIds := make([]uint16, 0)
974 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
975 logger.Debugw(ctx, "TechProfile exist", log.Fields{"device-id": onuTP.deviceID})
976 for _, gemPortParam := range techProfile.mapGemPortParams {
977 if !gemPortParam.isMulticast {
978 logger.Debugw(ctx, "Detected unicast gemPort", log.Fields{"device-id": onuTP.deviceID,
979 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
980 "GemId": gemPortParam.multicastGemPortID})
981 gemPortIds = append(gemPortIds, gemPortParam.gemPortID)
982 }
983 }
984 } else {
985 logger.Debugw(ctx, "TechProfile doesn't exist", log.Fields{"device-id": onuTP.deviceID})
986 } //else: the state is just ignored (does not exist)
987 logger.Debugw(ctx, "Gem PortID list", log.Fields{"device-id": onuTP.deviceID, "gemportList": gemPortIds})
988 return gemPortIds
989}
990
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000991// GetAllBidirectionalGemPortIDsForOnu - TODO: add comment
992func (onuTP *OnuUniTechProf) GetAllBidirectionalGemPortIDsForOnu() []uint16 {
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800993 var gemPortInstIDs []uint16
994 onuTP.mutexTPState.RLock()
995 defer onuTP.mutexTPState.RUnlock()
996 for _, tcontGemList := range onuTP.mapPonAniConfig {
997 for gemPortID, gemPortData := range tcontGemList.mapGemPortParams {
998 if gemPortData != nil && !gemPortData.isMulticast { // only if not multicast gem port
999 gemPortInstIDs = append(gemPortInstIDs, gemPortID)
1000 }
1001 }
1002 }
1003 return gemPortInstIDs
1004}
mpagenko73143992021-04-09 15:17:10 +00001005
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +00001006// GetNumberOfConfiguredUsGemPorts - provides the number of Gem ports for each UNI/TP combination
1007func (onuTP *OnuUniTechProf) GetNumberOfConfiguredUsGemPorts(ctx context.Context) int {
1008 onuTP.mutexTPState.RLock()
1009 defer onuTP.mutexTPState.RUnlock()
1010 usGemPorts := make([]uint16, 0)
1011 for _, tcontGemList := range onuTP.mapPonAniConfig {
1012 for gemPortID, gemPortParams := range tcontGemList.mapGemPortParams {
1013 if gemPortParams.direction == cGemDirBiDirect || gemPortParams.direction == cGemDirUniToAni {
1014 alreadyConfigured := false
1015 for _, foundUsGemPortID := range usGemPorts {
1016 if foundUsGemPortID == gemPortID {
1017 alreadyConfigured = true
1018 break
1019 }
1020 }
1021 if !alreadyConfigured {
1022 usGemPorts = append(usGemPorts, gemPortID)
1023 }
1024 }
1025 }
1026 }
1027 return len(usGemPorts)
1028}
1029
mpagenko73143992021-04-09 15:17:10 +00001030// setProfileResetting sets/resets the indication, that a reset of the TechProfileConfig/Removal is ongoing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001031func (onuTP *OnuUniTechProf) setProfileResetting(ctx context.Context, aUniID uint8, aTpID uint8, aState bool) {
mpagenko73143992021-04-09 15:17:10 +00001032 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
1033 onuTP.mutexTPState.Lock()
1034 defer onuTP.mutexTPState.Unlock()
1035 onuTP.tpProfileResetting[uniTpKey] = aState
1036}
1037
1038// getProfileResetting returns true, if the the according indication for started reset procedure is set
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001039func (onuTP *OnuUniTechProf) getProfileResetting(aUniTpKey uniTP) bool {
mpagenko73143992021-04-09 15:17:10 +00001040 onuTP.mutexTPState.RLock()
1041 defer onuTP.mutexTPState.RUnlock()
1042 if isResetting, exist := onuTP.tpProfileResetting[aUniTpKey]; exist {
1043 return isResetting
1044 }
1045 return false
1046}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001047
1048// PrepareForGarbageCollection - remove references to prepare for garbage collection
1049func (onuTP *OnuUniTechProf) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
1050 logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
1051 onuTP.baseDeviceHandler = nil
1052 onuTP.onuDevice = nil
1053 for k, v := range onuTP.PAniConfigFsm {
1054 v.PrepareForGarbageCollection(ctx, aDeviceID)
1055 delete(onuTP.PAniConfigFsm, k)
1056 }
1057}