mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 1 | /* |
| 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 |
| 18 | package adaptercoreonu |
| 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "encoding/json" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 23 | "errors" |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 24 | "fmt" |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 25 | "strings" |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 26 | "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 | |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 34 | const cBasePathTechProfileKVStore = "%s/technology_profiles" |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 35 | |
| 36 | //definitions for TechProfileProcessing - copied from OltAdapter:openolt_flowmgr.go |
| 37 | // could perhaps be defined more globally |
| 38 | const ( |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 39 | // binaryStringPrefix is binary string prefix |
| 40 | binaryStringPrefix = "0b" |
| 41 | // binaryBit1 is binary bit 1 expressed as a character |
| 42 | //binaryBit1 = '1' |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 43 | ) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 44 | |
| 45 | type resourceEntry int |
| 46 | |
| 47 | const ( |
| 48 | cResourceGemPort resourceEntry = 1 |
| 49 | cResourceTcont resourceEntry = 2 |
| 50 | ) |
| 51 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 52 | type tTechProfileIndication struct { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 53 | techProfileType string |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 54 | techProfileID uint8 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 55 | techProfileConfigDone bool |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 56 | techProfileToDelete bool |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | type tcontParamStruct struct { |
| 60 | allocID uint16 |
| 61 | schedPolicy uint8 |
| 62 | } |
| 63 | type gemPortParamStruct struct { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 64 | //ponOmciCC bool |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 65 | gemPortID uint16 |
| 66 | direction uint8 |
| 67 | gemPortEncState uint8 |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 68 | prioQueueIndex uint8 |
| 69 | pbitString string |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 70 | discardPolicy string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 71 | //could also be a queue specific parameter, not used that way here |
| 72 | //maxQueueSize uint16 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 73 | queueSchedPolicy string |
| 74 | queueWeight uint8 |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 75 | removeIndex uint16 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | //refers to one tcont and its properties and all assigned GemPorts and their properties |
| 79 | type tcontGemList struct { |
| 80 | tcontParams tcontParamStruct |
| 81 | mapGemPortParams map[uint16]*gemPortParamStruct |
| 82 | } |
| 83 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 84 | // refers a unique combination of uniID and tpID for a given ONU. |
| 85 | type uniTP struct { |
| 86 | uniID uint8 |
| 87 | tpID uint8 |
| 88 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 89 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 90 | //onuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU |
| 91 | type onuUniTechProf struct { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 92 | baseDeviceHandler *deviceHandler |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 93 | deviceID string |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 94 | tpProcMutex sync.RWMutex |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 95 | techProfileKVStore *db.Backend |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 96 | chTpConfigProcessingStep chan uint8 |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 97 | mapUniTpIndication map[uniTP]*tTechProfileIndication //use pointer values to ease assignments to the map |
| 98 | mapPonAniConfig map[uniTP]*tcontGemList //per UNI: use pointer values to ease assignments to the map |
| 99 | pAniConfigFsm map[uniTP]*uniPonAniConfigFsm |
| 100 | procResult map[uniTP]error //error indication of processing |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 101 | mutexTPState sync.Mutex |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 102 | tpProfileExists map[uniTP]bool |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 103 | mapRemoveGemEntry map[uniTP]*gemPortParamStruct //per UNI: pointer to GemEntry to be removed |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 106 | //newOnuUniTechProf returns the instance of a OnuUniTechProf |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 107 | //(one instance per ONU/deviceHandler for all possible UNI's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 108 | func newOnuUniTechProf(ctx context.Context, aDeviceHandler *deviceHandler) *onuUniTechProf { |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 109 | logger.Debugw("init-OnuUniTechProf", log.Fields{"device-id": aDeviceHandler.deviceID}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 110 | var onuTP onuUniTechProf |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 111 | onuTP.baseDeviceHandler = aDeviceHandler |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 112 | onuTP.deviceID = aDeviceHandler.deviceID |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 113 | onuTP.tpProcMutex = sync.RWMutex{} |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 114 | onuTP.chTpConfigProcessingStep = make(chan uint8) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 115 | onuTP.mapUniTpIndication = make(map[uniTP]*tTechProfileIndication) |
| 116 | onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList) |
| 117 | onuTP.procResult = make(map[uniTP]error) |
| 118 | onuTP.tpProfileExists = make(map[uniTP]bool) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 119 | onuTP.mapRemoveGemEntry = make(map[uniTP]*gemPortParamStruct) |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 120 | baseKvStorePath := fmt.Sprintf(cBasePathTechProfileKVStore, aDeviceHandler.pOpenOnuAc.cm.Backend.PathPrefix) |
| 121 | onuTP.techProfileKVStore = aDeviceHandler.setBackend(baseKvStorePath) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 122 | if onuTP.techProfileKVStore == nil { |
| 123 | logger.Errorw("Can't access techProfileKVStore - no backend connection to service", |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 124 | log.Fields{"device-id": aDeviceHandler.deviceID, "service": baseKvStorePath}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 125 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 126 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 127 | return &onuTP |
| 128 | } |
| 129 | |
| 130 | // lockTpProcMutex locks OnuUniTechProf processing mutex |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 131 | func (onuTP *onuUniTechProf) lockTpProcMutex() { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 132 | onuTP.tpProcMutex.Lock() |
| 133 | } |
| 134 | |
| 135 | // unlockTpProcMutex unlocks OnuUniTechProf processing mutex |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 136 | func (onuTP *onuUniTechProf) unlockTpProcMutex() { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 137 | onuTP.tpProcMutex.Unlock() |
| 138 | } |
| 139 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 140 | // resetTpProcessingErrorIndication resets the internal error indication |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 141 | // need to be called before evaluation of any subsequent processing (given by waitForTpCompletion()) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 142 | func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) { |
| 143 | onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 146 | func (onuTP *onuUniTechProf) getTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error { |
| 147 | return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 148 | } |
| 149 | |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 150 | // configureUniTp checks existing tp resources to configure and starts the corresponding OMCI configuation of the UNI port |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 151 | // all possibly blocking processing must be run in background to allow for deadline supervision! |
| 152 | // but take care on sequential background processing when needed (logical dependencies) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 153 | // use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 154 | func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 155 | aUniID uint8, aPathString string, wg *sync.WaitGroup) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 156 | defer wg.Done() //always decrement the waitGroup on return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 157 | logger.Debugw("configure the Uni according to TpPath", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 158 | "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 159 | tpID, err := GetTpIDFromTpPath(aPathString) |
| 160 | uniTpKey := uniTP{uniID: aUniID, tpID: tpID} |
| 161 | if err != nil { |
| 162 | logger.Errorw("error-extracting-tp-id-from-tp-path", log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString}) |
| 163 | return |
| 164 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 165 | if onuTP.techProfileKVStore == nil { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 166 | logger.Errorw("techProfileKVStore not set - abort", |
| 167 | log.Fields{"device-id": onuTP.deviceID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 168 | onuTP.procResult[uniTpKey] = errors.New("techProfile config aborted: techProfileKVStore not set") |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 169 | return |
| 170 | } |
| 171 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 172 | //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 173 | var pCurrentUniPort *onuUniPort |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 174 | for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap { |
| 175 | // only if this port is validated for operState transfer |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 176 | if uniPort.uniID == aUniID { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 177 | pCurrentUniPort = uniPort |
| 178 | break //found - end search loop |
| 179 | } |
| 180 | } |
| 181 | if pCurrentUniPort == nil { |
| 182 | logger.Errorw("TechProfile configuration aborted: requested uniID not found in PortDB", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 183 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 184 | onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: requested uniID not found %d on %s", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 185 | aUniID, onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 186 | return |
| 187 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 188 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 189 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 190 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 191 | //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called |
| 192 | // in case the KVPath has changed for the given UNI, |
| 193 | // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing |
| 194 | // (ANI) configuration of this port has to be removed first |
| 195 | // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well) |
| 196 | // existence of configuration can be detected based on tp stored TCONT's |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 197 | //TODO: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 198 | /* if tcontMap not empty { |
| 199 | go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 200 | if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 201 | //timeout or error detected |
| 202 | return |
| 203 | } |
| 204 | clear tcontMap |
| 205 | } |
| 206 | |
| 207 | processingStep++ |
| 208 | */ |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 209 | go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 210 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 211 | //timeout or error detected |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 212 | if onuTP.tpProfileExists[uniTpKey] { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 213 | //ignore the internal error in case the new profile is already configured |
| 214 | // and abort the processing here |
| 215 | return |
| 216 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 217 | logger.Errorw("tech-profile related configuration aborted on read", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 218 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 219 | onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: tech-profile read issue for %d on %s", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 220 | aUniID, onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 221 | return |
| 222 | } |
| 223 | |
| 224 | processingStep++ |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 225 | |
| 226 | valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey] |
| 227 | |
| 228 | if existPA { |
| 229 | if valuePA != nil { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 230 | //Config data for this uni and and at least TCont Index 0 exist |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 231 | if err := onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep); err != nil { |
| 232 | logger.Errorw("tech-profile related FSM could not be started", |
| 233 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 234 | onuTP.procResult[uniTpKey] = err |
| 235 | return |
| 236 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 237 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 238 | //timeout or error detected |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 239 | logger.Errorw("tech-profile related configuration aborted on set", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 240 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 241 | |
| 242 | onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: Omci AniSideConfig failed %d on %s", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 243 | aUniID, onuTP.deviceID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 244 | //this issue here means that the AniConfigFsm has not finished successfully |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 245 | //which requires to reset it to allow for new usage, e.g. also on a different UNI |
| 246 | //(without that it would be reset on device down indication latest) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 247 | _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 248 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 249 | } |
| 250 | } else { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 251 | // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 252 | logger.Errorw("no Tcont/Gem data for this UNI found - abort", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 253 | "device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 254 | |
| 255 | onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: no Tcont/Gem data found for this UNI %d on %s", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 256 | aUniID, onuTP.deviceID) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 257 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 258 | } |
| 259 | } else { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 260 | logger.Errorw("no PonAni data for this UNI found - abort", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 261 | "device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 262 | |
| 263 | onuTP.procResult[uniTpKey] = fmt.Errorf("techProfile config aborted: no AniSide data found for this UNI %d on %s", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 264 | aUniID, onuTP.deviceID) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 265 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 269 | /* internal methods *********************/ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 270 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 271 | func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile( |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 272 | ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, aProcessingStep uint8) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 273 | var tpInst tp.TechProfile |
| 274 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 275 | uniTPKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 276 | |
| 277 | onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false |
| 278 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 279 | //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup |
| 280 | //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier> |
| 281 | subStringSlice := strings.Split(aPathString, "/") |
| 282 | if len(subStringSlice) <= 2 { |
| 283 | logger.Errorw("invalid path name format", |
| 284 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 285 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 286 | return |
| 287 | } |
| 288 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 289 | //at this point it is assumed that a new TechProfile is assigned to the UNI |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 290 | //expectation is that no TPIndication entry exists here, if exists and with the same TPId |
| 291 | // then we throw a warning, set an internal error and abort with error, |
| 292 | // which is later re-defined to success response to OLT adapter |
| 293 | // if TPId has changed, current data is removed (note that the ONU config state may be |
| 294 | // ambivalent in such a case) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 295 | if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 296 | logger.Warnw("Some active profile entry at reading new TechProfile", |
| 297 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID, |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 298 | "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID}) |
| 299 | if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 300 | // ProfId not changed - assume profile to be still the same |
| 301 | // anyway this should not appear after full support of profile (Gem/TCont) removal |
| 302 | logger.Warnw("New TechProfile already exists - aborting configuration", |
| 303 | log.Fields{"device-id": onuTP.deviceID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 304 | onuTP.tpProfileExists[uniTPKey] = true |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 305 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
| 306 | return |
| 307 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 308 | //delete on the mapUniTpIndication map not needed, just overwritten later |
| 309 | //delete on the PonAniConfig map should be safe, even if not existing |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 310 | delete(onuTP.mapPonAniConfig, uniTPKey) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 311 | } else { |
| 312 | // this is normal processing |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 313 | onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first! |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 316 | onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0] |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 317 | //note the limitation on ID range (probably even more limited) - based on usage within OMCI EntityID |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 318 | onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID |
| 319 | onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false |
| 320 | onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 321 | logger.Debugw("tech-profile path indications", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 322 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 323 | "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType, |
| 324 | "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 325 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 326 | Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 327 | if err == nil { |
| 328 | if Value != nil { |
| 329 | logger.Debugw("tech-profile read", |
| 330 | log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID}) |
| 331 | tpTmpBytes, _ := kvstore.ToByte(Value.Value) |
| 332 | |
| 333 | if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil { |
| 334 | logger.Errorw("TechProf - Failed to unmarshal tech-profile into tpInst", |
| 335 | log.Fields{"error": err, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 336 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 337 | return |
| 338 | } |
| 339 | logger.Debugw("TechProf - tpInst", log.Fields{"tpInst": tpInst}) |
| 340 | // access examples |
| 341 | logger.Debugw("TechProf content", log.Fields{"Name": tpInst.Name, |
| 342 | "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize, |
| 343 | "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold}) |
| 344 | } else { |
| 345 | logger.Errorw("No tech-profile found", |
| 346 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 347 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 348 | return |
| 349 | } |
| 350 | } else { |
| 351 | logger.Errorw("kvstore-get failed for path", |
| 352 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 353 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 354 | return |
| 355 | } |
| 356 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 357 | //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 358 | localMapGemPortParams := make(map[uint16]*gemPortParamStruct) |
| 359 | localMapGemPortParams[0] = &gemPortParamStruct{} |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 360 | onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams} |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 361 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 362 | //note: the code is currently restricted to one TCcont per Onu (index [0]) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 363 | //get the relevant values from the profile and store to mapPonAniConfig |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 364 | onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 365 | //maybe tCont scheduling not (yet) needed - just to basically have it for future |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 366 | // (would only be relevant in case of ONU-2G QOS configuration flexibility) |
| 367 | if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 368 | onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 1 //for the moment fixed value acc. G.988 //TODO: defines! |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 369 | } else { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 370 | //default profile defines "Hybrid" - which probably comes down to WRR with some weigthts for SP |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 371 | onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 372 | } |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 373 | loNumGemPorts := tpInst.NumGemPorts |
| 374 | loGemPortRead := false |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 375 | for pos, content := range tpInst.UpstreamGemPortAttributeList { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 376 | if uint32(pos) == loNumGemPorts { |
| 377 | logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts", |
| 378 | log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 379 | break |
| 380 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 381 | if pos == 0 { |
| 382 | //at least one upstream GemPort should always exist (else traffic profile makes no sense) |
| 383 | loGemPortRead = true |
| 384 | } else { |
| 385 | //for all further GemPorts we need to extend the mapGemPortParams |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 386 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)] = &gemPortParamStruct{} |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 387 | } |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 388 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortID = |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 389 | uint16(content.GemportID) |
| 390 | //direction can be correlated later with Downstream list, |
| 391 | // for now just assume bidirectional (upstream never exists alone) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 392 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].direction = 3 //as defined in G.988 |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 393 | // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7 |
| 394 | if 7 < content.PriorityQueue { |
| 395 | logger.Errorw("PonAniConfig reject on GemPortList - PrioQueue value invalid", |
| 396 | log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue}) |
| 397 | //remove PonAniConfig as done so far, delete map should be safe, even if not existing |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 398 | delete(onuTP.mapPonAniConfig, uniTPKey) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 399 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 400 | return |
| 401 | } |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 402 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].prioQueueIndex = |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 403 | uint8(content.PriorityQueue) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 404 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].pbitString = |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 405 | strings.TrimPrefix(content.PbitMap, binaryStringPrefix) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 406 | if content.AesEncryption == "True" { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 407 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortEncState = 1 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 408 | } else { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 409 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortEncState = 0 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 410 | } |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 411 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].discardPolicy = |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 412 | content.DiscardPolicy |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 413 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].queueSchedPolicy = |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 414 | content.SchedulingPolicy |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 415 | //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 416 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].queueWeight = |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 417 | uint8(content.Weight) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 418 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 419 | if !loGemPortRead { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 420 | logger.Errorw("PonAniConfig reject - no GemPort could be read from TechProfile", |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 421 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 422 | //remove PonAniConfig as done so far, delete map should be safe, even if not existing |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 423 | delete(onuTP.mapPonAniConfig, uniTPKey) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 424 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 425 | return |
| 426 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 427 | //TODO!! MC (downstream) GemPorts can be set using DownstreamGemPortAttributeList separately |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 428 | |
| 429 | //logger does not simply output the given structures, just give some example debug values |
| 430 | logger.Debugw("PonAniConfig read from TechProfile", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 431 | "device-id": onuTP.deviceID, "uni-id": aUniID, |
| 432 | "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 433 | for gemIndex, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 434 | logger.Debugw("PonAniConfig read from TechProfile", log.Fields{ |
| 435 | "GemIndex": gemIndex, |
| 436 | "GemPort": gemEntry.gemPortID, |
| 437 | "QueueScheduling": gemEntry.queueSchedPolicy}) |
| 438 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 439 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 440 | onuTP.chTpConfigProcessingStep <- aProcessingStep //done |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 443 | func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile( |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 444 | ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) error { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 445 | |
| 446 | //OMCI transfer of ANI data acc. to mapPonAniConfig |
| 447 | // also the FSM's are running in background, |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 448 | // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 449 | uniTPKey := uniTP{uniID: aUniID, tpID: aTpID} |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 450 | if onuTP.pAniConfigFsm == nil { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 451 | return onuTP.createAniConfigFsm(aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 452 | } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 453 | return onuTP.createAniConfigFsm(aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 454 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 455 | //AniConfigFsm already init |
| 456 | return onuTP.runAniConfigFsm(aniEvStart, aProcessingStep, aUniID, aTpID) |
| 457 | } |
| 458 | |
| 459 | // deleteTpResource removes Resources from the ONU's specified Uni |
| 460 | func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context, |
| 461 | aUniID uint8, aTpID uint8, aPathString string, aResource resourceEntry, aEntryID uint32, |
| 462 | wg *sync.WaitGroup) { |
| 463 | defer wg.Done() |
| 464 | logger.Debugw("will remove TP resources from ONU's UNI", log.Fields{ |
| 465 | "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "Resource": aResource}) |
| 466 | uniTPKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 467 | |
| 468 | if cResourceGemPort == aResource { |
| 469 | logger.Debugw("remove GemPort from the list of existing ones of the TP", log.Fields{ |
| 470 | "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID}) |
| 471 | |
| 472 | // check if the requested GemPort exists in the DB, indicate it to the FSM |
| 473 | // store locally to remove it from DB later on success |
| 474 | pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey] |
| 475 | if pLocAniConfigOnUni == nil { |
| 476 | // No relevant entry exists anymore - acknowledge success |
| 477 | logger.Debugw("AniConfig or GemEntry do not exists in DB", log.Fields{ |
| 478 | "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID}) |
| 479 | return |
| 480 | } |
| 481 | for gemIndex, gemEntry := range pLocAniConfigOnUni.mapGemPortParams { |
| 482 | if gemEntry.gemPortID == uint16(aEntryID) { |
| 483 | //GemEntry to be deleted found |
| 484 | gemEntry.removeIndex = gemIndex //store the index for later removal |
| 485 | onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemIndex] |
| 486 | logger.Debugw("Remove-GemEntry stored", log.Fields{ |
| 487 | "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemIndex": gemIndex}) |
| 488 | break //abort loop, always only one GemPort to remove |
| 489 | } |
| 490 | } |
| 491 | if onuTP.mapRemoveGemEntry[uniTPKey] == nil { |
| 492 | logger.Errorw("GemPort removal aborted - GemPort not found", |
| 493 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID}) |
| 494 | /* Do not set some error indication to the outside system interface on delete |
| 495 | assume there is nothing to be deleted internally and hope a new config request will recover the situation |
| 496 | onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s", |
| 497 | aEntryID, aUniID, onuTP.deviceID) |
| 498 | */ |
| 499 | return |
| 500 | } |
| 501 | if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig { |
| 502 | // check that the TpConfigRequest was done before |
| 503 | // -> that is implicitly done using the AniConfigFsm, |
| 504 | // which must be in the according state to remove something |
| 505 | // initiate OMCI GemPort related removal |
| 506 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep |
| 507 | // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep |
| 508 | if onuTP.pAniConfigFsm == nil { |
| 509 | logger.Errorw("abort GemPort removal - no AniConfigFsm available", |
| 510 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 511 | /* Do not set some error indication to the outside system interface on delete (see above) |
| 512 | onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s", |
| 513 | aUniID, onuTP.deviceID) |
| 514 | */ |
| 515 | //if the FSM is not valid, also TP related remove data should not be valid: |
| 516 | // remove GemPort from config DB |
| 517 | delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeIndex) |
| 518 | // remove the removeEntry |
| 519 | delete(onuTP.mapRemoveGemEntry, uniTPKey) |
| 520 | return |
| 521 | } |
| 522 | if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok { |
| 523 | logger.Errorw("abort GemPort removal - no AniConfigFsm available for this uni/tp", |
| 524 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID}) |
| 525 | /* Do not set some error indication to the outside system interface on delete (see above) |
| 526 | onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid", |
| 527 | aUniID, onuTP.deviceID, aTpID) |
| 528 | */ |
| 529 | //if the FSM is not valid, also TP related remove data should not be valid: |
| 530 | // remove GemPort from config DB |
| 531 | delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeIndex) |
| 532 | // remove the removeEntry |
| 533 | delete(onuTP.mapRemoveGemEntry, uniTPKey) |
| 534 | return |
| 535 | } |
| 536 | if nil != onuTP.runAniConfigFsm(aniEvRemGemiw, processingStep, aUniID, aTpID) { |
| 537 | //even if the FSM invocation did not work we don't indicate a problem within procResult |
| 538 | //errors could exist also because there was nothing to delete - so we just accept that as 'deleted' |
| 539 | //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented) |
| 540 | return |
| 541 | } |
| 542 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
| 543 | //timeout or error detected |
| 544 | logger.Errorw("GemPort removal aborted - Omci AniSideConfig failed", |
| 545 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 546 | //even if the FSM delete execution did not work we don't indicate a problem within procResult |
| 547 | //we should never respond to delete with error ... |
| 548 | //this issue here means that the AniConfigFsm has not finished successfully |
| 549 | //which requires to reset it to allow for new usage, e.g. also on a different UNI |
| 550 | //(without that it would be reset on device down indication latest) |
| 551 | _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset) |
| 552 | //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented) |
| 553 | return |
| 554 | } |
| 555 | } else { |
| 556 | logger.Debugw("uniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{ |
| 557 | "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.deviceReason}) |
| 558 | } |
| 559 | // remove GemPort from config DB |
| 560 | delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeIndex) |
| 561 | // remove the removeEntry |
| 562 | delete(onuTP.mapRemoveGemEntry, uniTPKey) |
| 563 | // deviceHandler StatusEvent (reason update) (see end of function) is only generated in case some element really was removed |
| 564 | } else { //if cResourceTcont == aResource { |
| 565 | logger.Debugw("reset TCont with AllocId", log.Fields{ |
| 566 | "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID}) |
| 567 | |
| 568 | // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM |
| 569 | pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey] |
| 570 | if pLocAniConfigOnUni == nil { |
| 571 | // No relevant entry exists anymore - acknowledge success |
| 572 | logger.Debugw("AniConfig or TCont entry do not exists in DB", log.Fields{ |
| 573 | "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID}) |
| 574 | return |
| 575 | } |
| 576 | if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) { |
| 577 | logger.Errorw("TCont removal aborted - indicated AllocId not found", |
| 578 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID}) |
| 579 | /* Do not set some error indication to the outside system interface on delete |
| 580 | assume there is nothing to be deleted internally and hope a new config request will recover the situation |
| 581 | onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s", |
| 582 | aEntryID, aUniID, onuTP.deviceID) |
| 583 | */ |
| 584 | return |
| 585 | } |
| 586 | //T-Cont to be reset found |
| 587 | logger.Debugw("Reset-T-Cont AllocId found - valid", log.Fields{ |
| 588 | "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID}) |
| 589 | if onuTP.pAniConfigFsm == nil { |
| 590 | logger.Errorw("no TCont removal on OMCI - no AniConfigFsm available", |
| 591 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 592 | /* Do not set some error indication to the outside system interface on delete (see above) |
| 593 | onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s", |
| 594 | aUniID, onuTP.deviceID) |
| 595 | */ |
| 596 | //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data |
| 597 | onuTP.clearAniSideConfig(aUniID, aTpID) |
| 598 | return |
| 599 | } |
| 600 | if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok { |
| 601 | logger.Errorw("no TCont removal on OMCI - no AniConfigFsm available for this uni/tp", |
| 602 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID}) |
| 603 | //even if the FSM invocation did not work we don't indicate a problem within procResult |
| 604 | //errors could exist also because there was nothing to delete - so we just accept that as 'deleted' |
| 605 | //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data |
| 606 | onuTP.clearAniSideConfig(aUniID, aTpID) |
| 607 | return |
| 608 | } |
| 609 | if onuTP.baseDeviceHandler.ReadyForSpecificOmciConfig { |
| 610 | // check that the TpConfigRequest was done before |
| 611 | // -> that is implicitly done using the AniConfigFsm, |
| 612 | // which must be in the according state to remove something |
| 613 | // initiate OMCI TCont related cleanup |
| 614 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep |
| 615 | // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep |
| 616 | if nil != onuTP.runAniConfigFsm(aniEvRemTcontPath, processingStep, aUniID, aTpID) { |
| 617 | //even if the FSM invocation did not work we don't indicate a problem within procResult |
| 618 | //errors could exist also because there was nothing to delete - so we just accept that as 'deleted' |
| 619 | //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented) |
| 620 | return |
| 621 | } |
| 622 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
| 623 | //timeout or error detected |
| 624 | logger.Errorw("TCont cleanup aborted - Omci AniSideConfig failed", |
| 625 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 626 | //even if the FSM delete execution did not work we don't indicate a problem within procResult |
| 627 | //we should never respond to delete with error ... |
| 628 | //this issue here means that the AniConfigFsm has not finished successfully |
| 629 | //which requires to reset it to allow for new usage, e.g. also on a different UNI |
| 630 | //(without that it would be reset on device down indication latest) |
| 631 | _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset) |
| 632 | //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented) |
| 633 | return |
| 634 | } |
| 635 | } else { |
| 636 | logger.Debugw("uniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{ |
| 637 | "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.deviceReason}) |
| 638 | } |
| 639 | //clear the internal store profile data |
| 640 | onuTP.clearAniSideConfig(aUniID, aTpID) |
| 641 | // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created |
| 642 | // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting |
| 643 | _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset) |
| 644 | } |
| 645 | // generate deviceHandler StatusEvent in case the FSM was not invoked |
| 646 | go onuTP.baseDeviceHandler.deviceProcStatusUpdate(OmciAniResourceRemoved) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 649 | func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion( |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 650 | ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 651 | select { |
| 652 | case <-ctx.Done(): |
| 653 | logger.Warnw("processing not completed in-time: force release of TpProcMutex!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 654 | log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 655 | return false |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 656 | case rxStep := <-aChTpProcessingStep: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 657 | if rxStep == aProcessingStep { |
| 658 | return true |
| 659 | } |
| 660 | //all other values are not accepted - including 0 for error indication |
| 661 | logger.Warnw("Invalid processing step received: abort and force release of TpProcMutex!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 662 | log.Fields{"device-id": onuTP.deviceID, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 663 | "wantedStep": aProcessingStep, "haveStep": rxStep}) |
| 664 | return false |
| 665 | } |
| 666 | } |
| 667 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 668 | // createUniLockFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 669 | func (onuTP *onuUniTechProf) createAniConfigFsm(aUniID uint8, aTpID uint8, |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 670 | apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) error { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 671 | logger.Debugw("createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 672 | chAniConfigFsm := make(chan Message, 2048) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 673 | uniTPKey := uniTP{uniID: aUniID, tpID: aTpID} |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 674 | pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(true) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 675 | if pDevEntry == nil { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 676 | logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 677 | return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 678 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 679 | pAniCfgFsm := newUniPonAniConfigFsm(pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP, |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 680 | pDevEntry.pOnuDB, aTpID, devEvent, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 681 | "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 682 | if pAniCfgFsm == nil { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 683 | logger.Errorw("AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 684 | return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 685 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 686 | if onuTP.pAniConfigFsm == nil { |
| 687 | onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 688 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 689 | onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm |
| 690 | return onuTP.runAniConfigFsm(aniEvStart, aProcessingStep, aUniID, aTpID) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 691 | } |
| 692 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 693 | // runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 694 | func (onuTP *onuUniTechProf) runAniConfigFsm(aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 695 | /* Uni related ANI config procedure - |
| 696 | ***** should run via 'aniConfigDone' state and generate the argument requested event ***** |
| 697 | */ |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 698 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 699 | |
| 700 | pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 701 | if pACStatemachine != nil { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 702 | if aEvent == aniEvStart { |
| 703 | if !pACStatemachine.Is(aniStDisabled) { |
| 704 | logger.Errorw("wrong state of AniConfigFSM to start - want: Disabled", log.Fields{ |
| 705 | "have": pACStatemachine.Current(), "device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 706 | // maybe try a FSM reset and then again ... - TODO!!! |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 707 | return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 708 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 709 | } else if !pACStatemachine.Is(aniStConfigDone) { |
| 710 | logger.Errorw("wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 711 | "have": pACStatemachine.Current(), "device-id": onuTP.deviceID}) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 712 | return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 713 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 714 | //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config) |
| 715 | onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep) |
| 716 | if err := pACStatemachine.Event(aEvent); err != nil { |
| 717 | logger.Errorw("AniConfigFSM: can't trigger event", log.Fields{"err": err}) |
| 718 | return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID) |
| 719 | } |
| 720 | /***** AniConfigFSM event notified */ |
| 721 | logger.Debugw("AniConfigFSM event notified", log.Fields{ |
| 722 | "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent}) |
| 723 | return nil |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 724 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 725 | logger.Errorw("AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID}) |
| 726 | // maybe try a FSM reset and then again ... - TODO!!! |
| 727 | return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 728 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 729 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 730 | // clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID |
| 731 | func (onuTP *onuUniTechProf) clearAniSideConfig(aUniID uint8, aTpID uint8) { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 732 | logger.Debugw("removing TpIndication and PonAniConfig data", log.Fields{ |
| 733 | "device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 734 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 735 | |
| 736 | onuTP.mutexTPState.Lock() |
| 737 | defer onuTP.mutexTPState.Unlock() |
| 738 | delete(onuTP.mapUniTpIndication, uniTpKey) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 739 | //delete on the PonAniConfig map of this UNI should be safe, even if not existing |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 740 | delete(onuTP.mapPonAniConfig, uniTpKey) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 741 | } |
| 742 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 743 | // setConfigDone sets the requested techProfile config state (if possible) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 744 | func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) { |
| 745 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 746 | onuTP.mutexTPState.Lock() |
| 747 | defer onuTP.mutexTPState.Unlock() |
| 748 | if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP { |
| 749 | onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 750 | } //else: the state is just ignored (does not exist) |
| 751 | } |
| 752 | |
| 753 | // getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 754 | func (onuTP *onuUniTechProf) getTechProfileDone(aUniID uint8, aTpID uint8) bool { |
| 755 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 756 | onuTP.mutexTPState.Lock() |
| 757 | defer onuTP.mutexTPState.Unlock() |
| 758 | if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP { |
| 759 | if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID { |
| 760 | if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 761 | logger.Debugw("TechProfile not relevant for requested flow config - waiting on delete", |
| 762 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 763 | return false //still waiting for removal of this techProfile first |
| 764 | } |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 765 | return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | //for all other constellations indicate false = Config not done |
| 769 | return false |
| 770 | } |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 771 | |
| 772 | // setProfileToDelete sets the requested techProfile toDelete state (if possible) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 773 | func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) { |
| 774 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 775 | onuTP.mutexTPState.Lock() |
| 776 | defer onuTP.mutexTPState.Unlock() |
| 777 | if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP { |
| 778 | onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 779 | } //else: the state is just ignored (does not exist) |
| 780 | } |