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 | |
| 34 | const cBasePathTechProfileKVStore = "service/voltha/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 |
| 75 | } |
| 76 | |
| 77 | //refers to one tcont and its properties and all assigned GemPorts and their properties |
| 78 | type tcontGemList struct { |
| 79 | tcontParams tcontParamStruct |
| 80 | mapGemPortParams map[uint16]*gemPortParamStruct |
| 81 | } |
| 82 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 83 | // refers a unique combination of uniID and tpID for a given ONU. |
| 84 | type uniTP struct { |
| 85 | uniID uint8 |
| 86 | tpID uint8 |
| 87 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 88 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 89 | //onuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU |
| 90 | type onuUniTechProf struct { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 91 | baseDeviceHandler *deviceHandler |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 92 | deviceID string |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 93 | tpProcMutex sync.RWMutex |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 94 | techProfileKVStore *db.Backend |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 95 | chTpConfigProcessingStep chan uint8 |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 96 | mapUniTpIndication map[uniTP]*tTechProfileIndication //use pointer values to ease assignments to the map |
| 97 | mapPonAniConfig map[uniTP]*tcontGemList //per UNI: use pointer values to ease assignments to the map |
| 98 | pAniConfigFsm map[uniTP]*uniPonAniConfigFsm |
| 99 | procResult map[uniTP]error //error indication of processing |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 100 | mutexTPState sync.Mutex |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 101 | tpProfileExists map[uniTP]bool |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 104 | //newOnuUniTechProf returns the instance of a OnuUniTechProf |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 105 | //(one instance per ONU/deviceHandler for all possible UNI's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 106 | func newOnuUniTechProf(ctx context.Context, aDeviceHandler *deviceHandler) *onuUniTechProf { |
| 107 | logger.Infow("init-OnuUniTechProf", log.Fields{"device-id": aDeviceHandler.deviceID}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 108 | var onuTP onuUniTechProf |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 109 | onuTP.baseDeviceHandler = aDeviceHandler |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 110 | onuTP.deviceID = aDeviceHandler.deviceID |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 111 | onuTP.tpProcMutex = sync.RWMutex{} |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 112 | onuTP.chTpConfigProcessingStep = make(chan uint8) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 113 | onuTP.mapUniTpIndication = make(map[uniTP]*tTechProfileIndication) |
| 114 | onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList) |
| 115 | onuTP.procResult = make(map[uniTP]error) |
| 116 | onuTP.tpProfileExists = make(map[uniTP]bool) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 117 | onuTP.techProfileKVStore = aDeviceHandler.setBackend(cBasePathTechProfileKVStore) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 118 | if onuTP.techProfileKVStore == nil { |
| 119 | logger.Errorw("Can't access techProfileKVStore - no backend connection to service", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 120 | log.Fields{"device-id": aDeviceHandler.deviceID, "service": cBasePathTechProfileKVStore}) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 121 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 122 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 123 | return &onuTP |
| 124 | } |
| 125 | |
| 126 | // lockTpProcMutex locks OnuUniTechProf processing mutex |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 127 | func (onuTP *onuUniTechProf) lockTpProcMutex() { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 128 | onuTP.tpProcMutex.Lock() |
| 129 | } |
| 130 | |
| 131 | // unlockTpProcMutex unlocks OnuUniTechProf processing mutex |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 132 | func (onuTP *onuUniTechProf) unlockTpProcMutex() { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 133 | onuTP.tpProcMutex.Unlock() |
| 134 | } |
| 135 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 136 | // resetTpProcessingErrorIndication resets the internal error indication |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 137 | // 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^] | 138 | func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) { |
| 139 | onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 142 | func (onuTP *onuUniTechProf) getTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error { |
| 143 | return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | // configureUniTp checks existing tp resources to delete and starts the corresponding OMCI configuation of the UNI port |
| 147 | // all possibly blocking processing must be run in background to allow for deadline supervision! |
| 148 | // but take care on sequential background processing when needed (logical dependencies) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 149 | // use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 150 | func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 151 | aUniID uint8, aPathString string, wg *sync.WaitGroup) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 152 | defer wg.Done() //always decrement the waitGroup on return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 153 | logger.Debugw("configure the Uni according to TpPath", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 154 | "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 155 | tpID, err := GetTpIDFromTpPath(aPathString) |
| 156 | uniTpKey := uniTP{uniID: aUniID, tpID: tpID} |
| 157 | if err != nil { |
| 158 | logger.Errorw("error-extracting-tp-id-from-tp-path", log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString}) |
| 159 | return |
| 160 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 161 | if onuTP.techProfileKVStore == nil { |
| 162 | logger.Debug("techProfileKVStore not set - abort") |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 163 | onuTP.procResult[uniTpKey] = errors.New("techProfile config aborted: techProfileKVStore not set") |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 164 | return |
| 165 | } |
| 166 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 167 | //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] | 168 | var pCurrentUniPort *onuUniPort |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 169 | for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap { |
| 170 | // only if this port is validated for operState transfer |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 171 | if uniPort.uniID == aUniID { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 172 | pCurrentUniPort = uniPort |
| 173 | break //found - end search loop |
| 174 | } |
| 175 | } |
| 176 | if pCurrentUniPort == nil { |
| 177 | logger.Errorw("TechProfile configuration aborted: requested uniID not found in PortDB", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 178 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 179 | 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] | 180 | aUniID, onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 181 | return |
| 182 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 183 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 184 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 185 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 186 | //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called |
| 187 | // in case the KVPath has changed for the given UNI, |
| 188 | // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing |
| 189 | // (ANI) configuration of this port has to be removed first |
| 190 | // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well) |
| 191 | // existence of configuration can be detected based on tp stored TCONT's |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 192 | //TODO: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 193 | /* if tcontMap not empty { |
| 194 | go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 195 | if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 196 | //timeout or error detected |
| 197 | return |
| 198 | } |
| 199 | clear tcontMap |
| 200 | } |
| 201 | |
| 202 | processingStep++ |
| 203 | */ |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 204 | go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 205 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 206 | //timeout or error detected |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 207 | if onuTP.tpProfileExists[uniTpKey] { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 208 | //ignore the internal error in case the new profile is already configured |
| 209 | // and abort the processing here |
| 210 | return |
| 211 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 212 | logger.Debugw("tech-profile related configuration aborted on read", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 213 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 214 | 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] | 215 | aUniID, onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 216 | return |
| 217 | } |
| 218 | |
| 219 | processingStep++ |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 220 | |
| 221 | valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey] |
| 222 | |
| 223 | if existPA { |
| 224 | if valuePA != nil { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 225 | //Config data for this uni and and at least TCont Index 0 exist |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 226 | go onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 227 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 228 | //timeout or error detected |
| 229 | logger.Debugw("tech-profile related configuration aborted on set", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 230 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 231 | |
| 232 | 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] | 233 | aUniID, onuTP.deviceID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 234 | //this issue here means that the AniConfigFsm has not finished successfully |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 235 | //which requires to reset it to allow for new usage, e.g. also on a different UNI |
| 236 | //(without that it would be reset on device down indication latest) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 237 | _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 238 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 239 | } |
| 240 | } else { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 241 | // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed) |
| 242 | logger.Debugw("no Tcont/Gem data for this UNI found - abort", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 243 | "device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 244 | |
| 245 | 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] | 246 | aUniID, onuTP.deviceID) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 247 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 248 | } |
| 249 | } else { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 250 | logger.Debugw("no PonAni data for this UNI found - abort", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 251 | "device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 252 | |
| 253 | 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] | 254 | aUniID, onuTP.deviceID) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 255 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 259 | /* internal methods *********************/ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 260 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 261 | func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile( |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 262 | ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, aProcessingStep uint8) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 263 | var tpInst tp.TechProfile |
| 264 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 265 | uniTPKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 266 | |
| 267 | onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false |
| 268 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 269 | //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup |
| 270 | //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier> |
| 271 | subStringSlice := strings.Split(aPathString, "/") |
| 272 | if len(subStringSlice) <= 2 { |
| 273 | logger.Errorw("invalid path name format", |
| 274 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 275 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 276 | return |
| 277 | } |
| 278 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 279 | //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] | 280 | //expectation is that no TPIndication entry exists here, if exists and with the same TPId |
| 281 | // then we throw a warning, set an internal error and abort with error, |
| 282 | // which is later re-defined to success response to OLT adapter |
| 283 | // if TPId has changed, current data is removed (note that the ONU config state may be |
| 284 | // ambivalent in such a case) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 285 | if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 286 | logger.Warnw("Some active profile entry at reading new TechProfile", |
| 287 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID, |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 288 | "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID}) |
| 289 | if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 290 | // ProfId not changed - assume profile to be still the same |
| 291 | // anyway this should not appear after full support of profile (Gem/TCont) removal |
| 292 | logger.Warnw("New TechProfile already exists - aborting configuration", |
| 293 | log.Fields{"device-id": onuTP.deviceID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 294 | onuTP.tpProfileExists[uniTPKey] = true |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 295 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
| 296 | return |
| 297 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 298 | //delete on the mapUniTpIndication map not needed, just overwritten later |
| 299 | //delete on the PonAniConfig map should be safe, even if not existing |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 300 | delete(onuTP.mapPonAniConfig, uniTPKey) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 301 | } else { |
| 302 | // this is normal processing |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 303 | onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first! |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 306 | onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0] |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 307 | //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^] | 308 | onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID |
| 309 | onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false |
| 310 | onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 311 | logger.Debugw("tech-profile path indications", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 312 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 313 | "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType, |
| 314 | "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 315 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 316 | Value, err := onuTP.techProfileKVStore.Get(ctx, aPathString) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 317 | if err == nil { |
| 318 | if Value != nil { |
| 319 | logger.Debugw("tech-profile read", |
| 320 | log.Fields{"Key": Value.Key, "device-id": onuTP.deviceID}) |
| 321 | tpTmpBytes, _ := kvstore.ToByte(Value.Value) |
| 322 | |
| 323 | if err = json.Unmarshal(tpTmpBytes, &tpInst); err != nil { |
| 324 | logger.Errorw("TechProf - Failed to unmarshal tech-profile into tpInst", |
| 325 | log.Fields{"error": err, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 326 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 327 | return |
| 328 | } |
| 329 | logger.Debugw("TechProf - tpInst", log.Fields{"tpInst": tpInst}) |
| 330 | // access examples |
| 331 | logger.Debugw("TechProf content", log.Fields{"Name": tpInst.Name, |
| 332 | "MaxGemPayloadSize": tpInst.InstanceCtrl.MaxGemPayloadSize, |
| 333 | "DownstreamGemDiscardmaxThreshold": tpInst.DownstreamGemPortAttributeList[0].DiscardConfig.MaxThreshold}) |
| 334 | } else { |
| 335 | logger.Errorw("No tech-profile found", |
| 336 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 337 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 338 | return |
| 339 | } |
| 340 | } else { |
| 341 | logger.Errorw("kvstore-get failed for path", |
| 342 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 343 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 344 | return |
| 345 | } |
| 346 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 347 | //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 348 | localMapGemPortParams := make(map[uint16]*gemPortParamStruct) |
| 349 | localMapGemPortParams[0] = &gemPortParamStruct{} |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 350 | onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams} |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 351 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 352 | //note: the code is currently restricted to one TCcont per Onu (index [0]) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 353 | //get the relevant values from the profile and store to mapPonAniConfig |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 354 | onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 355 | //maybe tCont scheduling not (yet) needed - just to basically have it for future |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 356 | // (would only be relevant in case of ONU-2G QOS configuration flexibility) |
| 357 | if tpInst.UsScheduler.QSchedPolicy == "StrictPrio" { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 358 | 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] | 359 | } else { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 360 | //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^] | 361 | onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 362 | } |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 363 | loNumGemPorts := tpInst.NumGemPorts |
| 364 | loGemPortRead := false |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 365 | for pos, content := range tpInst.UpstreamGemPortAttributeList { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 366 | if uint32(pos) == loNumGemPorts { |
| 367 | logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts", |
| 368 | log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 369 | break |
| 370 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 371 | if pos == 0 { |
| 372 | //at least one upstream GemPort should always exist (else traffic profile makes no sense) |
| 373 | loGemPortRead = true |
| 374 | } else { |
| 375 | //for all further GemPorts we need to extend the mapGemPortParams |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 376 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)] = &gemPortParamStruct{} |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 377 | } |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 378 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortID = |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 379 | uint16(content.GemportID) |
| 380 | //direction can be correlated later with Downstream list, |
| 381 | // for now just assume bidirectional (upstream never exists alone) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 382 | 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] | 383 | // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7 |
| 384 | if 7 < content.PriorityQueue { |
| 385 | logger.Errorw("PonAniConfig reject on GemPortList - PrioQueue value invalid", |
| 386 | log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQueue}) |
| 387 | //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^] | 388 | delete(onuTP.mapPonAniConfig, uniTPKey) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 389 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 390 | return |
| 391 | } |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 392 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].prioQueueIndex = |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 393 | uint8(content.PriorityQueue) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 394 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].pbitString = |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 395 | strings.TrimPrefix(content.PbitMap, binaryStringPrefix) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 396 | if content.AesEncryption == "True" { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 397 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortEncState = 1 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 398 | } else { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 399 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].gemPortEncState = 0 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 400 | } |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 401 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].discardPolicy = |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 402 | content.DiscardPolicy |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 403 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].queueSchedPolicy = |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 404 | content.SchedulingPolicy |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 405 | //'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^] | 406 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(pos)].queueWeight = |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 407 | uint8(content.Weight) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 408 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 409 | if !loGemPortRead { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 410 | logger.Errorw("PonAniConfig reject - no GemPort could be read from TechProfile", |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 411 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 412 | //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^] | 413 | delete(onuTP.mapPonAniConfig, uniTPKey) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 414 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 415 | return |
| 416 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 417 | //TODO!! MC (downstream) GemPorts can be set using DownstreamGemPortAttributeList separately |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 418 | |
| 419 | //logger does not simply output the given structures, just give some example debug values |
| 420 | logger.Debugw("PonAniConfig read from TechProfile", log.Fields{ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 421 | "device-id": onuTP.deviceID, |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 422 | "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID}) |
| 423 | for gemIndex, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 424 | logger.Debugw("PonAniConfig read from TechProfile", log.Fields{ |
| 425 | "GemIndex": gemIndex, |
| 426 | "GemPort": gemEntry.gemPortID, |
| 427 | "QueueScheduling": gemEntry.queueSchedPolicy}) |
| 428 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 429 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 430 | onuTP.chTpConfigProcessingStep <- aProcessingStep //done |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 433 | func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile( |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 434 | ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 435 | |
| 436 | //OMCI transfer of ANI data acc. to mapPonAniConfig |
| 437 | // also the FSM's are running in background, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 438 | // hence we have to make sure they indicate 'success' success on chTpConfigProcessingStep with aProcessingStep |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 439 | uniTPKey := uniTP{uniID: aUniID, tpID: aTpID} |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 440 | if onuTP.pAniConfigFsm == nil { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 441 | onuTP.createAniConfigFsm(aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep) |
| 442 | } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok { |
| 443 | onuTP.createAniConfigFsm(aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 444 | } else { //AniConfigFsm already init |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 445 | onuTP.runAniConfigFsm(aProcessingStep, aUniID, aTpID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 449 | func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion( |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 450 | ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 451 | select { |
| 452 | case <-ctx.Done(): |
| 453 | logger.Warnw("processing not completed in-time: force release of TpProcMutex!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 454 | log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 455 | return false |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 456 | case rxStep := <-aChTpProcessingStep: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 457 | if rxStep == aProcessingStep { |
| 458 | return true |
| 459 | } |
| 460 | //all other values are not accepted - including 0 for error indication |
| 461 | logger.Warnw("Invalid processing step received: abort and force release of TpProcMutex!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 462 | log.Fields{"device-id": onuTP.deviceID, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 463 | "wantedStep": aProcessingStep, "haveStep": rxStep}) |
| 464 | return false |
| 465 | } |
| 466 | } |
| 467 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 468 | // 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^] | 469 | func (onuTP *onuUniTechProf) createAniConfigFsm(aUniID uint8, aTpID uint8, |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 470 | apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 471 | logger.Debugw("createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 472 | chAniConfigFsm := make(chan Message, 2048) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 473 | uniTPKey := uniTP{uniID: aUniID, tpID: aTpID} |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 474 | pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(true) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 475 | if pDevEntry == nil { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 476 | logger.Errorw("No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 477 | return |
| 478 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 479 | pAniCfgFsm := newUniPonAniConfigFsm(pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP, |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 480 | pDevEntry.pOnuDB, aTpID, devEvent, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 481 | "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 482 | if pAniCfgFsm != nil { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 483 | if onuTP.pAniConfigFsm == nil { |
| 484 | onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm) |
| 485 | } |
| 486 | onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm |
| 487 | onuTP.runAniConfigFsm(aProcessingStep, aUniID, aTpID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 488 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 489 | logger.Errorw("AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 493 | // deleteTpResource removes Resources from the ONU's specified Uni |
| 494 | func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context, |
| 495 | aUniID uint8, aPathString string, aResource resourceEntry, aEntryID uint32, |
| 496 | wg *sync.WaitGroup) { |
| 497 | defer wg.Done() |
| 498 | logger.Debugw("this would remove TP resources from ONU's UNI", log.Fields{ |
| 499 | "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "Resource": aResource}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 500 | tpID, err := GetTpIDFromTpPath(aPathString) |
| 501 | if err != nil { |
| 502 | logger.Errorw("error-extracting-tp-id-from-tp-path", log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString}) |
| 503 | return |
| 504 | } |
| 505 | uniTpKey := uniTP{uniID: aUniID, tpID: tpID} |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 506 | if cResourceGemPort == aResource { |
| 507 | logger.Debugw("remove GemPort from the list of existing ones of the TP", log.Fields{ |
| 508 | "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "entry": aEntryID}) |
| 509 | // check if the requested GemPort exists in the DB |
| 510 | // check that the TpConfigRequest was done |
| 511 | // initiate OMCI GemPort related removal |
| 512 | // remove GemPort from config DB |
| 513 | // dev reason update? (for the moment not yet done here!) |
| 514 | } else { //if cResourceTcont == aResource { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 515 | //the TechProfile indicated by path is considered for removal |
| 516 | // by now we do not clear the OMCI related configuration (to be done later) |
| 517 | // so we use this position here just to remove the internal stored profile data |
| 518 | // (needed for checking the existence of the TechProfile after some profile delete) |
| 519 | // at the oment we only admit 1 TechProfile (T-Cont), so by now we can just remove the only existing TechProfile |
| 520 | // TODO: To be updated with multi-T-Cont implementation |
| 521 | logger.Debugw("DeleteTcont clears the existing internal profile", log.Fields{ |
| 522 | "device-id": onuTP.deviceID, "uniID": aUniID, "path": aPathString, "Resource": aResource}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 523 | |
| 524 | onuTP.clearAniSideConfig(aUniID, tpID) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 525 | // reset also the FSM in order to admit a new OMCI configuration in case a new profile is created |
| 526 | // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting |
| 527 | if onuTP.pAniConfigFsm != nil { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 528 | _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | //TODO!!! - the real processing could look like that (for starting the removal, where the clearAniSideConfig is done implicitly): |
| 532 | //delete the given resource from ONU OMCI config and data base - as background routine |
| 533 | /* |
| 534 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep |
| 535 | go onuTp.deleteAniResource(ctx, processingStep) |
| 536 | if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) { |
| 537 | //timeout or error detected |
| 538 | return |
| 539 | } |
| 540 | */ |
| 541 | } |
| 542 | //if implemented, the called FSM would generate an adequate event if config has been done, |
| 543 | // by now we just stimulate this event here as 'done' - TODO!!: to be removed after full implementation |
| 544 | go onuTP.baseDeviceHandler.deviceProcStatusUpdate(OmciAniResourceRemoved) |
| 545 | } |
| 546 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 547 | // runAniConfigFsm starts 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^] | 548 | func (onuTP *onuUniTechProf) runAniConfigFsm(aProcessingStep uint8, aUniID uint8, aTpID uint8) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 549 | /* Uni related ANI config procedure - |
| 550 | ***** should run via 'aniConfigDone' state and generate the argument requested event ***** |
| 551 | */ |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 552 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 553 | |
| 554 | pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 555 | if pACStatemachine != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 556 | if pACStatemachine.Is(aniStDisabled) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 557 | //FSM init requirement to get informed abou FSM completion! (otherwise timeout of the TechProf config) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 558 | onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 559 | if err := pACStatemachine.Event(aniEvStart); err != nil { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 560 | logger.Warnw("AniConfigFSM: can't start", log.Fields{"err": err}) |
| 561 | // maybe try a FSM reset and then again ... - TODO!!! |
| 562 | } else { |
| 563 | /***** AniConfigFSM started */ |
| 564 | logger.Debugw("AniConfigFSM started", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 565 | "state": pACStatemachine.Current(), "device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 566 | } |
| 567 | } else { |
| 568 | logger.Warnw("wrong state of AniConfigFSM - want: disabled", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 569 | "have": pACStatemachine.Current(), "device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 570 | // maybe try a FSM reset and then again ... - TODO!!! |
| 571 | } |
| 572 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 573 | logger.Errorw("AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 574 | // maybe try a FSM reset and then again ... - TODO!!! |
| 575 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 576 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 577 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 578 | // clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID |
| 579 | func (onuTP *onuUniTechProf) clearAniSideConfig(aUniID uint8, aTpID uint8) { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 580 | logger.Debugw("removing TpIndication and PonAniConfig data", log.Fields{ |
| 581 | "device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 582 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 583 | |
| 584 | onuTP.mutexTPState.Lock() |
| 585 | defer onuTP.mutexTPState.Unlock() |
| 586 | delete(onuTP.mapUniTpIndication, uniTpKey) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 587 | //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^] | 588 | delete(onuTP.mapPonAniConfig, uniTpKey) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 589 | } |
| 590 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 591 | // setConfigDone sets the requested techProfile config state (if possible) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 592 | func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) { |
| 593 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 594 | onuTP.mutexTPState.Lock() |
| 595 | defer onuTP.mutexTPState.Unlock() |
| 596 | if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP { |
| 597 | onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 598 | } //else: the state is just ignored (does not exist) |
| 599 | } |
| 600 | |
| 601 | // 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^] | 602 | func (onuTP *onuUniTechProf) getTechProfileDone(aUniID uint8, aTpID uint8) bool { |
| 603 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 604 | onuTP.mutexTPState.Lock() |
| 605 | defer onuTP.mutexTPState.Unlock() |
| 606 | if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP { |
| 607 | if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID { |
| 608 | if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 609 | logger.Debugw("TechProfile not relevant for requested flow config - waiting on delete", |
| 610 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 611 | return false //still waiting for removal of this techProfile first |
| 612 | } |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 613 | return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | //for all other constellations indicate false = Config not done |
| 617 | return false |
| 618 | } |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 619 | |
| 620 | // setProfileToDelete sets the requested techProfile toDelete state (if possible) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame^] | 621 | func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) { |
| 622 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 623 | onuTP.mutexTPState.Lock() |
| 624 | defer onuTP.mutexTPState.Unlock() |
| 625 | if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP { |
| 626 | onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 627 | } //else: the state is just ignored (does not exist) |
| 628 | } |