blob: 2e19274e42df19c633d3cdcc242cd7ab56d4e68b [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"
mpagenko3dbcdd22020-07-22 07:38:45 +000025 "strconv"
26 "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
35const cBasePathTechProfileKVStore = "service/voltha/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
55 techProfileID uint16
56 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
76}
77
78//refers to one tcont and its properties and all assigned GemPorts and their properties
79type tcontGemList struct {
80 tcontParams tcontParamStruct
81 mapGemPortParams map[uint16]*gemPortParamStruct
82}
83
84//refers to all tcont and their Tcont/GemPort Parameters
85type tMapPonAniConfig map[uint16]*tcontGemList
86
Himani Chawla6d2ae152020-09-02 13:11:20 +053087//onuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU
88type onuUniTechProf struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053089 baseDeviceHandler *deviceHandler
mpagenko01e726e2020-10-23 09:45:29 +000090 deviceID string
mpagenkodff5dda2020-08-28 11:52:01 +000091 tpProcMutex sync.RWMutex
mpagenkodff5dda2020-08-28 11:52:01 +000092 techProfileKVStore *db.Backend
mpagenkodff5dda2020-08-28 11:52:01 +000093 chTpConfigProcessingStep chan uint8
mpagenkodff5dda2020-08-28 11:52:01 +000094 mapUniTpIndication map[uint8]*tTechProfileIndication //use pointer values to ease assignments to the map
95 mapPonAniConfig map[uint8]*tMapPonAniConfig //per UNI: use pointer values to ease assignments to the map
Himani Chawla6d2ae152020-09-02 13:11:20 +053096 pAniConfigFsm *uniPonAniConfigFsm
mpagenkodff5dda2020-08-28 11:52:01 +000097 procResult error //error indication of processing
98 mutexTPState sync.Mutex
mpagenko01e726e2020-10-23 09:45:29 +000099 tpProfileExists bool
mpagenkoaf801632020-07-03 10:00:42 +0000100}
101
Himani Chawla6d2ae152020-09-02 13:11:20 +0530102//newOnuUniTechProf returns the instance of a OnuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000103//(one instance per ONU/deviceHandler for all possible UNI's)
mpagenko01e726e2020-10-23 09:45:29 +0000104func newOnuUniTechProf(ctx context.Context, aDeviceHandler *deviceHandler) *onuUniTechProf {
105 logger.Infow("init-OnuUniTechProf", log.Fields{"device-id": aDeviceHandler.deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530106 var onuTP onuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000107 onuTP.baseDeviceHandler = aDeviceHandler
mpagenko01e726e2020-10-23 09:45:29 +0000108 onuTP.deviceID = aDeviceHandler.deviceID
mpagenkoaf801632020-07-03 10:00:42 +0000109 onuTP.tpProcMutex = sync.RWMutex{}
mpagenkodff5dda2020-08-28 11:52:01 +0000110 onuTP.chTpConfigProcessingStep = make(chan uint8)
mpagenkodff5dda2020-08-28 11:52:01 +0000111 onuTP.mapUniTpIndication = make(map[uint8]*tTechProfileIndication)
112 onuTP.mapPonAniConfig = make(map[uint8]*tMapPonAniConfig)
mpagenko1cc3cb42020-07-27 15:24:38 +0000113 onuTP.procResult = nil //default assumption processing done with success
mpagenkoaf801632020-07-03 10:00:42 +0000114
Himani Chawla6d2ae152020-09-02 13:11:20 +0530115 onuTP.techProfileKVStore = aDeviceHandler.setBackend(cBasePathTechProfileKVStore)
mpagenkoaf801632020-07-03 10:00:42 +0000116 if onuTP.techProfileKVStore == nil {
117 logger.Errorw("Can't access techProfileKVStore - no backend connection to service",
mpagenko01e726e2020-10-23 09:45:29 +0000118 log.Fields{"device-id": aDeviceHandler.deviceID, "service": cBasePathTechProfileKVStore})
mpagenkoaf801632020-07-03 10:00:42 +0000119 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000120
mpagenkoaf801632020-07-03 10:00:42 +0000121 return &onuTP
122}
123
124// lockTpProcMutex locks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530125func (onuTP *onuUniTechProf) lockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000126 onuTP.tpProcMutex.Lock()
127}
128
129// unlockTpProcMutex unlocks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530130func (onuTP *onuUniTechProf) unlockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000131 onuTP.tpProcMutex.Unlock()
132}
133
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000134// resetTpProcessingErrorIndication resets the internal error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000135// need to be called before evaluation of any subsequent processing (given by waitForTpCompletion())
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000136func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication() {
mpagenko1cc3cb42020-07-27 15:24:38 +0000137 onuTP.procResult = nil
138}
139
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000140func (onuTP *onuUniTechProf) getTpProcessingErrorIndication() error {
mpagenko1cc3cb42020-07-27 15:24:38 +0000141 return onuTP.procResult
mpagenko3dbcdd22020-07-22 07:38:45 +0000142}
143
144// configureUniTp checks existing tp resources to delete and starts the corresponding OMCI configuation of the UNI port
145// all possibly blocking processing must be run in background to allow for deadline supervision!
146// but take care on sequential background processing when needed (logical dependencies)
Himani Chawla4d908332020-08-31 12:30:20 +0530147// use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization
Himani Chawla6d2ae152020-09-02 13:11:20 +0530148func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context,
mpagenkodff5dda2020-08-28 11:52:01 +0000149 aUniID uint8, aPathString string, wg *sync.WaitGroup) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000150 defer wg.Done() //always decrement the waitGroup on return
mpagenkoaf801632020-07-03 10:00:42 +0000151 logger.Debugw("configure the Uni according to TpPath", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000152 "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString})
mpagenkoaf801632020-07-03 10:00:42 +0000153
mpagenkoaf801632020-07-03 10:00:42 +0000154 if onuTP.techProfileKVStore == nil {
155 logger.Debug("techProfileKVStore not set - abort")
Himani Chawla26e555c2020-08-31 12:30:20 +0530156 onuTP.procResult = errors.New("techProfile config aborted: techProfileKVStore not set")
mpagenkoaf801632020-07-03 10:00:42 +0000157 return
158 }
159
mpagenko3dbcdd22020-07-22 07:38:45 +0000160 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530161 var pCurrentUniPort *onuUniPort
mpagenko3dbcdd22020-07-22 07:38:45 +0000162 for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap {
163 // only if this port is validated for operState transfer
Himani Chawla26e555c2020-08-31 12:30:20 +0530164 if uniPort.uniID == uint8(aUniID) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000165 pCurrentUniPort = uniPort
166 break //found - end search loop
167 }
168 }
169 if pCurrentUniPort == nil {
170 logger.Errorw("TechProfile configuration aborted: requested uniID not found in PortDB",
mpagenko01e726e2020-10-23 09:45:29 +0000171 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200172 onuTP.procResult = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s",
173 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000174 return
175 }
mpagenkoaf801632020-07-03 10:00:42 +0000176
mpagenkodff5dda2020-08-28 11:52:01 +0000177 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
mpagenkoaf801632020-07-03 10:00:42 +0000178
mpagenko3dbcdd22020-07-22 07:38:45 +0000179 //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called
180 // in case the KVPath has changed for the given UNI,
181 // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
182 // (ANI) configuration of this port has to be removed first
183 // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
184 // existence of configuration can be detected based on tp stored TCONT's
Andrea Campanella6515c582020-10-05 11:25:00 +0200185 //TODO:
mpagenko3dbcdd22020-07-22 07:38:45 +0000186 /* if tcontMap not empty {
187 go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000188 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000189 //timeout or error detected
190 return
191 }
192 clear tcontMap
193 }
194
195 processingStep++
196 */
197 go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, aPathString, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000198 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000199 //timeout or error detected
mpagenko01e726e2020-10-23 09:45:29 +0000200 if onuTP.tpProfileExists {
201 //ignore the internal error in case the new profile is already configured
202 // and abort the processing here
203 return
204 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000205 logger.Debugw("tech-profile related configuration aborted on read",
mpagenko01e726e2020-10-23 09:45:29 +0000206 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200207 onuTP.procResult = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s",
208 aUniID, onuTP.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +0000209 return
210 }
211
212 processingStep++
213 if valuePA, existPA := onuTP.mapPonAniConfig[aUniID]; existPA {
214 if _, existTG := (*valuePA)[0]; existTG {
215 //Config data for this uni and and at least TCont Index 0 exist
216 go onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, pCurrentUniPort, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000217 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000218 //timeout or error detected
219 logger.Debugw("tech-profile related configuration aborted on set",
mpagenko01e726e2020-10-23 09:45:29 +0000220 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200221 onuTP.procResult = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s",
222 aUniID, onuTP.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530223 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000224 //which requires to reset it to allow for new usage, e.g. also on a different UNI
225 //(without that it would be reset on device down indication latest)
Himani Chawla4d908332020-08-31 12:30:20 +0530226 _ = onuTP.pAniConfigFsm.pAdaptFsm.pFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +0000227 return
mpagenkoaf801632020-07-03 10:00:42 +0000228 }
229 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000230 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
231 logger.Debugw("no Tcont/Gem data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000232 "device-id": onuTP.deviceID, "uni-id": aUniID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200233 onuTP.procResult = fmt.Errorf("techProfile config aborted: no Tcont/Gem data found for this UNI %d on %s",
234 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000235 return
mpagenkoaf801632020-07-03 10:00:42 +0000236 }
237 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000238 logger.Debugw("no PonAni data for this UNI found - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000239 "device-id": onuTP.deviceID, "uni-id": aUniID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200240 onuTP.procResult = fmt.Errorf("techProfile config aborted: no AniSide data found for this UNI %d on %s",
241 aUniID, onuTP.deviceID)
mpagenko1cc3cb42020-07-27 15:24:38 +0000242 return
mpagenkoaf801632020-07-03 10:00:42 +0000243 }
244}
245
mpagenko3dbcdd22020-07-22 07:38:45 +0000246/* internal methods *********************/
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000247
Himani Chawla6d2ae152020-09-02 13:11:20 +0530248func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile(
mpagenkodff5dda2020-08-28 11:52:01 +0000249 ctx context.Context, aUniID uint8, aPathString string, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000250 var tpInst tp.TechProfile
251
mpagenko01e726e2020-10-23 09:45:29 +0000252 onuTP.tpProfileExists = false
mpagenko3dbcdd22020-07-22 07:38:45 +0000253 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
254 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
255 subStringSlice := strings.Split(aPathString, "/")
256 if len(subStringSlice) <= 2 {
257 logger.Errorw("invalid path name format",
258 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000259 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000260 return
261 }
mpagenko01e726e2020-10-23 09:45:29 +0000262 profID, err := strconv.ParseUint(subStringSlice[1], 10, 32)
263 if err != nil {
264 logger.Errorw("invalid ProfileId from path",
265 log.Fields{"ParseErr": err})
266 onuTP.chTpConfigProcessingStep <- 0 //error indication
267 return
268 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000269
mpagenko3dbcdd22020-07-22 07:38:45 +0000270 //at this point it is assumed that a new TechProfile is assigned to the UNI
mpagenko01e726e2020-10-23 09:45:29 +0000271 //expectation is that no TPIndication entry exists here, if exists and with the same TPId
272 // then we throw a warning, set an internal error and abort with error,
273 // which is later re-defined to success response to OLT adapter
274 // if TPId has changed, current data is removed (note that the ONU config state may be
275 // ambivalent in such a case)
mpagenko3dbcdd22020-07-22 07:38:45 +0000276 if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP {
277 logger.Warnw("Some active profile entry at reading new TechProfile",
278 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
mpagenko01e726e2020-10-23 09:45:29 +0000279 "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[aUniID].techProfileID})
280 if uint16(profID) == onuTP.mapUniTpIndication[aUniID].techProfileID {
281 // ProfId not changed - assume profile to be still the same
282 // anyway this should not appear after full support of profile (Gem/TCont) removal
283 logger.Warnw("New TechProfile already exists - aborting configuration",
284 log.Fields{"device-id": onuTP.deviceID})
285 onuTP.tpProfileExists = true
286 onuTP.chTpConfigProcessingStep <- 0 //error indication
287 return
288 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000289 //delete on the mapUniTpIndication map not needed, just overwritten later
290 //delete on the PonAniConfig map should be safe, even if not existing
291 delete(onuTP.mapPonAniConfig, aUniID)
292 } else {
293 // this is normal processing
294 onuTP.mapUniTpIndication[aUniID] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
295 }
296
297 onuTP.mapUniTpIndication[aUniID].techProfileType = subStringSlice[0]
mpagenko3dbcdd22020-07-22 07:38:45 +0000298 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
299 onuTP.mapUniTpIndication[aUniID].techProfileID = uint16(profID)
mpagenko01e726e2020-10-23 09:45:29 +0000300 onuTP.mapUniTpIndication[aUniID].techProfileConfigDone = false
mpagenko2418ab02020-11-12 12:58:06 +0000301 onuTP.mapUniTpIndication[aUniID].techProfileToDelete = false
mpagenko3dbcdd22020-07-22 07:38:45 +0000302 logger.Debugw("tech-profile path indications",
mpagenko01e726e2020-10-23 09:45:29 +0000303 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000304 "profType": onuTP.mapUniTpIndication[aUniID].techProfileType,
305 "profID": onuTP.mapUniTpIndication[aUniID].techProfileID})
306
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000307 Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString)
mpagenko3dbcdd22020-07-22 07:38:45 +0000308 if err == nil {
309 if Value != nil {
310 logger.Debugw("tech-profile read",
311 log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID})
312 tpTmpBytes, _ := kvstore.ToByte(Value.Value)
313
314 if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil {
315 logger.Errorw("TechProf - Failed to unmarshal tech-profile into tpInst",
316 log.Fields{"error": err, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000317 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000318 return
319 }
320 logger.Debugw("TechProf - tpInst", log.Fields{"tpInst": tpInst})
321 // access examples
322 logger.Debugw("TechProf content", log.Fields{"Name": tpInst.Name,
323 "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize,
324 "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
325 } else {
326 logger.Errorw("No tech-profile found",
327 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000328 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000329 return
330 }
331 } else {
332 logger.Errorw("kvstore-get failed for path",
333 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000334 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000335 return
336 }
337
mpagenko01e726e2020-10-23 09:45:29 +0000338 //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000339 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
340 localMapGemPortParams[0] = &gemPortParamStruct{}
341 localMapPonAniConfig := make(map[uint16]*tcontGemList)
342 localMapPonAniConfig[0] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
343 onuTP.mapPonAniConfig[aUniID] = (*tMapPonAniConfig)(&localMapPonAniConfig)
344
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000345 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000346 //get the relevant values from the profile and store to mapPonAniConfig
347 (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID)
Himani Chawla4d908332020-08-31 12:30:20 +0530348 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000349 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
350 if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" {
351 (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
352 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000353 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
mpagenko3dbcdd22020-07-22 07:38:45 +0000354 (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.schedPolicy = 2 //for G.988 WRR
355 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000356 loNumGemPorts := tpInst.NumGemPorts
357 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000358 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000359 if uint32(pos) == loNumGemPorts {
360 logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
361 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000362 break
363 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000364 if pos == 0 {
365 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
366 loGemPortRead = true
367 } else {
368 //for all further GemPorts we need to extend the mapGemPortParams
369 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)] = &gemPortParamStruct{}
370 }
371 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortID =
372 uint16(content.GemportID)
373 //direction can be correlated later with Downstream list,
374 // for now just assume bidirectional (upstream never exists alone)
mpagenko3dbcdd22020-07-22 07:38:45 +0000375 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000376 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
377 if 7 < content.PriorityQueue {
378 logger.Errorw("PonAniConfig reject on GemPortList - PrioQueue value invalid",
379 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue})
380 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
381 delete(onuTP.mapPonAniConfig, aUniID)
mpagenkodff5dda2020-08-28 11:52:01 +0000382 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000383 return
384 }
385 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].prioQueueIndex =
386 uint8(content.PriorityQueue)
387 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530388 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000389 if content.AesEncryption == "True" {
390 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortEncState = 1
391 } else {
392 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortEncState = 0
393 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000394 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].discardPolicy =
395 content.DiscardPolicy
396 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].queueSchedPolicy =
397 content.SchedulingPolicy
mpagenko3dbcdd22020-07-22 07:38:45 +0000398 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000399 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].queueWeight =
400 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000401 }
Himani Chawla4d908332020-08-31 12:30:20 +0530402 if !loGemPortRead {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000403 logger.Errorw("PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000404 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000405 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
406 delete(onuTP.mapPonAniConfig, aUniID)
mpagenkodff5dda2020-08-28 11:52:01 +0000407 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000408 return
409 }
Himani Chawla4d908332020-08-31 12:30:20 +0530410 //TODO!! MC (downstream) GemPorts can be set using DownstreamGemPortAttributeList separately
mpagenko3dbcdd22020-07-22 07:38:45 +0000411
412 //logger does not simply output the given structures, just give some example debug values
413 logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000414 "device-id": onuTP.deviceID,
415 "AllocId": (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.allocID})
416 for gemIndex, gemEntry := range (*(onuTP.mapPonAniConfig[0]))[0].mapGemPortParams {
417 logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
418 "GemIndex": gemIndex,
419 "GemPort": gemEntry.gemPortID,
420 "QueueScheduling": gemEntry.queueSchedPolicy})
421 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000422
mpagenkodff5dda2020-08-28 11:52:01 +0000423 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000424}
425
Himani Chawla6d2ae152020-09-02 13:11:20 +0530426func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
427 ctx context.Context, aUniID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000428
429 //OMCI transfer of ANI data acc. to mapPonAniConfig
430 // also the FSM's are running in background,
mpagenkodff5dda2020-08-28 11:52:01 +0000431 // hence we have to make sure they indicate 'success' success on chTpConfigProcessingStep with aProcessingStep
mpagenko3dbcdd22020-07-22 07:38:45 +0000432 if onuTP.pAniConfigFsm == nil {
433 onuTP.createAniConfigFsm(aUniID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
434 } else { //AniConfigFsm already init
435 onuTP.runAniConfigFsm(aProcessingStep)
436 }
437}
438
Himani Chawla6d2ae152020-09-02 13:11:20 +0530439func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000440 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000441 select {
442 case <-ctx.Done():
443 logger.Warnw("processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000444 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000445 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000446 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000447 if rxStep == aProcessingStep {
448 return true
449 }
450 //all other values are not accepted - including 0 for error indication
451 logger.Warnw("Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000452 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000453 "wantedStep": aProcessingStep, "haveStep": rxStep})
454 return false
455 }
456}
457
Himani Chawla4d908332020-08-31 12:30:20 +0530458// createUniLockFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Himani Chawla6d2ae152020-09-02 13:11:20 +0530459func (onuTP *onuUniTechProf) createAniConfigFsm(aUniID uint8,
460 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) {
divyadesai4d299552020-08-18 07:13:49 +0000461 logger.Debugw("createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000462 chAniConfigFsm := make(chan Message, 2048)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530463 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000464 if pDevEntry == nil {
divyadesai4d299552020-08-18 07:13:49 +0000465 logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000466 return
467 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530468 pAniCfgFsm := newUniPonAniConfigFsm(pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
mpagenko3dbcdd22020-07-22 07:38:45 +0000469 pDevEntry.pOnuDB, onuTP.mapUniTpIndication[aUniID].techProfileID, devEvent,
mpagenko01e726e2020-10-23 09:45:29 +0000470 "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm)
mpagenko3dbcdd22020-07-22 07:38:45 +0000471 if pAniCfgFsm != nil {
472 onuTP.pAniConfigFsm = pAniCfgFsm
473 onuTP.runAniConfigFsm(aProcessingStep)
474 } else {
divyadesai4d299552020-08-18 07:13:49 +0000475 logger.Errorw("AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000476 }
477}
478
mpagenkofc4f56e2020-11-04 17:17:49 +0000479// deleteTpResource removes Resources from the ONU's specified Uni
480func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context,
481 aUniID uint8, aPathString string, aResource resourceEntry, aEntryID uint32,
482 wg *sync.WaitGroup) {
483 defer wg.Done()
484 logger.Debugw("this would remove TP resources from ONU's UNI", log.Fields{
485 "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "Resource": aResource})
486 if cResourceTcont == aResource {
487 //the TechProfile indicated by path is considered for removal
488 // by now we do not clear the OMCI related configuration (to be done later)
489 // so we use this position here just to remove the internal stored profile data
490 // (needed for checking the existence of the TechProfile after some profile delete)
491 // at the oment we only admit 1 TechProfile (T-Cont), so by now we can just remove the only existing TechProfile
492 // TODO: To be updated with multi-T-Cont implementation
493 logger.Debugw("DeleteTcont clears the existing internal profile", log.Fields{
494 "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "Resource": aResource})
495 onuTP.clearAniSideConfig(aUniID)
496 // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created
497 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
498 if onuTP.pAniConfigFsm != nil {
499 _ = onuTP.pAniConfigFsm.pAdaptFsm.pFsm.Event(aniEvReset)
500 }
501
502 //TODO!!! - the real processing could look like that (for starting the removal, where the clearAniSideConfig is done implicitly):
503 //delete the given resource from ONU OMCI config and data base - as background routine
504 /*
505 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
506 go onuTp.deleteAniResource(ctx, processingStep)
507 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
508 //timeout or error detected
509 return
510 }
511 */
512 }
513 //if implemented, the called FSM would generate an adequate event if config has been done,
514 // by now we just stimulate this event here as 'done' - TODO!!: to be removed after full implementation
515 go onuTP.baseDeviceHandler.deviceProcStatusUpdate(OmciAniResourceRemoved)
516}
517
mpagenko3dbcdd22020-07-22 07:38:45 +0000518// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Himani Chawla6d2ae152020-09-02 13:11:20 +0530519func (onuTP *onuUniTechProf) runAniConfigFsm(aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000520 /* Uni related ANI config procedure -
521 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
522 */
Himani Chawla4d908332020-08-31 12:30:20 +0530523 pACStatemachine := onuTP.pAniConfigFsm.pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000524 if pACStatemachine != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000525 if pACStatemachine.Is(aniStDisabled) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000526 //FSM init requirement to get informed abou FSM completion! (otherwise timeout of the TechProf config)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530527 onuTP.pAniConfigFsm.setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
mpagenko1cc3cb42020-07-27 15:24:38 +0000528 if err := pACStatemachine.Event(aniEvStart); err != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000529 logger.Warnw("AniConfigFSM: can't start", log.Fields{"err": err})
530 // maybe try a FSM reset and then again ... - TODO!!!
531 } else {
532 /***** AniConfigFSM started */
533 logger.Debugw("AniConfigFSM started", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000534 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000535 }
536 } else {
537 logger.Warnw("wrong state of AniConfigFSM - want: disabled", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000538 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000539 // maybe try a FSM reset and then again ... - TODO!!!
540 }
541 } else {
divyadesai4d299552020-08-18 07:13:49 +0000542 logger.Errorw("AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000543 // maybe try a FSM reset and then again ... - TODO!!!
544 }
mpagenkoaf801632020-07-03 10:00:42 +0000545}
mpagenkodff5dda2020-08-28 11:52:01 +0000546
mpagenko01e726e2020-10-23 09:45:29 +0000547// clearAniSideConfig deletes all internal TechProfile related data connected to the requested UniPort
548func (onuTP *onuUniTechProf) clearAniSideConfig(aUniID uint8) {
549 logger.Debugw("removing TpIndication and PonAniConfig data", log.Fields{
550 "device-id": onuTP.deviceID, "uni-id": aUniID})
551 //a mutex protection on the concerned data should not be needed here, as the config/write action should not
552 // interfere with any read action or the initial write/config activity at start
553 //remove the TechProfile indications of this UNI, should be safe even if not existing
554 delete(onuTP.mapUniTpIndication, aUniID)
555 //delete on the PonAniConfig map of this UNI should be safe, even if not existing
556 delete(onuTP.mapPonAniConfig, aUniID)
557}
558
mpagenkodff5dda2020-08-28 11:52:01 +0000559// setConfigDone sets the requested techProfile config state (if possible)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530560func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aState bool) {
mpagenkodff5dda2020-08-28 11:52:01 +0000561 if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP {
562 onuTP.mutexTPState.Lock()
563 onuTP.mapUniTpIndication[aUniID].techProfileConfigDone = aState
564 onuTP.mutexTPState.Unlock()
565 } //else: the state is just ignored (does not exist)
566}
567
568// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
Himani Chawla6d2ae152020-09-02 13:11:20 +0530569func (onuTP *onuUniTechProf) getTechProfileDone(aUniID uint8, aTpID uint16) bool {
mpagenkodff5dda2020-08-28 11:52:01 +0000570 if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP {
571 if onuTP.mapUniTpIndication[aUniID].techProfileID == aTpID {
572 onuTP.mutexTPState.Lock()
573 defer onuTP.mutexTPState.Unlock()
mpagenko2418ab02020-11-12 12:58:06 +0000574 if onuTP.mapUniTpIndication[aUniID].techProfileToDelete {
575 logger.Debugw("TechProfile not relevant for requested flow config - waiting on delete",
576 log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID})
577 return false //still waiting for removal of this techProfile first
578 }
mpagenkodff5dda2020-08-28 11:52:01 +0000579 return onuTP.mapUniTpIndication[aUniID].techProfileConfigDone
580 }
581 }
582 //for all other constellations indicate false = Config not done
583 return false
584}
mpagenko2418ab02020-11-12 12:58:06 +0000585
586// setProfileToDelete sets the requested techProfile toDelete state (if possible)
587func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aState bool) {
588 if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP {
589 onuTP.mutexTPState.Lock()
590 onuTP.mapUniTpIndication[aUniID].techProfileToDelete = aState
591 onuTP.mutexTPState.Unlock()
592 } //else: the state is just ignored (does not exist)
593}