blob: 2be93b9513abb31f1568afc62d1053f36ec5bf2e [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
29 "github.com/opencord/voltha-lib-go/v3/pkg/db"
30 "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore"
31 "github.com/opencord/voltha-lib-go/v3/pkg/log"
32 tp "github.com/opencord/voltha-lib-go/v3/pkg/techprofile"
33)
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
mpagenko8b07c1b2020-11-26 10:36:31 +000076 removeIndex 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
mpagenkodff5dda2020-08-28 11:52:01 +0000107 mutexTPState sync.Mutex
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 {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000115 logger.Debugw("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)
127 onuTP.techProfileKVStore = aDeviceHandler.setBackend(baseKvStorePath)
mpagenkoaf801632020-07-03 10:00:42 +0000128 if onuTP.techProfileKVStore == nil {
129 logger.Errorw("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
mpagenkoaf801632020-07-03 10:00:42 +0000163 logger.Debugw("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 {
168 logger.Errorw("error-extracting-tp-id-from-tp-path", log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
169 return
170 }
mpagenkoaf801632020-07-03 10:00:42 +0000171 if onuTP.techProfileKVStore == nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000172 logger.Errorw("techProfileKVStore not set - abort",
173 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 {
188 logger.Errorw("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 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000223 logger.Errorw("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 {
238 logger.Errorw("tech-profile related FSM could not be started",
239 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
mpagenko8b07c1b2020-11-26 10:36:31 +0000245 logger.Errorw("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)
mpagenko8b07c1b2020-11-26 10:36:31 +0000258 logger.Errorw("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 {
mpagenko8b07c1b2020-11-26 10:36:31 +0000266 logger.Errorw("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 {
289 logger.Errorw("invalid path name format",
290 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 {
mpagenko3dbcdd22020-07-22 07:38:45 +0000302 logger.Warnw("Some active profile entry at reading new TechProfile",
303 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
308 logger.Warnw("New TechProfile already exists - aborting configuration",
309 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
mpagenko3dbcdd22020-07-22 07:38:45 +0000327 logger.Debugw("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 {
335 logger.Debugw("tech-profile read",
336 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 {
340 logger.Errorw("TechProf - Failed to unmarshal tech-profile into tpInst",
341 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 }
345 logger.Debugw("TechProf - tpInst", log.Fields{"tpInst": tpInst})
346 // access examples
347 logger.Debugw("TechProf content", log.Fields{"Name": tpInst.Name,
348 "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize,
349 "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
350 } else {
351 logger.Errorw("No tech-profile found",
352 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 {
357 logger.Errorw("kvstore-get failed for path",
358 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)
365 localMapGemPortParams[0] = &gemPortParamStruct{}
Girish Gowdra041dcb32020-11-16 16:54:30 -0800366 onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
mpagenko3dbcdd22020-07-22 07:38:45 +0000367
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000368 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000369 //get the relevant values from the profile and store to mapPonAniConfig
Girish Gowdra041dcb32020-11-16 16:54:30 -0800370 onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID)
Himani Chawla4d908332020-08-31 12:30:20 +0530371 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000372 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
373 if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800374 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
mpagenko3dbcdd22020-07-22 07:38:45 +0000375 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000376 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
Girish Gowdra041dcb32020-11-16 16:54:30 -0800377 onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR
mpagenko3dbcdd22020-07-22 07:38:45 +0000378 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000379 loNumGemPorts := tpInst.NumGemPorts
380 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000381 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000382 if uint32(pos) == loNumGemPorts {
383 logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
384 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000385 break
386 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000387 if pos == 0 {
388 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
389 loGemPortRead = true
390 } else {
391 //for all further GemPorts we need to extend the mapGemPortParams
ozgecanetsia4b232302020-11-11 10:58:10 +0300392 //FIXME one can use uint16(content.GemportID) as key to the map
393 // see jira https://jira.opencord.org/browse/VOL-3667
Girish Gowdra041dcb32020-11-16 16:54:30 -0800394 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)] = &gemPortParamStruct{}
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000395 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800396 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortID =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000397 uint16(content.GemportID)
398 //direction can be correlated later with Downstream list,
399 // for now just assume bidirectional (upstream never exists alone)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800400 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000401 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
ozgecanetsia4b232302020-11-11 10:58:10 +0300402 if content.PriorityQueue > 7 {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000403 logger.Errorw("PonAniConfig reject on GemPortList - PrioQueue value invalid",
404 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue})
405 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800406 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000407 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000408 return
409 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800410 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].prioQueueIndex =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000411 uint8(content.PriorityQueue)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800412 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530413 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000414 if content.AesEncryption == "True" {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800415 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortEncState = 1
mpagenko3dbcdd22020-07-22 07:38:45 +0000416 } else {
Girish Gowdra041dcb32020-11-16 16:54:30 -0800417 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortEncState = 0
mpagenko3dbcdd22020-07-22 07:38:45 +0000418 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800419 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].discardPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000420 content.DiscardPolicy
Girish Gowdra041dcb32020-11-16 16:54:30 -0800421 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].queueSchedPolicy =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000422 content.SchedulingPolicy
mpagenko3dbcdd22020-07-22 07:38:45 +0000423 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Girish Gowdra041dcb32020-11-16 16:54:30 -0800424 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].queueWeight =
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000425 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000426 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300427
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300428 for _, downstreamContent := range tpInst.DownstreamGemPortAttributeList {
429 log.Debugw("Operating on Downstream Gem Port", log.Fields{"downstream-gem": downstreamContent})
430 //Commenting this out due to faliure, needs investigation
431 //if uint32(pos) == loNumGemPorts {
432 // logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
433 // log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
434 // break
435 //}
436 isMulticast := false
ozgecanetsia4b232302020-11-11 10:58:10 +0300437 //Flag is defined as string in the TP in voltha-lib-go, parsing it from string
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300438 if downstreamContent.IsMulticast != "" {
439 isMulticast, err = strconv.ParseBool(downstreamContent.IsMulticast)
440 if err != nil {
441 logger.Errorw("multicast-error-config-unknown-flag-in-technology-profile",
442 log.Fields{"UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "error": err})
443 continue
444 }
ozgecanetsia4b232302020-11-11 10:58:10 +0300445 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300446 log.Infow("Gem Port is multicast", log.Fields{"isMulticast": isMulticast})
ozgecanetsia4b232302020-11-11 10:58:10 +0300447 if isMulticast {
448 mcastGemID := uint16(downstreamContent.McastGemID)
449 _, existing := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID]
450 if existing {
451 //GEM port was previously configured, avoid setting multicast attributes
452 logger.Errorw("multicast-error-config-existing-gem-port-config", log.Fields{"UniTpKey": uniTPKey,
453 "downstream-gem": downstreamContent, "key": mcastGemID})
454 continue
455 } else {
456 //GEM port is not configured, setting multicast attributes
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300457 logger.Infow("creating-multicast-gem-port", log.Fields{"uniTpKey": uniTPKey,
ozgecanetsia4b232302020-11-11 10:58:10 +0300458 "gemPortId": mcastGemID, "key": mcastGemID})
459
460 //for all further GemPorts we need to extend the mapGemPortParams
461 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID] = &gemPortParamStruct{}
462
463 //Separate McastGemId is derived from OMCI-lib-go, if not needed first needs to be removed there.
464 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortID = mcastGemID
465 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].direction = 2 // for ANI to UNI as defined in G.988
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300466
467 if downstreamContent.AesEncryption == "True" {
468 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 1
469 } else {
470 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 0
471 }
472
473 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
ozgecanetsia4b232302020-11-11 10:58:10 +0300474 if downstreamContent.PriorityQueue > 7 {
475 logger.Errorw("PonAniConfig reject on GemPortList - PrioQueue value invalid",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300476 log.Fields{"device-id": onuTP.deviceID, "index": mcastGemID, "PrioQueue": downstreamContent.PriorityQueue})
477 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
478 delete(onuTP.mapPonAniConfig, uniTPKey)
479 onuTP.chTpConfigProcessingStep <- 0 //error indication
480 return
ozgecanetsia4b232302020-11-11 10:58:10 +0300481 }
482 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].prioQueueIndex =
483 uint8(downstreamContent.PriorityQueue)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300484 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].pbitString =
485 strings.TrimPrefix(downstreamContent.PbitMap, binaryStringPrefix)
486
487 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].discardPolicy =
488 downstreamContent.DiscardPolicy
489 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueSchedPolicy =
490 downstreamContent.SchedulingPolicy
491 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
492 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueWeight =
493 uint8(downstreamContent.Weight)
494
ozgecanetsia4b232302020-11-11 10:58:10 +0300495 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].isMulticast = isMulticast
496 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].multicastGemPortID =
497 uint16(downstreamContent.McastGemID)
498 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].staticACL = downstreamContent.SControlList
499 onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].dynamicACL = downstreamContent.DControlList
500 }
501 }
502 }
503
Himani Chawla4d908332020-08-31 12:30:20 +0530504 if !loGemPortRead {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000505 logger.Errorw("PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000506 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000507 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800508 delete(onuTP.mapPonAniConfig, uniTPKey)
mpagenkodff5dda2020-08-28 11:52:01 +0000509 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000510 return
511 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000512 //logger does not simply output the given structures, just give some example debug values
513 logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +0000514 "device-id": onuTP.deviceID, "uni-id": aUniID,
515 "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800516 for gemIndex, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000517 logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
518 "GemIndex": gemIndex,
519 "GemPort": gemEntry.gemPortID,
520 "QueueScheduling": gemEntry.queueSchedPolicy})
521 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000522
mpagenkodff5dda2020-08-28 11:52:01 +0000523 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000524}
525
Himani Chawla6d2ae152020-09-02 13:11:20 +0530526func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
mpagenko8b07c1b2020-11-26 10:36:31 +0000527 ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000528
529 //OMCI transfer of ANI data acc. to mapPonAniConfig
530 // also the FSM's are running in background,
mpagenko8b07c1b2020-11-26 10:36:31 +0000531 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
Girish Gowdra041dcb32020-11-16 16:54:30 -0800532 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
mpagenko3dbcdd22020-07-22 07:38:45 +0000533 if onuTP.pAniConfigFsm == nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000534 return onuTP.createAniConfigFsm(aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800535 } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
mpagenko8b07c1b2020-11-26 10:36:31 +0000536 return onuTP.createAniConfigFsm(aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
mpagenko3dbcdd22020-07-22 07:38:45 +0000537 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000538 //AniConfigFsm already init
539 return onuTP.runAniConfigFsm(aniEvStart, aProcessingStep, aUniID, aTpID)
540}
541
542// deleteTpResource removes Resources from the ONU's specified Uni
543func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context,
544 aUniID uint8, aTpID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
545 wg *sync.WaitGroup) {
546 defer wg.Done()
547 logger.Debugw("will remove TP resources from ONU's UNI", log.Fields{
548 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "Resource": aResource})
549 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
550
551 if cResourceGemPort == aResource {
552 logger.Debugw("remove GemPort from the list of existing ones of the TP", log.Fields{
553 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID})
554
555 // check if the requested GemPort exists in the DB, indicate it to the FSM
556 // store locally to remove it from DB later on success
557 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
558 if pLocAniConfigOnUni == nil {
559 // No relevant entry exists anymore - acknowledge success
560 logger.Debugw("AniConfig or GemEntry do not exists in DB", log.Fields{
561 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
562 return
563 }
564 for gemIndex, gemEntry := range pLocAniConfigOnUni.mapGemPortParams {
565 if gemEntry.gemPortID == uint16(aEntryID) {
566 //GemEntry to be deleted found
567 gemEntry.removeIndex = gemIndex //store the index for later removal
568 onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemIndex]
569 logger.Debugw("Remove-GemEntry stored", log.Fields{
570 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemIndex": gemIndex})
571 break //abort loop, always only one GemPort to remove
572 }
573 }
574 if onuTP.mapRemoveGemEntry[uniTPKey] == nil {
575 logger.Errorw("GemPort removal aborted - GemPort not found",
576 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID})
577 /* Do not set some error indication to the outside system interface on delete
578 assume there is nothing to be deleted internally and hope a new config request will recover the situation
579 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s",
580 aEntryID, aUniID, onuTP.deviceID)
581 */
582 return
583 }
584 if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig {
585 // check that the TpConfigRequest was done before
586 // -> that is implicitly done using the AniConfigFsm,
587 // which must be in the according state to remove something
588 // initiate OMCI GemPort related removal
589 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
590 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
591 if onuTP.pAniConfigFsm == nil {
592 logger.Errorw("abort GemPort removal - no AniConfigFsm available",
593 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
594 /* Do not set some error indication to the outside system interface on delete (see above)
595 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s",
596 aUniID, onuTP.deviceID)
597 */
598 //if the FSM is not valid, also TP related remove data should not be valid:
599 // remove GemPort from config DB
600 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeIndex)
601 // remove the removeEntry
602 delete(onuTP.mapRemoveGemEntry, uniTPKey)
603 return
604 }
605 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
606 logger.Errorw("abort GemPort removal - no AniConfigFsm available for this uni/tp",
607 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
608 /* Do not set some error indication to the outside system interface on delete (see above)
609 onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid",
610 aUniID, onuTP.deviceID, aTpID)
611 */
612 //if the FSM is not valid, also TP related remove data should not be valid:
613 // remove GemPort from config DB
614 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeIndex)
615 // remove the removeEntry
616 delete(onuTP.mapRemoveGemEntry, uniTPKey)
617 return
618 }
619 if nil != onuTP.runAniConfigFsm(aniEvRemGemiw, processingStep, aUniID, aTpID) {
620 //even if the FSM invocation did not work we don't indicate a problem within procResult
621 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
622 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
623 return
624 }
625 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
626 //timeout or error detected
627 logger.Errorw("GemPort removal aborted - Omci AniSideConfig failed",
628 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
629 //even if the FSM delete execution did not work we don't indicate a problem within procResult
630 //we should never respond to delete with error ...
631 //this issue here means that the AniConfigFsm has not finished successfully
632 //which requires to reset it to allow for new usage, e.g. also on a different UNI
633 //(without that it would be reset on device down indication latest)
634 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
635 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
636 return
637 }
638 } else {
639 logger.Debugw("uniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{
640 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.deviceReason})
641 }
642 // remove GemPort from config DB
643 delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeIndex)
644 // remove the removeEntry
645 delete(onuTP.mapRemoveGemEntry, uniTPKey)
646 // deviceHandler StatusEvent (reason update) (see end of function) is only generated in case some element really was removed
647 } else { //if cResourceTcont == aResource {
648 logger.Debugw("reset TCont with AllocId", log.Fields{
649 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID})
650
651 // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM
652 pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey]
653 if pLocAniConfigOnUni == nil {
654 // No relevant entry exists anymore - acknowledge success
655 logger.Debugw("AniConfig or TCont entry do not exists in DB", log.Fields{
656 "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
657 return
658 }
659 if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) {
660 logger.Errorw("TCont removal aborted - indicated AllocId not found",
661 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID})
662 /* Do not set some error indication to the outside system interface on delete
663 assume there is nothing to be deleted internally and hope a new config request will recover the situation
664 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s",
665 aEntryID, aUniID, onuTP.deviceID)
666 */
667 return
668 }
669 //T-Cont to be reset found
670 logger.Debugw("Reset-T-Cont AllocId found - valid", log.Fields{
671 "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID})
672 if onuTP.pAniConfigFsm == nil {
673 logger.Errorw("no TCont removal on OMCI - no AniConfigFsm available",
674 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
675 /* Do not set some error indication to the outside system interface on delete (see above)
676 onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s",
677 aUniID, onuTP.deviceID)
678 */
679 //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data
680 onuTP.clearAniSideConfig(aUniID, aTpID)
681 return
682 }
683 if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok {
684 logger.Errorw("no TCont removal on OMCI - no AniConfigFsm available for this uni/tp",
685 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID})
686 //even if the FSM invocation did not work we don't indicate a problem within procResult
687 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
688 //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data
689 onuTP.clearAniSideConfig(aUniID, aTpID)
690 return
691 }
692 if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig {
693 // check that the TpConfigRequest was done before
694 // -> that is implicitly done using the AniConfigFsm,
695 // which must be in the according state to remove something
696 // initiate OMCI TCont related cleanup
697 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
698 // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep
699 if nil != onuTP.runAniConfigFsm(aniEvRemTcontPath, processingStep, aUniID, aTpID) {
700 //even if the FSM invocation did not work we don't indicate a problem within procResult
701 //errors could exist also because there was nothing to delete - so we just accept that as 'deleted'
702 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
703 return
704 }
705 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
706 //timeout or error detected
707 logger.Errorw("TCont cleanup aborted - Omci AniSideConfig failed",
708 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
709 //even if the FSM delete execution did not work we don't indicate a problem within procResult
710 //we should never respond to delete with error ...
711 //this issue here means that the AniConfigFsm has not finished successfully
712 //which requires to reset it to allow for new usage, e.g. also on a different UNI
713 //(without that it would be reset on device down indication latest)
714 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
715 //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented)
716 return
717 }
718 } else {
719 logger.Debugw("uniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{
720 "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.deviceReason})
721 }
722 //clear the internal store profile data
723 onuTP.clearAniSideConfig(aUniID, aTpID)
724 // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created
725 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
726 _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset)
727 }
728 // generate deviceHandler StatusEvent in case the FSM was not invoked
729 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(OmciAniResourceRemoved)
mpagenko3dbcdd22020-07-22 07:38:45 +0000730}
731
Himani Chawla6d2ae152020-09-02 13:11:20 +0530732func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000733 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000734 select {
735 case <-ctx.Done():
736 logger.Warnw("processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000737 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000738 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000739 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000740 if rxStep == aProcessingStep {
741 return true
742 }
743 //all other values are not accepted - including 0 for error indication
744 logger.Warnw("Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000745 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000746 "wantedStep": aProcessingStep, "haveStep": rxStep})
747 return false
748 }
749}
750
Himani Chawla4d908332020-08-31 12:30:20 +0530751// createUniLockFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Girish Gowdra041dcb32020-11-16 16:54:30 -0800752func (onuTP *onuUniTechProf) createAniConfigFsm(aUniID uint8, aTpID uint8,
mpagenko8b07c1b2020-11-26 10:36:31 +0000753 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) error {
divyadesai4d299552020-08-18 07:13:49 +0000754 logger.Debugw("createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000755 chAniConfigFsm := make(chan Message, 2048)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800756 uniTPKey := uniTP{uniID: aUniID, tpID: aTpID}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530757 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000758 if pDevEntry == nil {
divyadesai4d299552020-08-18 07:13:49 +0000759 logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000760 return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000761 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530762 pAniCfgFsm := newUniPonAniConfigFsm(pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
Girish Gowdra041dcb32020-11-16 16:54:30 -0800763 pDevEntry.pOnuDB, aTpID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000764 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko8b07c1b2020-11-26 10:36:31 +0000765 if pAniCfgFsm == nil {
divyadesai4d299552020-08-18 07:13:49 +0000766 logger.Errorw("AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000767 return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000768 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000769 if onuTP.pAniConfigFsm == nil {
770 onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800771 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000772 onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm
773 return onuTP.runAniConfigFsm(aniEvStart, aProcessingStep, aUniID, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000774}
775
mpagenko3dbcdd22020-07-22 07:38:45 +0000776// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
mpagenko8b07c1b2020-11-26 10:36:31 +0000777func (onuTP *onuUniTechProf) runAniConfigFsm(aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000778 /* Uni related ANI config procedure -
779 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
780 */
Girish Gowdra041dcb32020-11-16 16:54:30 -0800781 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
782
783 pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000784 if pACStatemachine != nil {
mpagenko8b07c1b2020-11-26 10:36:31 +0000785 if aEvent == aniEvStart {
786 if !pACStatemachine.Is(aniStDisabled) {
787 logger.Errorw("wrong state of AniConfigFSM to start - want: Disabled", log.Fields{
788 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000789 // maybe try a FSM reset and then again ... - TODO!!!
mpagenko8b07c1b2020-11-26 10:36:31 +0000790 return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000791 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000792 } else if !pACStatemachine.Is(aniStConfigDone) {
793 logger.Errorw("wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000794 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000795 return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000796 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000797 //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config)
798 onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
799 if err := pACStatemachine.Event(aEvent); err != nil {
800 logger.Errorw("AniConfigFSM: can't trigger event", log.Fields{"err": err})
801 return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID)
802 }
803 /***** AniConfigFSM event notified */
804 logger.Debugw("AniConfigFSM event notified", log.Fields{
805 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent})
806 return nil
mpagenko3dbcdd22020-07-22 07:38:45 +0000807 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000808 logger.Errorw("AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
809 // maybe try a FSM reset and then again ... - TODO!!!
810 return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID)
mpagenkoaf801632020-07-03 10:00:42 +0000811}
mpagenkodff5dda2020-08-28 11:52:01 +0000812
Girish Gowdra041dcb32020-11-16 16:54:30 -0800813// clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID
814func (onuTP *onuUniTechProf) clearAniSideConfig(aUniID uint8, aTpID uint8) {
mpagenko01e726e2020-10-23 09:45:29 +0000815 logger.Debugw("removing TpIndication and PonAniConfig data", log.Fields{
816 "device-id": onuTP.deviceID, "uni-id": aUniID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800817 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
818
819 onuTP.mutexTPState.Lock()
820 defer onuTP.mutexTPState.Unlock()
821 delete(onuTP.mapUniTpIndication, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000822 //delete on the PonAniConfig map of this UNI should be safe, even if not existing
Girish Gowdra041dcb32020-11-16 16:54:30 -0800823 delete(onuTP.mapPonAniConfig, uniTpKey)
mpagenko01e726e2020-10-23 09:45:29 +0000824}
825
mpagenkodff5dda2020-08-28 11:52:01 +0000826// setConfigDone sets the requested techProfile config state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800827func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) {
828 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
829 onuTP.mutexTPState.Lock()
830 defer onuTP.mutexTPState.Unlock()
831 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
832 onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState
mpagenkodff5dda2020-08-28 11:52:01 +0000833 } //else: the state is just ignored (does not exist)
834}
835
836// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
Girish Gowdra041dcb32020-11-16 16:54:30 -0800837func (onuTP *onuUniTechProf) getTechProfileDone(aUniID uint8, aTpID uint8) bool {
838 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
839 onuTP.mutexTPState.Lock()
840 defer onuTP.mutexTPState.Unlock()
841 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
842 if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID {
843 if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete {
mpagenko2418ab02020-11-12 12:58:06 +0000844 logger.Debugw("TechProfile not relevant for requested flow config - waiting on delete",
845 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
846 return false //still waiting for removal of this techProfile first
847 }
Girish Gowdra041dcb32020-11-16 16:54:30 -0800848 return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone
mpagenkodff5dda2020-08-28 11:52:01 +0000849 }
850 }
851 //for all other constellations indicate false = Config not done
852 return false
853}
mpagenko2418ab02020-11-12 12:58:06 +0000854
855// setProfileToDelete sets the requested techProfile toDelete state (if possible)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800856func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) {
857 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
858 onuTP.mutexTPState.Lock()
859 defer onuTP.mutexTPState.Unlock()
860 if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP {
861 onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState
mpagenko2418ab02020-11-12 12:58:06 +0000862 } //else: the state is just ignored (does not exist)
863}
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300864
865// setProfileToDelete sets the requested techProfile toDelete state (if possible)
866func (onuTP *onuUniTechProf) getMulticastGemPorts(aUniID uint8, aTpID uint8) []uint16 {
867 uniTpKey := uniTP{uniID: aUniID, tpID: aTpID}
868 onuTP.mutexTPState.Lock()
869 defer onuTP.mutexTPState.Unlock()
870 gemPortIds := make([]uint16, 0)
871 if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP {
872 for _, gemPortParam := range techProfile.mapGemPortParams {
873 if gemPortParam.isMulticast {
874 log.Debugw("Detected multicast gemPort", log.Fields{"device-id": onuTP.deviceID,
875 "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey,
876 "mcastGemId": gemPortParam.multicastGemPortID})
877 gemPortIds = append(gemPortIds, gemPortParam.multicastGemPortID)
878 }
879 }
880 } //else: the state is just ignored (does not exist)
881 return gemPortIds
882}