blob: f47025b9d1e2e1d2cba96f4894ae073ee690d7ec [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"
mpagenko3dbcdd22020-07-22 07:38:45 +000024 "strconv"
25 "strings"
mpagenkoaf801632020-07-03 10:00:42 +000026 "sync"
27
28 "github.com/opencord/voltha-lib-go/v3/pkg/db"
29 "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore"
30 "github.com/opencord/voltha-lib-go/v3/pkg/log"
31 tp "github.com/opencord/voltha-lib-go/v3/pkg/techprofile"
32)
33
34const cBasePathTechProfileKVStore = "service/voltha/technology_profiles"
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000035
36//definitions for TechProfileProcessing - copied from OltAdapter:openolt_flowmgr.go
37// could perhaps be defined more globally
38const (
Himani Chawla6d2ae152020-09-02 13:11:20 +053039 // binaryStringPrefix is binary string prefix
40 binaryStringPrefix = "0b"
41 // binaryBit1 is binary bit 1 expressed as a character
42 //binaryBit1 = '1'
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000043)
mpagenkoaf801632020-07-03 10:00:42 +000044
45type resourceEntry int
46
47const (
48 cResourceGemPort resourceEntry = 1
49 cResourceTcont resourceEntry = 2
50)
51
mpagenko3dbcdd22020-07-22 07:38:45 +000052type tTechProfileIndication struct {
mpagenkodff5dda2020-08-28 11:52:01 +000053 techProfileType string
54 techProfileID uint16
55 techProfileConfigDone bool
mpagenko3dbcdd22020-07-22 07:38:45 +000056}
57
58type tcontParamStruct struct {
59 allocID uint16
60 schedPolicy uint8
61}
62type gemPortParamStruct struct {
Himani Chawla4d908332020-08-31 12:30:20 +053063 //ponOmciCC bool
mpagenko3dbcdd22020-07-22 07:38:45 +000064 gemPortID uint16
65 direction uint8
66 gemPortEncState uint8
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000067 prioQueueIndex uint8
68 pbitString string
mpagenko3dbcdd22020-07-22 07:38:45 +000069 discardPolicy string
Himani Chawla4d908332020-08-31 12:30:20 +053070 //could also be a queue specific parameter, not used that way here
71 //maxQueueSize uint16
mpagenko3dbcdd22020-07-22 07:38:45 +000072 queueSchedPolicy string
73 queueWeight uint8
74}
75
76//refers to one tcont and its properties and all assigned GemPorts and their properties
77type tcontGemList struct {
78 tcontParams tcontParamStruct
79 mapGemPortParams map[uint16]*gemPortParamStruct
80}
81
82//refers to all tcont and their Tcont/GemPort Parameters
83type tMapPonAniConfig map[uint16]*tcontGemList
84
Himani Chawla6d2ae152020-09-02 13:11:20 +053085//onuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU
86type onuUniTechProf struct {
mpagenkodff5dda2020-08-28 11:52:01 +000087 deviceID string
Himani Chawla6d2ae152020-09-02 13:11:20 +053088 baseDeviceHandler *deviceHandler
mpagenkodff5dda2020-08-28 11:52:01 +000089 tpProcMutex sync.RWMutex
mpagenkodff5dda2020-08-28 11:52:01 +000090 techProfileKVStore *db.Backend
mpagenkodff5dda2020-08-28 11:52:01 +000091 chTpConfigProcessingStep chan uint8
mpagenkodff5dda2020-08-28 11:52:01 +000092 mapUniTpIndication map[uint8]*tTechProfileIndication //use pointer values to ease assignments to the map
93 mapPonAniConfig map[uint8]*tMapPonAniConfig //per UNI: use pointer values to ease assignments to the map
Himani Chawla6d2ae152020-09-02 13:11:20 +053094 pAniConfigFsm *uniPonAniConfigFsm
mpagenkodff5dda2020-08-28 11:52:01 +000095 procResult error //error indication of processing
96 mutexTPState sync.Mutex
mpagenkoaf801632020-07-03 10:00:42 +000097}
98
Himani Chawla6d2ae152020-09-02 13:11:20 +053099//newOnuUniTechProf returns the instance of a OnuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000100//(one instance per ONU/deviceHandler for all possible UNI's)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530101func newOnuUniTechProf(ctx context.Context, aDeviceID string, aDeviceHandler *deviceHandler) *onuUniTechProf {
divyadesai4d299552020-08-18 07:13:49 +0000102 logger.Infow("init-OnuUniTechProf", log.Fields{"device-id": aDeviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530103 var onuTP onuUniTechProf
mpagenkoaf801632020-07-03 10:00:42 +0000104 onuTP.deviceID = aDeviceID
105 onuTP.baseDeviceHandler = aDeviceHandler
106 onuTP.tpProcMutex = sync.RWMutex{}
mpagenkodff5dda2020-08-28 11:52:01 +0000107 onuTP.chTpConfigProcessingStep = make(chan uint8)
mpagenkodff5dda2020-08-28 11:52:01 +0000108 onuTP.mapUniTpIndication = make(map[uint8]*tTechProfileIndication)
109 onuTP.mapPonAniConfig = make(map[uint8]*tMapPonAniConfig)
mpagenko1cc3cb42020-07-27 15:24:38 +0000110 onuTP.procResult = nil //default assumption processing done with success
mpagenkoaf801632020-07-03 10:00:42 +0000111
Himani Chawla6d2ae152020-09-02 13:11:20 +0530112 onuTP.techProfileKVStore = aDeviceHandler.setBackend(cBasePathTechProfileKVStore)
mpagenkoaf801632020-07-03 10:00:42 +0000113 if onuTP.techProfileKVStore == nil {
114 logger.Errorw("Can't access techProfileKVStore - no backend connection to service",
divyadesai4d299552020-08-18 07:13:49 +0000115 log.Fields{"device-id": aDeviceID, "service": cBasePathTechProfileKVStore})
mpagenkoaf801632020-07-03 10:00:42 +0000116 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000117
mpagenkoaf801632020-07-03 10:00:42 +0000118 return &onuTP
119}
120
121// lockTpProcMutex locks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530122func (onuTP *onuUniTechProf) lockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000123 onuTP.tpProcMutex.Lock()
124}
125
126// unlockTpProcMutex unlocks OnuUniTechProf processing mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530127func (onuTP *onuUniTechProf) unlockTpProcMutex() {
mpagenkoaf801632020-07-03 10:00:42 +0000128 onuTP.tpProcMutex.Unlock()
129}
130
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000131// resetTpProcessingErrorIndication resets the internal error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000132// need to be called before evaluation of any subsequent processing (given by waitForTpCompletion())
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000133func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication() {
mpagenko1cc3cb42020-07-27 15:24:38 +0000134 onuTP.procResult = nil
135}
136
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000137func (onuTP *onuUniTechProf) getTpProcessingErrorIndication() error {
mpagenko1cc3cb42020-07-27 15:24:38 +0000138 return onuTP.procResult
mpagenko3dbcdd22020-07-22 07:38:45 +0000139}
140
141// configureUniTp checks existing tp resources to delete and starts the corresponding OMCI configuation of the UNI port
142// all possibly blocking processing must be run in background to allow for deadline supervision!
143// but take care on sequential background processing when needed (logical dependencies)
Himani Chawla4d908332020-08-31 12:30:20 +0530144// use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization
Himani Chawla6d2ae152020-09-02 13:11:20 +0530145func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context,
mpagenkodff5dda2020-08-28 11:52:01 +0000146 aUniID uint8, aPathString string, wg *sync.WaitGroup) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000147 defer wg.Done() //always decrement the waitGroup on return
mpagenkoaf801632020-07-03 10:00:42 +0000148 logger.Debugw("configure the Uni according to TpPath", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000149 "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString})
mpagenkoaf801632020-07-03 10:00:42 +0000150
mpagenkoaf801632020-07-03 10:00:42 +0000151 if onuTP.techProfileKVStore == nil {
152 logger.Debug("techProfileKVStore not set - abort")
Himani Chawla26e555c2020-08-31 12:30:20 +0530153 onuTP.procResult = errors.New("techProfile config aborted: techProfileKVStore not set")
mpagenkoaf801632020-07-03 10:00:42 +0000154 return
155 }
156
mpagenko3dbcdd22020-07-22 07:38:45 +0000157 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530158 var pCurrentUniPort *onuUniPort
mpagenko3dbcdd22020-07-22 07:38:45 +0000159 for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap {
160 // only if this port is validated for operState transfer
Himani Chawla26e555c2020-08-31 12:30:20 +0530161 if uniPort.uniID == uint8(aUniID) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000162 pCurrentUniPort = uniPort
163 break //found - end search loop
164 }
165 }
166 if pCurrentUniPort == nil {
167 logger.Errorw("TechProfile configuration aborted: requested uniID not found in PortDB",
168 log.Fields{"device-id": onuTP.deviceID, "uniID": aUniID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530169 onuTP.procResult = errors.New("techProfile config aborted: requested uniID not found")
mpagenko3dbcdd22020-07-22 07:38:45 +0000170 return
171 }
mpagenkoaf801632020-07-03 10:00:42 +0000172
mpagenkodff5dda2020-08-28 11:52:01 +0000173 var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep
mpagenkoaf801632020-07-03 10:00:42 +0000174
mpagenko3dbcdd22020-07-22 07:38:45 +0000175 //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called
176 // in case the KVPath has changed for the given UNI,
177 // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing
178 // (ANI) configuration of this port has to be removed first
179 // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well)
180 // existence of configuration can be detected based on tp stored TCONT's
181 //TODO!!!:
182 /* if tcontMap not empty {
183 go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000184 if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000185 //timeout or error detected
186 return
187 }
188 clear tcontMap
189 }
190
191 processingStep++
192 */
193 go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, aPathString, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000194 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000195 //timeout or error detected
196 logger.Debugw("tech-profile related configuration aborted on read",
197 log.Fields{"device-id": onuTP.deviceID, "UniId": aUniID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530198 onuTP.procResult = errors.New("techProfile config aborted: tech-profile read issue")
mpagenko3dbcdd22020-07-22 07:38:45 +0000199 return
200 }
201
202 processingStep++
203 if valuePA, existPA := onuTP.mapPonAniConfig[aUniID]; existPA {
204 if _, existTG := (*valuePA)[0]; existTG {
205 //Config data for this uni and and at least TCont Index 0 exist
206 go onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, pCurrentUniPort, processingStep)
mpagenkodff5dda2020-08-28 11:52:01 +0000207 if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000208 //timeout or error detected
209 logger.Debugw("tech-profile related configuration aborted on set",
210 log.Fields{"device-id": onuTP.deviceID, "UniId": aUniID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530211 onuTP.procResult = errors.New("techProfile config aborted: Omci AniSideConfig failed")
Himani Chawla4d908332020-08-31 12:30:20 +0530212 //this issue here means that the AniConfigFsm has not finished successfully
mpagenko3dbcdd22020-07-22 07:38:45 +0000213 //which requires to reset it to allow for new usage, e.g. also on a different UNI
214 //(without that it would be reset on device down indication latest)
Himani Chawla4d908332020-08-31 12:30:20 +0530215 _ = onuTP.pAniConfigFsm.pAdaptFsm.pFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +0000216 return
mpagenkoaf801632020-07-03 10:00:42 +0000217 }
218 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000219 // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed)
220 logger.Debugw("no Tcont/Gem data for this UNI found - abort", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000221 "device-id": onuTP.deviceID, "uniID": aUniID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530222 onuTP.procResult = errors.New("techProfile config aborted: no Tcont/Gem data found for this UNI")
mpagenko1cc3cb42020-07-27 15:24:38 +0000223 return
mpagenkoaf801632020-07-03 10:00:42 +0000224 }
225 } else {
mpagenko3dbcdd22020-07-22 07:38:45 +0000226 logger.Debugw("no PonAni data for this UNI found - abort", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000227 "device-id": onuTP.deviceID, "uniID": aUniID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530228 onuTP.procResult = errors.New("techProfile config aborted: no AniSide data found for this UNI")
mpagenko1cc3cb42020-07-27 15:24:38 +0000229 return
mpagenkoaf801632020-07-03 10:00:42 +0000230 }
231}
232
mpagenko3dbcdd22020-07-22 07:38:45 +0000233/* internal methods *********************/
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000234
Himani Chawla6d2ae152020-09-02 13:11:20 +0530235func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile(
mpagenkodff5dda2020-08-28 11:52:01 +0000236 ctx context.Context, aUniID uint8, aPathString string, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000237 var tpInst tp.TechProfile
238
239 //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup
240 //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier>
241 subStringSlice := strings.Split(aPathString, "/")
242 if len(subStringSlice) <= 2 {
243 logger.Errorw("invalid path name format",
244 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000245 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000246 return
247 }
248
249 //just some logical check to avoid unexpected behavior
250 //at this point it is assumed that a new TechProfile is assigned to the UNI
251 //expectation is that no TPIndication entry exists here, if yes,
252 // then we throw a warning and remove it (and the possible ANIConfig) simply
253 // note that the ONU config state may be ambivalent in such a case
254 // also note, that the PonAniConfig map is not checked additionally
255 // consistency to TPIndication is assumed
256 if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP {
257 logger.Warnw("Some active profile entry at reading new TechProfile",
258 log.Fields{"path": aPathString, "device-id": onuTP.deviceID,
259 "UniId": aUniID, "wrongProfile": onuTP.mapUniTpIndication[aUniID].techProfileID})
260 //delete on the mapUniTpIndication map not needed, just overwritten later
261 //delete on the PonAniConfig map should be safe, even if not existing
262 delete(onuTP.mapPonAniConfig, aUniID)
263 } else {
264 // this is normal processing
265 onuTP.mapUniTpIndication[aUniID] = &tTechProfileIndication{} //need to assign some (empty) struct memory first!
266 }
267
268 onuTP.mapUniTpIndication[aUniID].techProfileType = subStringSlice[0]
269 profID, err := strconv.ParseUint(subStringSlice[1], 10, 32)
270 if err != nil {
271 logger.Errorw("invalid ProfileId from path",
272 log.Fields{"ParseErr": err})
mpagenkodff5dda2020-08-28 11:52:01 +0000273 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000274 return
275 }
276
277 //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID
278 onuTP.mapUniTpIndication[aUniID].techProfileID = uint16(profID)
279 logger.Debugw("tech-profile path indications",
280 log.Fields{"device-id": onuTP.deviceID, "UniId": aUniID,
281 "profType": onuTP.mapUniTpIndication[aUniID].techProfileType,
282 "profID": onuTP.mapUniTpIndication[aUniID].techProfileID})
283
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000284 Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString)
mpagenko3dbcdd22020-07-22 07:38:45 +0000285 if err == nil {
286 if Value != nil {
287 logger.Debugw("tech-profile read",
288 log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID})
289 tpTmpBytes, _ := kvstore.ToByte(Value.Value)
290
291 if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil {
292 logger.Errorw("TechProf - Failed to unmarshal tech-profile into tpInst",
293 log.Fields{"error": err, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000294 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000295 return
296 }
297 logger.Debugw("TechProf - tpInst", log.Fields{"tpInst": tpInst})
298 // access examples
299 logger.Debugw("TechProf content", log.Fields{"Name": tpInst.Name,
300 "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize,
301 "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold})
302 } else {
303 logger.Errorw("No tech-profile found",
304 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000305 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000306 return
307 }
308 } else {
309 logger.Errorw("kvstore-get failed for path",
310 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000311 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko3dbcdd22020-07-22 07:38:45 +0000312 return
313 }
314
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000315 //default start with 1Tcont1Gem profile, later extend for multi GemPerTcont and perhaps even MultiTcontMultiGem
mpagenko3dbcdd22020-07-22 07:38:45 +0000316 localMapGemPortParams := make(map[uint16]*gemPortParamStruct)
317 localMapGemPortParams[0] = &gemPortParamStruct{}
318 localMapPonAniConfig := make(map[uint16]*tcontGemList)
319 localMapPonAniConfig[0] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams}
320 onuTP.mapPonAniConfig[aUniID] = (*tMapPonAniConfig)(&localMapPonAniConfig)
321
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000322 //note: the code is currently restricted to one TCcont per Onu (index [0])
mpagenko3dbcdd22020-07-22 07:38:45 +0000323 //get the relevant values from the profile and store to mapPonAniConfig
324 (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID)
Himani Chawla4d908332020-08-31 12:30:20 +0530325 //maybe tCont scheduling not (yet) needed - just to basically have it for future
mpagenko3dbcdd22020-07-22 07:38:45 +0000326 // (would only be relevant in case of ONU-2G QOS configuration flexibility)
327 if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" {
328 (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines!
329 } else {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000330 //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP
mpagenko3dbcdd22020-07-22 07:38:45 +0000331 (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.schedPolicy = 2 //for G.988 WRR
332 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000333 loNumGemPorts := tpInst.NumGemPorts
334 loGemPortRead := false
mpagenko3dbcdd22020-07-22 07:38:45 +0000335 for pos, content := range tpInst.UpstreamGemPortAttributeList {
mpagenko1cc3cb42020-07-27 15:24:38 +0000336 if uint32(pos) == loNumGemPorts {
337 logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts",
338 log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts})
mpagenko3dbcdd22020-07-22 07:38:45 +0000339 break
340 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000341 if pos == 0 {
342 //at least one upstream GemPort should always exist (else traffic profile makes no sense)
343 loGemPortRead = true
344 } else {
345 //for all further GemPorts we need to extend the mapGemPortParams
346 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)] = &gemPortParamStruct{}
347 }
348 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortID =
349 uint16(content.GemportID)
350 //direction can be correlated later with Downstream list,
351 // for now just assume bidirectional (upstream never exists alone)
mpagenko3dbcdd22020-07-22 07:38:45 +0000352 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].direction = 3 //as defined in G.988
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000353 // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7
354 if 7 < content.PriorityQueue {
355 logger.Errorw("PonAniConfig reject on GemPortList - PrioQueue value invalid",
356 log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue})
357 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
358 delete(onuTP.mapPonAniConfig, aUniID)
mpagenkodff5dda2020-08-28 11:52:01 +0000359 onuTP.chTpConfigProcessingStep <- 0 //error indication
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000360 return
361 }
362 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].prioQueueIndex =
363 uint8(content.PriorityQueue)
364 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].pbitString =
Himani Chawla6d2ae152020-09-02 13:11:20 +0530365 strings.TrimPrefix(content.PbitMap, binaryStringPrefix)
mpagenko3dbcdd22020-07-22 07:38:45 +0000366 if content.AesEncryption == "True" {
367 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortEncState = 1
368 } else {
369 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].gemPortEncState = 0
370 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000371 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].discardPolicy =
372 content.DiscardPolicy
373 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].queueSchedPolicy =
374 content.SchedulingPolicy
mpagenko3dbcdd22020-07-22 07:38:45 +0000375 //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000376 (*(onuTP.mapPonAniConfig[aUniID]))[0].mapGemPortParams[uint16(pos)].queueWeight =
377 uint8(content.Weight)
mpagenko3dbcdd22020-07-22 07:38:45 +0000378 }
Himani Chawla4d908332020-08-31 12:30:20 +0530379 if !loGemPortRead {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000380 logger.Errorw("PonAniConfig reject - no GemPort could be read from TechProfile",
mpagenko1cc3cb42020-07-27 15:24:38 +0000381 log.Fields{"path": aPathString, "device-id": onuTP.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000382 //remove PonAniConfig as done so far, delete map should be safe, even if not existing
383 delete(onuTP.mapPonAniConfig, aUniID)
mpagenkodff5dda2020-08-28 11:52:01 +0000384 onuTP.chTpConfigProcessingStep <- 0 //error indication
mpagenko1cc3cb42020-07-27 15:24:38 +0000385 return
386 }
Himani Chawla4d908332020-08-31 12:30:20 +0530387 //TODO!! MC (downstream) GemPorts can be set using DownstreamGemPortAttributeList separately
mpagenko3dbcdd22020-07-22 07:38:45 +0000388
389 //logger does not simply output the given structures, just give some example debug values
390 logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000391 "device-id": onuTP.deviceID,
392 "AllocId": (*(onuTP.mapPonAniConfig[aUniID]))[0].tcontParams.allocID})
393 for gemIndex, gemEntry := range (*(onuTP.mapPonAniConfig[0]))[0].mapGemPortParams {
394 logger.Debugw("PonAniConfig read from TechProfile", log.Fields{
395 "GemIndex": gemIndex,
396 "GemPort": gemEntry.gemPortID,
397 "QueueScheduling": gemEntry.queueSchedPolicy})
398 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000399
mpagenkodff5dda2020-08-28 11:52:01 +0000400 onuTP.chTpConfigProcessingStep <- aProcessingStep //done
mpagenko3dbcdd22020-07-22 07:38:45 +0000401}
402
Himani Chawla6d2ae152020-09-02 13:11:20 +0530403func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile(
404 ctx context.Context, aUniID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000405
406 //OMCI transfer of ANI data acc. to mapPonAniConfig
407 // also the FSM's are running in background,
mpagenkodff5dda2020-08-28 11:52:01 +0000408 // hence we have to make sure they indicate 'success' success on chTpConfigProcessingStep with aProcessingStep
mpagenko3dbcdd22020-07-22 07:38:45 +0000409 if onuTP.pAniConfigFsm == nil {
410 onuTP.createAniConfigFsm(aUniID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep)
411 } else { //AniConfigFsm already init
412 onuTP.runAniConfigFsm(aProcessingStep)
413 }
414}
415
Himani Chawla6d2ae152020-09-02 13:11:20 +0530416func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion(
mpagenkodff5dda2020-08-28 11:52:01 +0000417 ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool {
mpagenko3dbcdd22020-07-22 07:38:45 +0000418 select {
419 case <-ctx.Done():
420 logger.Warnw("processing not completed in-time: force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000421 log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()})
mpagenko3dbcdd22020-07-22 07:38:45 +0000422 return false
mpagenkodff5dda2020-08-28 11:52:01 +0000423 case rxStep := <-aChTpProcessingStep:
mpagenko3dbcdd22020-07-22 07:38:45 +0000424 if rxStep == aProcessingStep {
425 return true
426 }
427 //all other values are not accepted - including 0 for error indication
428 logger.Warnw("Invalid processing step received: abort and force release of TpProcMutex!",
divyadesai4d299552020-08-18 07:13:49 +0000429 log.Fields{"device-id": onuTP.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000430 "wantedStep": aProcessingStep, "haveStep": rxStep})
431 return false
432 }
433}
434
Himani Chawla4d908332020-08-31 12:30:20 +0530435// createUniLockFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Himani Chawla6d2ae152020-09-02 13:11:20 +0530436func (onuTP *onuUniTechProf) createAniConfigFsm(aUniID uint8,
437 apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) {
divyadesai4d299552020-08-18 07:13:49 +0000438 logger.Debugw("createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000439 chAniConfigFsm := make(chan Message, 2048)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530440 pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000441 if pDevEntry == nil {
divyadesai4d299552020-08-18 07:13:49 +0000442 logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000443 return
444 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530445 pAniCfgFsm := newUniPonAniConfigFsm(pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP,
mpagenko3dbcdd22020-07-22 07:38:45 +0000446 pDevEntry.pOnuDB, onuTP.mapUniTpIndication[aUniID].techProfileID, devEvent,
447 "AniConfigFsm", onuTP.deviceID, chAniConfigFsm)
448 if pAniCfgFsm != nil {
449 onuTP.pAniConfigFsm = pAniCfgFsm
450 onuTP.runAniConfigFsm(aProcessingStep)
451 } else {
divyadesai4d299552020-08-18 07:13:49 +0000452 logger.Errorw("AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000453 }
454}
455
456// runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration
Himani Chawla6d2ae152020-09-02 13:11:20 +0530457func (onuTP *onuUniTechProf) runAniConfigFsm(aProcessingStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000458 /* Uni related ANI config procedure -
459 ***** should run via 'aniConfigDone' state and generate the argument requested event *****
460 */
Himani Chawla4d908332020-08-31 12:30:20 +0530461 pACStatemachine := onuTP.pAniConfigFsm.pAdaptFsm.pFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000462 if pACStatemachine != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000463 if pACStatemachine.Is(aniStDisabled) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000464 //FSM init requirement to get informed abou FSM completion! (otherwise timeout of the TechProf config)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530465 onuTP.pAniConfigFsm.setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep)
mpagenko1cc3cb42020-07-27 15:24:38 +0000466 if err := pACStatemachine.Event(aniEvStart); err != nil {
mpagenko3dbcdd22020-07-22 07:38:45 +0000467 logger.Warnw("AniConfigFSM: can't start", log.Fields{"err": err})
468 // maybe try a FSM reset and then again ... - TODO!!!
469 } else {
470 /***** AniConfigFSM started */
471 logger.Debugw("AniConfigFSM started", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000472 "state": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000473 }
474 } else {
475 logger.Warnw("wrong state of AniConfigFSM - want: disabled", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000476 "have": pACStatemachine.Current(), "device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000477 // maybe try a FSM reset and then again ... - TODO!!!
478 }
479 } else {
divyadesai4d299552020-08-18 07:13:49 +0000480 logger.Errorw("AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000481 // maybe try a FSM reset and then again ... - TODO!!!
482 }
mpagenkoaf801632020-07-03 10:00:42 +0000483}
mpagenkodff5dda2020-08-28 11:52:01 +0000484
485// setConfigDone sets the requested techProfile config state (if possible)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530486func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aState bool) {
mpagenkodff5dda2020-08-28 11:52:01 +0000487 if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP {
488 onuTP.mutexTPState.Lock()
489 onuTP.mapUniTpIndication[aUniID].techProfileConfigDone = aState
490 onuTP.mutexTPState.Unlock()
491 } //else: the state is just ignored (does not exist)
492}
493
494// getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done
Himani Chawla6d2ae152020-09-02 13:11:20 +0530495func (onuTP *onuUniTechProf) getTechProfileDone(aUniID uint8, aTpID uint16) bool {
mpagenkodff5dda2020-08-28 11:52:01 +0000496 if _, existTP := onuTP.mapUniTpIndication[aUniID]; existTP {
497 if onuTP.mapUniTpIndication[aUniID].techProfileID == aTpID {
498 onuTP.mutexTPState.Lock()
499 defer onuTP.mutexTPState.Unlock()
500 return onuTP.mapUniTpIndication[aUniID].techProfileConfigDone
501 }
502 }
503 //for all other constellations indicate false = Config not done
504 return false
505}