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" |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 22 | "fmt" |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 23 | "strconv" |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 24 | "strings" |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 25 | "sync" |
| 26 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 27 | "github.com/opencord/voltha-protos/v4/go/tech_profile" |
| 28 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 29 | "github.com/opencord/voltha-lib-go/v5/pkg/log" |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 30 | ) |
| 31 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 32 | //definitions for TechProfileProcessing - copied from OltAdapter:openolt_flowmgr.go |
| 33 | // could perhaps be defined more globally |
| 34 | const ( |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 35 | // binaryStringPrefix is binary string prefix |
| 36 | binaryStringPrefix = "0b" |
| 37 | // binaryBit1 is binary bit 1 expressed as a character |
| 38 | //binaryBit1 = '1' |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 39 | ) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 40 | |
| 41 | type resourceEntry int |
| 42 | |
| 43 | const ( |
| 44 | cResourceGemPort resourceEntry = 1 |
| 45 | cResourceTcont resourceEntry = 2 |
| 46 | ) |
| 47 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 48 | type tTechProfileIndication struct { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 49 | techProfileType string |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 50 | techProfileID uint8 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 51 | techProfileConfigDone bool |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 52 | techProfileToDelete bool |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | type tcontParamStruct struct { |
| 56 | allocID uint16 |
| 57 | schedPolicy uint8 |
| 58 | } |
| 59 | type gemPortParamStruct struct { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 60 | //ponOmciCC bool |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 61 | gemPortID uint16 |
| 62 | direction uint8 |
| 63 | gemPortEncState uint8 |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 64 | prioQueueIndex uint8 |
| 65 | pbitString string |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 66 | discardPolicy string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 67 | //could also be a queue specific parameter, not used that way here |
| 68 | //maxQueueSize uint16 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 69 | queueSchedPolicy string |
| 70 | queueWeight uint8 |
Himani Chawla | 1c13690 | 2020-12-10 16:30:59 +0530 | [diff] [blame] | 71 | removeGemID uint16 |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 72 | isMulticast bool |
| 73 | //TODO check if this has any value/difference from gemPortId |
| 74 | multicastGemPortID uint16 |
| 75 | staticACL string |
| 76 | dynamicACL string |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | //refers to one tcont and its properties and all assigned GemPorts and their properties |
| 80 | type tcontGemList struct { |
| 81 | tcontParams tcontParamStruct |
| 82 | mapGemPortParams map[uint16]*gemPortParamStruct |
| 83 | } |
| 84 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 85 | // refers a unique combination of uniID and tpID for a given ONU. |
| 86 | type uniTP struct { |
| 87 | uniID uint8 |
| 88 | tpID uint8 |
| 89 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 90 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 91 | //onuUniTechProf structure holds information about the TechProfiles attached to Uni Ports of the ONU |
| 92 | type onuUniTechProf struct { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 93 | baseDeviceHandler *deviceHandler |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 94 | deviceID string |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 95 | tpProcMutex sync.RWMutex |
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 |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 101 | mutexTPState sync.RWMutex |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 102 | tpProfileExists map[uniTP]bool |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 103 | tpProfileResetting map[uniTP]bool |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 104 | mapRemoveGemEntry map[uniTP]*gemPortParamStruct //per UNI: pointer to GemEntry to be removed |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 105 | } |
| 106 | |
ozgecanetsia | 72e1c9f | 2021-05-26 17:26:29 +0300 | [diff] [blame] | 107 | func (onuTP *onuUniTechProf) multicastConfiguredForOtherUniTps(ctx context.Context, uniTpKey uniTP) bool { |
| 108 | for _, aniFsm := range onuTP.pAniConfigFsm { |
| 109 | if aniFsm.uniTpKey.uniID == uniTpKey.uniID && aniFsm.uniTpKey.tpID == uniTpKey.tpID { |
| 110 | continue |
| 111 | } |
| 112 | if aniFsm.hasMulticastGem(ctx) { |
| 113 | return true |
| 114 | } |
| 115 | } |
| 116 | return false |
| 117 | } |
| 118 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 119 | //newOnuUniTechProf returns the instance of a OnuUniTechProf |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 120 | //(one instance per ONU/deviceHandler for all possible UNI's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 121 | func newOnuUniTechProf(ctx context.Context, aDeviceHandler *deviceHandler) *onuUniTechProf { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 122 | logger.Debugw(ctx, "init-OnuUniTechProf", log.Fields{"device-id": aDeviceHandler.deviceID}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 123 | var onuTP onuUniTechProf |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 124 | onuTP.baseDeviceHandler = aDeviceHandler |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 125 | onuTP.deviceID = aDeviceHandler.deviceID |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 126 | onuTP.chTpConfigProcessingStep = make(chan uint8) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 127 | onuTP.mapUniTpIndication = make(map[uniTP]*tTechProfileIndication) |
| 128 | onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList) |
| 129 | onuTP.procResult = make(map[uniTP]error) |
| 130 | onuTP.tpProfileExists = make(map[uniTP]bool) |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 131 | onuTP.tpProfileResetting = make(map[uniTP]bool) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 132 | onuTP.mapRemoveGemEntry = make(map[uniTP]*gemPortParamStruct) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 133 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 134 | return &onuTP |
| 135 | } |
| 136 | |
| 137 | // lockTpProcMutex locks OnuUniTechProf processing mutex |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 138 | func (onuTP *onuUniTechProf) lockTpProcMutex() { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 139 | onuTP.tpProcMutex.Lock() |
| 140 | } |
| 141 | |
| 142 | // unlockTpProcMutex unlocks OnuUniTechProf processing mutex |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 143 | func (onuTP *onuUniTechProf) unlockTpProcMutex() { |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 144 | onuTP.tpProcMutex.Unlock() |
| 145 | } |
| 146 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 147 | // resetTpProcessingErrorIndication resets the internal error indication |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 148 | // 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] | 149 | func (onuTP *onuUniTechProf) resetTpProcessingErrorIndication(aUniID uint8, aTpID uint8) { |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 150 | onuTP.mutexTPState.Lock() |
| 151 | defer onuTP.mutexTPState.Unlock() |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 152 | onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] = nil |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 155 | func (onuTP *onuUniTechProf) getTpProcessingErrorIndication(aUniID uint8, aTpID uint8) error { |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 156 | onuTP.mutexTPState.RLock() |
| 157 | defer onuTP.mutexTPState.RUnlock() |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 158 | return onuTP.procResult[uniTP{uniID: aUniID, tpID: aTpID}] |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 159 | } |
| 160 | |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 161 | // 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] | 162 | // all possibly blocking processing must be run in background to allow for deadline supervision! |
| 163 | // but take care on sequential background processing when needed (logical dependencies) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 164 | // use waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) for internal synchronization |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 165 | func (onuTP *onuUniTechProf) configureUniTp(ctx context.Context, |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 166 | aUniID uint8, aPathString string, tpInst tech_profile.TechProfileInstance, wg *sync.WaitGroup) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 167 | defer wg.Done() //always decrement the waitGroup on return |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 168 | logger.Debugw(ctx, "configure the Uni according to TpPath", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 169 | "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 170 | tpID, err := GetTpIDFromTpPath(aPathString) |
| 171 | uniTpKey := uniTP{uniID: aUniID, tpID: tpID} |
| 172 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 173 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 174 | return |
| 175 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 176 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 177 | //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] | 178 | var pCurrentUniPort *onuUniPort |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 179 | for _, uniPort := range onuTP.baseDeviceHandler.uniEntityMap { |
| 180 | // only if this port is validated for operState transfer |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 181 | if uniPort.uniID == aUniID { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 182 | pCurrentUniPort = uniPort |
| 183 | break //found - end search loop |
| 184 | } |
| 185 | } |
| 186 | if pCurrentUniPort == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 187 | logger.Errorw(ctx, "TechProfile configuration aborted: requested uniID not found in PortDB", |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 188 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID}) |
| 189 | onuTP.mutexTPState.Lock() |
| 190 | defer onuTP.mutexTPState.Unlock() |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 191 | 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] | 192 | aUniID, onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 193 | return |
| 194 | } |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 195 | |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 196 | if onuTP.getProfileResetting(uniTpKey) { |
| 197 | logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{ |
| 198 | "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID}) |
| 199 | onuTP.mutexTPState.Lock() |
| 200 | defer onuTP.mutexTPState.Unlock() |
| 201 | onuTP.procResult[uniTpKey] = fmt.Errorf( |
| 202 | "techProfile config aborted - reset requested in parallel - for uniID %d on %s", |
| 203 | aUniID, onuTP.deviceID) |
| 204 | return |
| 205 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 206 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 207 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 208 | //according to updateOnuUniTpPath() logic the assumption here is, that this configuration is only called |
| 209 | // in case the KVPath has changed for the given UNI, |
| 210 | // as T-Cont and Gem-Id's are dependent on TechProfile-Id this means, that possibly previously existing |
| 211 | // (ANI) configuration of this port has to be removed first |
| 212 | // (moreover in this case a possibly existing flow configuration is also not valid anymore and needs clean-up as well) |
| 213 | // existence of configuration can be detected based on tp stored TCONT's |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 214 | //TODO: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 215 | /* if tcontMap not empty { |
| 216 | go onuTP.deleteAniSideConfig(ctx, aUniID, processingStep) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 217 | if !onuTP.waitForTimeoutOrCompletion(ctx, chTpConfigProcessingStep, processingStep) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 218 | //timeout or error detected |
| 219 | return |
| 220 | } |
| 221 | clear tcontMap |
| 222 | } |
| 223 | |
| 224 | processingStep++ |
| 225 | */ |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 226 | go onuTP.readAniSideConfigFromTechProfile(ctx, aUniID, tpID, aPathString, tpInst, 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 |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 229 | onuTP.mutexTPState.RLock() |
Girish Gowdra | 24dd113 | 2021-07-06 15:25:40 -0700 | [diff] [blame] | 230 | ok := onuTP.tpProfileExists[uniTpKey] |
| 231 | onuTP.mutexTPState.RUnlock() |
| 232 | if ok { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 233 | //ignore the internal error in case the new profile is already configured |
| 234 | // and abort the processing here |
| 235 | return |
| 236 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 237 | logger.Errorw(ctx, "tech-profile related configuration aborted on read", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 238 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 239 | onuTP.mutexTPState.Lock() |
| 240 | defer onuTP.mutexTPState.Unlock() |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 241 | 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] | 242 | aUniID, onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 243 | return |
| 244 | } |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 245 | if onuTP.getProfileResetting(uniTpKey) { |
| 246 | logger.Debugw(ctx, "aborting TP configuration, reset requested in parallel", log.Fields{ |
| 247 | "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": uniTpKey.tpID}) |
| 248 | onuTP.mutexTPState.Lock() |
| 249 | defer onuTP.mutexTPState.Unlock() |
| 250 | onuTP.procResult[uniTpKey] = fmt.Errorf( |
| 251 | "techProfile config aborted - reset requested in parallel - for uniID %d on %s", |
| 252 | aUniID, onuTP.deviceID) |
| 253 | return |
| 254 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 255 | processingStep++ |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 256 | |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 257 | //ensure read protection for access to mapPonAniConfig |
| 258 | onuTP.mutexTPState.RLock() |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 259 | valuePA, existPA := onuTP.mapPonAniConfig[uniTpKey] |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 260 | onuTP.mutexTPState.RUnlock() |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 261 | if existPA { |
| 262 | if valuePA != nil { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 263 | //Config data for this uni and and at least TCont Index 0 exist |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 264 | if err := onuTP.setAniSideConfigFromTechProfile(ctx, aUniID, tpID, pCurrentUniPort, processingStep); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 265 | logger.Errorw(ctx, "tech-profile related FSM could not be started", |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 266 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 267 | onuTP.mutexTPState.Lock() |
| 268 | defer onuTP.mutexTPState.Unlock() |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 269 | onuTP.procResult[uniTpKey] = err |
| 270 | return |
| 271 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 272 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 273 | //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset)) |
| 274 | logger.Warnw(ctx, "tech-profile related configuration aborted on set", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 275 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 276 | |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 277 | onuTP.mutexTPState.Lock() |
| 278 | defer onuTP.mutexTPState.Unlock() |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 279 | 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] | 280 | aUniID, onuTP.deviceID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 281 | //this issue here means that the AniConfigFsm has not finished successfully |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 282 | //which requires to reset it to allow for new usage, e.g. also on a different UNI |
| 283 | //(without that it would be reset on device down indication latest) |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 284 | if _, ok := onuTP.pAniConfigFsm[uniTpKey]; ok { |
| 285 | _ = onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm.Event(aniEvReset) |
| 286 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 287 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 288 | } |
| 289 | } else { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 290 | // strange: UNI entry exists, but no ANI data, maybe such situation should be cleared up (if observed) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 291 | logger.Errorw(ctx, "no Tcont/Gem data for this UNI found - abort", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 292 | "device-id": onuTP.deviceID, "uni-id": aUniID}) |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 293 | onuTP.mutexTPState.Lock() |
| 294 | defer onuTP.mutexTPState.Unlock() |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 295 | 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] | 296 | aUniID, onuTP.deviceID) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 297 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 298 | } |
| 299 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 300 | logger.Errorw(ctx, "no PonAni data for this UNI found - abort", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 301 | "device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 302 | |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 303 | onuTP.mutexTPState.Lock() |
| 304 | defer onuTP.mutexTPState.Unlock() |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 305 | 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] | 306 | aUniID, onuTP.deviceID) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 307 | return |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 311 | /* internal methods *********************/ |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 312 | // nolint: gocyclo |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 313 | func (onuTP *onuUniTechProf) readAniSideConfigFromTechProfile( |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 314 | ctx context.Context, aUniID uint8, aTpID uint8, aPathString string, tpInst tech_profile.TechProfileInstance, aProcessingStep uint8) { |
| 315 | var err error |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 316 | //store profile type and identifier for later usage within the OMCI identifier and possibly ME setup |
| 317 | //pathstring is defined to be in the form of <ProfType>/<profID>/<Interface/../Identifier> |
| 318 | subStringSlice := strings.Split(aPathString, "/") |
| 319 | if len(subStringSlice) <= 2 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 320 | logger.Errorw(ctx, "invalid path name format", |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 321 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 322 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 323 | return |
| 324 | } |
| 325 | |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 326 | //ensure write protection for access to used maps |
| 327 | onuTP.mutexTPState.Lock() |
| 328 | defer onuTP.mutexTPState.Unlock() |
| 329 | |
| 330 | uniTPKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 331 | onuTP.tpProfileExists[uniTP{uniID: aUniID, tpID: aTpID}] = false |
| 332 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 333 | //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] | 334 | //expectation is that no TPIndication entry exists here, if exists and with the same TPId |
| 335 | // then we throw a warning, set an internal error and abort with error, |
| 336 | // which is later re-defined to success response to OLT adapter |
| 337 | // if TPId has changed, current data is removed (note that the ONU config state may be |
| 338 | // ambivalent in such a case) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 339 | if _, existTP := onuTP.mapUniTpIndication[uniTPKey]; existTP { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 340 | logger.Warnw(ctx, "Some active profile entry at reading new TechProfile", |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 341 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID, |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 342 | "uni-id": aUniID, "wrongProfile": onuTP.mapUniTpIndication[uniTPKey].techProfileID}) |
| 343 | if aTpID == onuTP.mapUniTpIndication[uniTPKey].techProfileID { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 344 | // ProfId not changed - assume profile to be still the same |
| 345 | // anyway this should not appear after full support of profile (Gem/TCont) removal |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 346 | logger.Warnw(ctx, "New TechProfile already exists - aborting configuration", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 347 | log.Fields{"device-id": onuTP.deviceID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 348 | onuTP.tpProfileExists[uniTPKey] = true |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 349 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
| 350 | return |
| 351 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 352 | //delete on the mapUniTpIndication map not needed, just overwritten later |
| 353 | //delete on the PonAniConfig map should be safe, even if not existing |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 354 | delete(onuTP.mapPonAniConfig, uniTPKey) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 355 | } else { |
| 356 | // this is normal processing |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 357 | onuTP.mapUniTpIndication[uniTPKey] = &tTechProfileIndication{} //need to assign some (empty) struct memory first! |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 360 | onuTP.mapUniTpIndication[uniTPKey].techProfileType = subStringSlice[0] |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 361 | //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] | 362 | onuTP.mapUniTpIndication[uniTPKey].techProfileID = aTpID |
| 363 | onuTP.mapUniTpIndication[uniTPKey].techProfileConfigDone = false |
| 364 | onuTP.mapUniTpIndication[uniTPKey].techProfileToDelete = false |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 365 | logger.Debugw(ctx, "tech-profile path indications", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 366 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 367 | "profType": onuTP.mapUniTpIndication[uniTPKey].techProfileType, |
| 368 | "profID": onuTP.mapUniTpIndication[uniTPKey].techProfileID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 369 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 370 | //default start with 1Tcont profile, later perhaps extend to MultiTcontMultiGem |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 371 | localMapGemPortParams := make(map[uint16]*gemPortParamStruct) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 372 | onuTP.mapPonAniConfig[uniTPKey] = &tcontGemList{tcontParamStruct{}, localMapGemPortParams} |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 373 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 374 | //note: the code is currently restricted to one TCcont per Onu (index [0]) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 375 | //get the relevant values from the profile and store to mapPonAniConfig |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 376 | onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID = uint16(tpInst.UsScheduler.AllocId) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 377 | //maybe tCont scheduling not (yet) needed - just to basically have it for future |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 378 | // (would only be relevant in case of ONU-2G QOS configuration flexibility) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 379 | if tpInst.UsScheduler.QSchedPolicy == tech_profile.SchedulingPolicy_StrictPriority { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 380 | 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] | 381 | } else { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 382 | //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] | 383 | onuTP.mapPonAniConfig[uniTPKey].tcontParams.schedPolicy = 2 //for G.988 WRR |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 384 | } |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 385 | loNumGemPorts := tpInst.NumGemPorts |
| 386 | loGemPortRead := false |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 387 | for pos, content := range tpInst.UpstreamGemPortAttributeList { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 388 | if uint32(pos) == loNumGemPorts { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 389 | logger.Debugw(ctx, "PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts", |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 390 | log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 391 | break |
| 392 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 393 | if pos == 0 { |
| 394 | //at least one upstream GemPort should always exist (else traffic profile makes no sense) |
| 395 | loGemPortRead = true |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 396 | } |
Himani Chawla | 1c13690 | 2020-12-10 16:30:59 +0530 | [diff] [blame] | 397 | //for all GemPorts we need to extend the mapGemPortParams |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 398 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)] = &gemPortParamStruct{} |
Himani Chawla | 1c13690 | 2020-12-10 16:30:59 +0530 | [diff] [blame] | 399 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 400 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortID = |
| 401 | uint16(content.GemportId) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 402 | //direction can be correlated later with Downstream list, |
| 403 | // for now just assume bidirectional (upstream never exists alone) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 404 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].direction = 3 //as defined in G.988 |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 405 | // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7 |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 406 | if content.PriorityQ > 7 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 407 | logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid", |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 408 | log.Fields{"device-id": onuTP.deviceID, "index": pos, "PrioQueue": content.PriorityQ}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 409 | //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] | 410 | delete(onuTP.mapPonAniConfig, uniTPKey) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 411 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 412 | return |
| 413 | } |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 414 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].prioQueueIndex = |
| 415 | uint8(content.PriorityQ) |
| 416 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].pbitString = |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 417 | strings.TrimPrefix(content.PbitMap, binaryStringPrefix) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 418 | if content.AesEncryption == "True" { |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 419 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortEncState = 1 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 420 | } else { |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 421 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].gemPortEncState = 0 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 422 | } |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 423 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].discardPolicy = |
| 424 | content.DiscardPolicy.String() |
| 425 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].queueSchedPolicy = |
| 426 | content.SchedulingPolicy.String() |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 427 | //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 428 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[uint16(content.GemportId)].queueWeight = |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 429 | uint8(content.Weight) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 430 | } |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 431 | |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 432 | for _, downstreamContent := range tpInst.DownstreamGemPortAttributeList { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 433 | logger.Debugw(ctx, "Operating on Downstream Gem Port", log.Fields{"downstream-gem": downstreamContent}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 434 | //Commenting this out due to faliure, needs investigation |
| 435 | //if uint32(pos) == loNumGemPorts { |
| 436 | // logger.Debugw("PonAniConfig abort GemPortList - GemList exceeds set NumberOfGemPorts", |
| 437 | // log.Fields{"device-id": onuTP.deviceID, "index": pos, "NumGem": loNumGemPorts}) |
| 438 | // break |
| 439 | //} |
| 440 | isMulticast := false |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 441 | //Flag is defined as string in the TP in voltha-lib-go, parsing it from string |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 442 | if downstreamContent.IsMulticast != "" { |
| 443 | isMulticast, err = strconv.ParseBool(downstreamContent.IsMulticast) |
| 444 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 445 | logger.Errorw(ctx, "multicast-error-config-unknown-flag-in-technology-profile", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 446 | log.Fields{"UniTpKey": uniTPKey, "downstream-gem": downstreamContent, "error": err}) |
| 447 | continue |
| 448 | } |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 449 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 450 | logger.Infow(ctx, "Gem Port is multicast", log.Fields{"isMulticast": isMulticast}) |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 451 | if isMulticast { |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 452 | mcastGemID := uint16(downstreamContent.MulticastGemId) |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 453 | _, existing := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID] |
| 454 | if existing { |
| 455 | //GEM port was previously configured, avoid setting multicast attributes |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 456 | logger.Errorw(ctx, "multicast-error-config-existing-gem-port-config", log.Fields{"UniTpKey": uniTPKey, |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 457 | "downstream-gem": downstreamContent, "key": mcastGemID}) |
| 458 | continue |
| 459 | } else { |
| 460 | //GEM port is not configured, setting multicast attributes |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 461 | logger.Infow(ctx, "creating-multicast-gem-port", log.Fields{"uniTpKey": uniTPKey, |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 462 | "gemPortId": mcastGemID, "key": mcastGemID}) |
| 463 | |
| 464 | //for all further GemPorts we need to extend the mapGemPortParams |
| 465 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID] = &gemPortParamStruct{} |
| 466 | |
| 467 | //Separate McastGemId is derived from OMCI-lib-go, if not needed first needs to be removed there. |
| 468 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortID = mcastGemID |
| 469 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].direction = 2 // for ANI to UNI as defined in G.988 |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 470 | |
| 471 | if downstreamContent.AesEncryption == "True" { |
| 472 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 1 |
| 473 | } else { |
| 474 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].gemPortEncState = 0 |
| 475 | } |
| 476 | |
| 477 | // expected Prio-Queue values 0..7 with 7 for highest PrioQueue, QueueIndex=Prio = 0..7 |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 478 | if downstreamContent.PriorityQ > 7 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 479 | logger.Errorw(ctx, "PonAniConfig reject on GemPortList - PrioQueue value invalid", |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 480 | log.Fields{"device-id": onuTP.deviceID, "index": mcastGemID, "PrioQueue": downstreamContent.PriorityQ}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 481 | //remove PonAniConfig as done so far, delete map should be safe, even if not existing |
| 482 | delete(onuTP.mapPonAniConfig, uniTPKey) |
| 483 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
| 484 | return |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 485 | } |
| 486 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].prioQueueIndex = |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 487 | uint8(downstreamContent.PriorityQ) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 488 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].pbitString = |
| 489 | strings.TrimPrefix(downstreamContent.PbitMap, binaryStringPrefix) |
| 490 | |
| 491 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].discardPolicy = |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 492 | downstreamContent.DiscardPolicy.String() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 493 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueSchedPolicy = |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 494 | downstreamContent.SchedulingPolicy.String() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 495 | //'GemWeight' looks strange in default profile, for now we just copy the weight to first queue |
| 496 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].queueWeight = |
| 497 | uint8(downstreamContent.Weight) |
| 498 | |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 499 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].isMulticast = isMulticast |
| 500 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].multicastGemPortID = |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 501 | uint16(downstreamContent.MulticastGemId) |
| 502 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].staticACL = downstreamContent.StaticAccessControlList |
| 503 | onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams[mcastGemID].dynamicACL = downstreamContent.DynamicAccessControlList |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 508 | if !loGemPortRead { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 509 | logger.Errorw(ctx, "PonAniConfig reject - no GemPort could be read from TechProfile", |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 510 | log.Fields{"path": aPathString, "device-id": onuTP.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 511 | //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] | 512 | delete(onuTP.mapPonAniConfig, uniTPKey) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 513 | onuTP.chTpConfigProcessingStep <- 0 //error indication |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 514 | return |
| 515 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 516 | //logger does not simply output the given structures, just give some example debug values |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 517 | logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 518 | "device-id": onuTP.deviceID, "uni-id": aUniID, |
| 519 | "AllocId": onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID}) |
Himani Chawla | 1c13690 | 2020-12-10 16:30:59 +0530 | [diff] [blame] | 520 | for gemPortID, gemEntry := range onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 521 | logger.Debugw(ctx, "PonAniConfig read from TechProfile", log.Fields{ |
Himani Chawla | 1c13690 | 2020-12-10 16:30:59 +0530 | [diff] [blame] | 522 | "GemPort": gemPortID, |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 523 | "QueueScheduling": gemEntry.queueSchedPolicy}) |
| 524 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 525 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 526 | onuTP.chTpConfigProcessingStep <- aProcessingStep //done |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 529 | func (onuTP *onuUniTechProf) setAniSideConfigFromTechProfile( |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 530 | ctx context.Context, aUniID uint8, aTpID uint8, apCurrentUniPort *onuUniPort, aProcessingStep uint8) error { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 531 | |
| 532 | //OMCI transfer of ANI data acc. to mapPonAniConfig |
| 533 | // also the FSM's are running in background, |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 534 | // 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] | 535 | uniTPKey := uniTP{uniID: aUniID, tpID: aTpID} |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 536 | if onuTP.pAniConfigFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 537 | return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 538 | } else if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 539 | return onuTP.createAniConfigFsm(ctx, aUniID, aTpID, apCurrentUniPort, OmciAniConfigDone, aProcessingStep) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 540 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 541 | //AniConfigFsm already init |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 542 | return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | // deleteTpResource removes Resources from the ONU's specified Uni |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 546 | // nolint: gocyclo |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 547 | func (onuTP *onuUniTechProf) deleteTpResource(ctx context.Context, |
| 548 | aUniID uint8, aTpID uint8, aPathString string, aResource resourceEntry, aEntryID uint32, |
| 549 | wg *sync.WaitGroup) { |
| 550 | defer wg.Done() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 551 | logger.Debugw(ctx, "will remove TP resources from ONU's UNI", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 552 | "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "Resource": aResource}) |
| 553 | uniTPKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 554 | |
| 555 | if cResourceGemPort == aResource { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 556 | logger.Debugw(ctx, "remove GemPort from the list of existing ones of the TP", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 557 | "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "GemPort": aEntryID}) |
| 558 | |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 559 | //ensure read protection for access to mapPonAniConfig |
| 560 | onuTP.mutexTPState.RLock() |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 561 | // check if the requested GemPort exists in the DB, indicate it to the FSM |
| 562 | // store locally to remove it from DB later on success |
| 563 | pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey] |
| 564 | if pLocAniConfigOnUni == nil { |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 565 | onuTP.mutexTPState.RUnlock() |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 566 | // No relevant entry exists anymore - acknowledge success |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 567 | logger.Debugw(ctx, "AniConfig or GemEntry do not exists in DB", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 568 | "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID}) |
| 569 | return |
| 570 | } |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 571 | onuTP.mutexTPState.RUnlock() |
| 572 | |
Himani Chawla | 1c13690 | 2020-12-10 16:30:59 +0530 | [diff] [blame] | 573 | for gemPortID, gemEntry := range pLocAniConfigOnUni.mapGemPortParams { |
| 574 | if gemPortID == uint16(aEntryID) { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 575 | //GemEntry to be deleted found |
Himani Chawla | 1c13690 | 2020-12-10 16:30:59 +0530 | [diff] [blame] | 576 | gemEntry.removeGemID = gemPortID //store the index for later removal |
| 577 | onuTP.mapRemoveGemEntry[uniTPKey] = pLocAniConfigOnUni.mapGemPortParams[gemPortID] |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 578 | logger.Debugw(ctx, "Remove-GemEntry stored", log.Fields{ |
Himani Chawla | 1c13690 | 2020-12-10 16:30:59 +0530 | [diff] [blame] | 579 | "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID}) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 580 | break //abort loop, always only one GemPort to remove |
| 581 | } |
| 582 | } |
| 583 | if onuTP.mapRemoveGemEntry[uniTPKey] == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 584 | logger.Errorw(ctx, "GemPort removal aborted - GemPort not found", |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 585 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "GemPort": aEntryID}) |
| 586 | /* Do not set some error indication to the outside system interface on delete |
| 587 | assume there is nothing to be deleted internally and hope a new config request will recover the situation |
| 588 | onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: GemPort not found %d for %d on %s", |
| 589 | aEntryID, aUniID, onuTP.deviceID) |
| 590 | */ |
| 591 | return |
| 592 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 593 | if onuTP.baseDeviceHandler.isReadyForOmciConfig() { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 594 | // check that the TpConfigRequest was done before |
| 595 | // -> that is implicitly done using the AniConfigFsm, |
| 596 | // which must be in the according state to remove something |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 597 | if onuTP.pAniConfigFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 598 | logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available", |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 599 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 600 | /* Do not set some error indication to the outside system interface on delete (see above) |
| 601 | onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s", |
| 602 | aUniID, onuTP.deviceID) |
| 603 | */ |
| 604 | //if the FSM is not valid, also TP related remove data should not be valid: |
| 605 | // remove GemPort from config DB |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 606 | //ensure write protection for access to mapPonAniConfig |
| 607 | onuTP.mutexTPState.Lock() |
Himani Chawla | 1c13690 | 2020-12-10 16:30:59 +0530 | [diff] [blame] | 608 | delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 609 | // remove the removeEntry |
| 610 | delete(onuTP.mapRemoveGemEntry, uniTPKey) |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 611 | onuTP.mutexTPState.Unlock() |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 612 | return |
| 613 | } |
| 614 | if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 615 | logger.Errorw(ctx, "abort GemPort removal - no AniConfigFsm available for this uni/tp", |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 616 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID}) |
| 617 | /* Do not set some error indication to the outside system interface on delete (see above) |
| 618 | onuTP.procResult[uniTpKey] = fmt.Errorf("GemPort removal aborted: no AniConfigFsm available %d on %s for tpid", |
| 619 | aUniID, onuTP.deviceID, aTpID) |
| 620 | */ |
| 621 | //if the FSM is not valid, also TP related remove data should not be valid: |
| 622 | // remove GemPort from config DB |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 623 | //ensure write protection for access to mapPonAniConfig |
| 624 | onuTP.mutexTPState.Lock() |
Himani Chawla | 1c13690 | 2020-12-10 16:30:59 +0530 | [diff] [blame] | 625 | delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 626 | // remove the removeEntry |
| 627 | delete(onuTP.mapRemoveGemEntry, uniTPKey) |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 628 | onuTP.mutexTPState.Unlock() |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 629 | return |
| 630 | } |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 631 | if onuTP.getProfileResetting(uniTPKey) { |
| 632 | logger.Debugw(ctx, "aborting GemRemoval on FSM, reset requested in parallel", log.Fields{ |
| 633 | "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID}) |
| 634 | //ensure write protection for access to mapPonAniConfig |
| 635 | onuTP.mutexTPState.Lock() |
| 636 | delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID) |
| 637 | // remove the removeEntry |
| 638 | delete(onuTP.mapRemoveGemEntry, uniTPKey) |
| 639 | onuTP.mutexTPState.Unlock() |
| 640 | return |
| 641 | } |
| 642 | // initiate OMCI GemPort related removal |
| 643 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep |
| 644 | // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 645 | if nil != onuTP.runAniConfigFsm(ctx, aniEvRemGemiw, processingStep, aUniID, aTpID) { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 646 | //even if the FSM invocation did not work we don't indicate a problem within procResult |
| 647 | //errors could exist also because there was nothing to delete - so we just accept that as 'deleted' |
| 648 | //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented) |
| 649 | return |
| 650 | } |
| 651 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 652 | //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset)) |
| 653 | logger.Warnw(ctx, "GemPort removal aborted - Omci AniSideConfig failed", |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 654 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 655 | //even if the FSM delete execution did not work we don't indicate a problem within procResult |
| 656 | //we should never respond to delete with error ... |
| 657 | //this issue here means that the AniConfigFsm has not finished successfully |
| 658 | //which requires to reset it to allow for new usage, e.g. also on a different UNI |
| 659 | //(without that it would be reset on device down indication latest) |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 660 | if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok { |
| 661 | _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset) |
| 662 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 663 | //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented) |
| 664 | return |
| 665 | } |
| 666 | } else { |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 667 | //if we can't do the OMCI processing we also suppress the ProcStatusUpdate |
| 668 | //this is needed as in the device-down case where all FSM's are getting reset and internal data gets cleared |
| 669 | //as a consequence a possible remove-flow does not see any dependency on the TechProfile anymore and is executed (pro forma) directly |
| 670 | //a later TechProfile removal would cause the device-reason to be updated to 'techProfile-delete-success' which is not the expected state |
| 671 | // and anyway is no real useful information at that stage |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 672 | logger.Debugw(ctx, "uniPonAniConfigFsm delete Gem on OMCI skipped based on device state", log.Fields{ |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 673 | "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()}) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 674 | } |
| 675 | // remove GemPort from config DB |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 676 | //ensure write protection for access to mapPonAniConfig |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 677 | logger.Debugw(ctx, "uniPonAniConfigFsm removing gem from config data and clearing ani FSM", log.Fields{ |
| 678 | "device-id": onuTP.deviceID, "gem-id": onuTP.mapRemoveGemEntry[uniTPKey].removeGemID, "uniTPKey": uniTPKey}) |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 679 | onuTP.mutexTPState.Lock() |
Himani Chawla | 1c13690 | 2020-12-10 16:30:59 +0530 | [diff] [blame] | 680 | delete(onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams, onuTP.mapRemoveGemEntry[uniTPKey].removeGemID) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 681 | // remove the removeEntry |
| 682 | delete(onuTP.mapRemoveGemEntry, uniTPKey) |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 683 | onuTP.mutexTPState.Unlock() |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 684 | } else { //if cResourceTcont == aResource { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 685 | logger.Debugw(ctx, "reset TCont with AllocId", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 686 | "device-id": onuTP.deviceID, "uni-id": aUniID, "path": aPathString, "allocId": aEntryID}) |
| 687 | |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 688 | //ensure read protection for access to mapPonAniConfig |
| 689 | onuTP.mutexTPState.RLock() |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 690 | // check if the TCont with the indicated AllocId exists in the DB, indicate its EntityId to the FSM |
| 691 | pLocAniConfigOnUni := onuTP.mapPonAniConfig[uniTPKey] |
| 692 | if pLocAniConfigOnUni == nil { |
| 693 | // No relevant entry exists anymore - acknowledge success |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 694 | onuTP.mutexTPState.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 695 | logger.Debugw(ctx, "AniConfig or TCont entry do not exists in DB", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 696 | "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID}) |
| 697 | return |
| 698 | } |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 699 | onuTP.mutexTPState.RUnlock() |
| 700 | |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 701 | if pLocAniConfigOnUni.tcontParams.allocID != uint16(aEntryID) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 702 | logger.Errorw(ctx, "TCont removal aborted - indicated AllocId not found", |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 703 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID, "AllocId": aEntryID}) |
| 704 | /* Do not set some error indication to the outside system interface on delete |
| 705 | assume there is nothing to be deleted internally and hope a new config request will recover the situation |
| 706 | onuTP.procResult[uniTpKey] = fmt.Errorf("TCont removal aborted: AllocId not found %d for %d on %s", |
| 707 | aEntryID, aUniID, onuTP.deviceID) |
| 708 | */ |
| 709 | return |
| 710 | } |
| 711 | //T-Cont to be reset found |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 712 | logger.Debugw(ctx, "Reset-T-Cont AllocId found - valid", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 713 | "device-id": onuTP.deviceID, "uni-id": aUniID, "AllocId": aEntryID}) |
| 714 | if onuTP.pAniConfigFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 715 | logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available", |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 716 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 717 | /* Do not set some error indication to the outside system interface on delete (see above) |
| 718 | onuTP.procResult[uniTpKey] = fmt.Errorf("TCont cleanup aborted: no AniConfigFsm available %d on %s", |
| 719 | aUniID, onuTP.deviceID) |
| 720 | */ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 721 | return |
| 722 | } |
| 723 | if _, ok := onuTP.pAniConfigFsm[uniTPKey]; !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 724 | logger.Errorw(ctx, "no TCont removal on OMCI - no AniConfigFsm available for this uni/tp", |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 725 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID}) |
| 726 | //even if the FSM invocation did not work we don't indicate a problem within procResult |
| 727 | //errors could exist also because there was nothing to delete - so we just accept that as 'deleted' |
| 728 | //if the FSM is not valid, also TP related data should not be valid - clear the internal store profile data |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 729 | return |
| 730 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 731 | if onuTP.baseDeviceHandler.isReadyForOmciConfig() { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 732 | // check that the TpConfigRequest was done before |
| 733 | // -> that is implicitly done using the AniConfigFsm, |
| 734 | // which must be in the according state to remove something |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 735 | if onuTP.getProfileResetting(uniTPKey) { |
| 736 | logger.Debugw(ctx, "aborting TCont removal on FSM, reset requested in parallel", log.Fields{ |
| 737 | "device-id": onuTP.deviceID, "uni-id": aUniID, "tp-id": aTpID}) |
| 738 | return |
| 739 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 740 | // initiate OMCI TCont related cleanup |
| 741 | var processingStep uint8 = 1 // used to synchronize the different processing steps with chTpConfigProcessingStep |
| 742 | // hence we have to make sure they indicate 'success' on chTpConfigProcessingStep with aProcessingStep |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 743 | if nil != onuTP.runAniConfigFsm(ctx, aniEvRemTcontPath, processingStep, aUniID, aTpID) { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 744 | //even if the FSM invocation did not work we don't indicate a problem within procResult |
| 745 | //errors could exist also because there was nothing to delete - so we just accept that as 'deleted' |
| 746 | //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented) |
| 747 | return |
| 748 | } |
| 749 | if !onuTP.waitForTimeoutOrCompletion(ctx, onuTP.chTpConfigProcessingStep, processingStep) { |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 750 | //timeout or error detected (included wanted cancellation after e.g. disable device (FsmReset)) |
| 751 | logger.Warnw(ctx, "TCont cleanup aborted - Omci AniSideConfig failed", |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 752 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 753 | //even if the FSM delete execution did not work we don't indicate a problem within procResult |
| 754 | //we should never respond to delete with error ... |
| 755 | //this issue here means that the AniConfigFsm has not finished successfully |
| 756 | //which requires to reset it to allow for new usage, e.g. also on a different UNI |
| 757 | //(without that it would be reset on device down indication latest) |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 758 | if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok { |
| 759 | _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset) |
| 760 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 761 | //TP related data cleared by FSM error treatment or re-used by FSM error-recovery (if implemented) |
| 762 | return |
| 763 | } |
| 764 | } else { |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 765 | //see gemPort comments |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 766 | logger.Debugw(ctx, "uniPonAniConfigFsm TCont cleanup on OMCI skipped based on device state", log.Fields{ |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 767 | "device-id": onuTP.deviceID, "device-state": onuTP.baseDeviceHandler.getDeviceReasonString()}) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 768 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 769 | } |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 770 | |
| 771 | } |
| 772 | |
| 773 | func (onuTP *onuUniTechProf) isTechProfileConfigCleared(ctx context.Context, uniID uint8, tpID uint8) bool { |
| 774 | uniTPKey := uniTP{uniID: uniID, tpID: tpID} |
| 775 | logger.Debugw(ctx, "isTechProfileConfigCleared", log.Fields{"device-id": onuTP.deviceID}) |
| 776 | if onuTP.mapPonAniConfig[uniTPKey] != nil { |
| 777 | mapGemPortParams := onuTP.mapPonAniConfig[uniTPKey].mapGemPortParams |
| 778 | unicastGemCount := 0 |
| 779 | for _, gemEntry := range mapGemPortParams { |
| 780 | if !gemEntry.isMulticast { |
| 781 | unicastGemCount++ |
| 782 | } |
| 783 | } |
| 784 | if unicastGemCount == 0 || onuTP.mapPonAniConfig[uniTPKey].tcontParams.allocID == 0 { |
| 785 | logger.Debugw(ctx, "clearing-ani-side-config", log.Fields{ |
| 786 | "device-id": onuTP.deviceID, "uniTpKey": uniTPKey}) |
| 787 | onuTP.clearAniSideConfig(ctx, uniID, tpID) |
| 788 | if _, ok := onuTP.pAniConfigFsm[uniTPKey]; ok { |
| 789 | _ = onuTP.pAniConfigFsm[uniTPKey].pAdaptFsm.pFsm.Event(aniEvReset) |
| 790 | } |
| 791 | go onuTP.baseDeviceHandler.deviceProcStatusUpdate(ctx, OmciAniResourceRemoved) |
| 792 | return true |
| 793 | } |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 794 | } |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 795 | return false |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 798 | func (onuTP *onuUniTechProf) waitForTimeoutOrCompletion( |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 799 | ctx context.Context, aChTpProcessingStep <-chan uint8, aProcessingStep uint8) bool { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 800 | select { |
| 801 | case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 802 | logger.Warnw(ctx, "processing not completed in-time: force release of TpProcMutex!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 803 | log.Fields{"device-id": onuTP.deviceID, "error": ctx.Err()}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 804 | return false |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 805 | case rxStep := <-aChTpProcessingStep: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 806 | if rxStep == aProcessingStep { |
| 807 | return true |
| 808 | } |
| 809 | //all other values are not accepted - including 0 for error indication |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 810 | logger.Warnw(ctx, "Invalid processing step received: abort and force release of TpProcMutex!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 811 | log.Fields{"device-id": onuTP.deviceID, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 812 | "wantedStep": aProcessingStep, "haveStep": rxStep}) |
| 813 | return false |
| 814 | } |
| 815 | } |
| 816 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 817 | // createAniConfigFsm initializes and runs the AniConfig FSM to transfer the OMCI related commands for ANI side configuration |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 818 | func (onuTP *onuUniTechProf) createAniConfigFsm(ctx context.Context, aUniID uint8, aTpID uint8, |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 819 | apCurrentUniPort *onuUniPort, devEvent OnuDeviceEvent, aProcessingStep uint8) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 820 | logger.Debugw(ctx, "createAniConfigFsm", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 821 | chAniConfigFsm := make(chan Message, 2048) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 822 | uniTPKey := uniTP{uniID: aUniID, tpID: aTpID} |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 823 | pDevEntry := onuTP.baseDeviceHandler.getOnuDeviceEntry(ctx, true) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 824 | if pDevEntry == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 825 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 826 | return fmt.Errorf("no valid OnuDevice: %s", onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 827 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 828 | pAniCfgFsm := newUniPonAniConfigFsm(ctx, pDevEntry.PDevOmciCC, apCurrentUniPort, onuTP, |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 829 | pDevEntry.pOnuDB, aTpID, devEvent, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 830 | "AniConfigFsm", onuTP.baseDeviceHandler, chAniConfigFsm) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 831 | if pAniCfgFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 832 | logger.Errorw(ctx, "AniConfigFSM could not be created - abort!!", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 833 | return fmt.Errorf("could not create AniConfigFSM: %s", onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 834 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 835 | if onuTP.pAniConfigFsm == nil { |
| 836 | onuTP.pAniConfigFsm = make(map[uniTP]*uniPonAniConfigFsm) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 837 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 838 | onuTP.pAniConfigFsm[uniTPKey] = pAniCfgFsm |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 839 | return onuTP.runAniConfigFsm(ctx, aniEvStart, aProcessingStep, aUniID, aTpID) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 840 | } |
| 841 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 842 | // runAniConfigFsm starts the AniConfig FSM to transfer the OMCI related commands for ANI side configuration |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 843 | func (onuTP *onuUniTechProf) runAniConfigFsm(ctx context.Context, aEvent string, aProcessingStep uint8, aUniID uint8, aTpID uint8) error { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 844 | /* Uni related ANI config procedure - |
| 845 | ***** should run via 'aniConfigDone' state and generate the argument requested event ***** |
| 846 | */ |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 847 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 848 | |
| 849 | pACStatemachine := onuTP.pAniConfigFsm[uniTpKey].pAdaptFsm.pFsm |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 850 | if pACStatemachine != nil { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 851 | if aEvent == aniEvStart { |
| 852 | if !pACStatemachine.Is(aniStDisabled) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 853 | logger.Errorw(ctx, "wrong state of AniConfigFSM to start - want: Disabled", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 854 | "have": pACStatemachine.Current(), "device-id": onuTP.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 855 | // maybe try a FSM reset and then again ... - TODO!!! |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 856 | return fmt.Errorf("wrong state of AniConfigFSM to start: %s", onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 857 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 858 | } else if !pACStatemachine.Is(aniStConfigDone) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 859 | logger.Errorw(ctx, "wrong state of AniConfigFSM to remove - want: ConfigDone", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 860 | "have": pACStatemachine.Current(), "device-id": onuTP.deviceID}) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 861 | return fmt.Errorf("wrong state of AniConfigFSM to remove: %s", onuTP.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 862 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 863 | //FSM init requirement to get informed about FSM completion! (otherwise timeout of the TechProf config) |
| 864 | onuTP.pAniConfigFsm[uniTpKey].setFsmCompleteChannel(onuTP.chTpConfigProcessingStep, aProcessingStep) |
| 865 | if err := pACStatemachine.Event(aEvent); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 866 | logger.Errorw(ctx, "AniConfigFSM: can't trigger event", log.Fields{"err": err}) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 867 | return fmt.Errorf("can't trigger event in AniConfigFSM: %s", onuTP.deviceID) |
| 868 | } |
| 869 | /***** AniConfigFSM event notified */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 870 | logger.Debugw(ctx, "AniConfigFSM event notified", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 871 | "state": pACStatemachine.Current(), "device-id": onuTP.deviceID, "event": aEvent}) |
| 872 | return nil |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 873 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 874 | logger.Errorw(ctx, "AniConfigFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": onuTP.deviceID}) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 875 | // maybe try a FSM reset and then again ... - TODO!!! |
| 876 | return fmt.Errorf("stateMachine AniConfigFSM invalid: %s", onuTP.deviceID) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 877 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 878 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 879 | // clearAniSideConfig deletes internal TechProfile related data connected to the requested UniPort and TpID |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 880 | func (onuTP *onuUniTechProf) clearAniSideConfig(ctx context.Context, aUniID uint8, aTpID uint8) { |
| 881 | logger.Debugw(ctx, "removing TpIndication and PonAniConfig data", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 882 | "device-id": onuTP.deviceID, "uni-id": aUniID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 883 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 884 | |
| 885 | onuTP.mutexTPState.Lock() |
| 886 | defer onuTP.mutexTPState.Unlock() |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 887 | //deleting a map entry should be safe, even if not existing |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 888 | delete(onuTP.mapUniTpIndication, uniTpKey) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 889 | delete(onuTP.mapPonAniConfig, uniTpKey) |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 890 | delete(onuTP.procResult, uniTpKey) |
| 891 | delete(onuTP.tpProfileExists, uniTpKey) |
| 892 | delete(onuTP.tpProfileResetting, uniTpKey) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 893 | } |
| 894 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 895 | // setConfigDone sets the requested techProfile config state (if possible) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 896 | func (onuTP *onuUniTechProf) setConfigDone(aUniID uint8, aTpID uint8, aState bool) { |
| 897 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 898 | onuTP.mutexTPState.Lock() |
| 899 | defer onuTP.mutexTPState.Unlock() |
| 900 | if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP { |
| 901 | onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone = aState |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 902 | } //else: the state is just ignored (does not exist) |
| 903 | } |
| 904 | |
| 905 | // getTechProfileDone checks if the Techprofile processing with the requested TechProfile ID was done |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 906 | func (onuTP *onuUniTechProf) getTechProfileDone(ctx context.Context, aUniID uint8, aTpID uint8) bool { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 907 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 908 | onuTP.mutexTPState.RLock() |
| 909 | defer onuTP.mutexTPState.RUnlock() |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 910 | if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP { |
| 911 | if onuTP.mapUniTpIndication[uniTpKey].techProfileID == aTpID { |
| 912 | if onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 913 | logger.Debugw(ctx, "TechProfile not relevant for requested flow config - waiting on delete", |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 914 | log.Fields{"device-id": onuTP.deviceID, "uni-id": aUniID}) |
| 915 | return false //still waiting for removal of this techProfile first |
| 916 | } |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 917 | return onuTP.mapUniTpIndication[uniTpKey].techProfileConfigDone |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | //for all other constellations indicate false = Config not done |
| 921 | return false |
| 922 | } |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 923 | |
| 924 | // setProfileToDelete sets the requested techProfile toDelete state (if possible) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 925 | func (onuTP *onuUniTechProf) setProfileToDelete(aUniID uint8, aTpID uint8, aState bool) { |
| 926 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 927 | onuTP.mutexTPState.Lock() |
| 928 | defer onuTP.mutexTPState.Unlock() |
| 929 | if _, existTP := onuTP.mapUniTpIndication[uniTpKey]; existTP { |
| 930 | onuTP.mapUniTpIndication[uniTpKey].techProfileToDelete = aState |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 931 | } //else: the state is just ignored (does not exist) |
| 932 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 933 | |
| 934 | // setProfileToDelete sets the requested techProfile toDelete state (if possible) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 935 | func (onuTP *onuUniTechProf) getMulticastGemPorts(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 936 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 937 | onuTP.mutexTPState.RLock() |
| 938 | defer onuTP.mutexTPState.RUnlock() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 939 | gemPortIds := make([]uint16, 0) |
| 940 | if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP { |
| 941 | for _, gemPortParam := range techProfile.mapGemPortParams { |
| 942 | if gemPortParam.isMulticast { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 943 | logger.Debugw(ctx, "Detected multicast gemPort", log.Fields{"device-id": onuTP.deviceID, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 944 | "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey, |
| 945 | "mcastGemId": gemPortParam.multicastGemPortID}) |
| 946 | gemPortIds = append(gemPortIds, gemPortParam.multicastGemPortID) |
| 947 | } |
| 948 | } |
| 949 | } //else: the state is just ignored (does not exist) |
| 950 | return gemPortIds |
| 951 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 952 | |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 953 | func (onuTP *onuUniTechProf) getBidirectionalGemPortIDsForTP(ctx context.Context, aUniID uint8, aTpID uint8) []uint16 { |
| 954 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 955 | onuTP.mutexTPState.RLock() |
| 956 | defer onuTP.mutexTPState.RUnlock() |
| 957 | gemPortIds := make([]uint16, 0) |
| 958 | if techProfile, existTP := onuTP.mapPonAniConfig[uniTpKey]; existTP { |
| 959 | logger.Debugw(ctx, "TechProfile exist", log.Fields{"device-id": onuTP.deviceID}) |
| 960 | for _, gemPortParam := range techProfile.mapGemPortParams { |
| 961 | if !gemPortParam.isMulticast { |
| 962 | logger.Debugw(ctx, "Detected unicast gemPort", log.Fields{"device-id": onuTP.deviceID, |
| 963 | "aUniID": aUniID, "aTPID": aTpID, "uniTPKey": uniTpKey, |
| 964 | "GemId": gemPortParam.multicastGemPortID}) |
| 965 | gemPortIds = append(gemPortIds, gemPortParam.gemPortID) |
| 966 | } |
| 967 | } |
| 968 | } else { |
| 969 | logger.Debugw(ctx, "TechProfile doesn't exist", log.Fields{"device-id": onuTP.deviceID}) |
| 970 | } //else: the state is just ignored (does not exist) |
| 971 | logger.Debugw(ctx, "Gem PortID list", log.Fields{"device-id": onuTP.deviceID, "gemportList": gemPortIds}) |
| 972 | return gemPortIds |
| 973 | } |
| 974 | |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 975 | func (onuTP *onuUniTechProf) GetAllBidirectionalGemPortIDsForOnu() []uint16 { |
| 976 | var gemPortInstIDs []uint16 |
| 977 | onuTP.mutexTPState.RLock() |
| 978 | defer onuTP.mutexTPState.RUnlock() |
| 979 | for _, tcontGemList := range onuTP.mapPonAniConfig { |
| 980 | for gemPortID, gemPortData := range tcontGemList.mapGemPortParams { |
| 981 | if gemPortData != nil && !gemPortData.isMulticast { // only if not multicast gem port |
| 982 | gemPortInstIDs = append(gemPortInstIDs, gemPortID) |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | return gemPortInstIDs |
| 987 | } |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 988 | |
| 989 | // setProfileResetting sets/resets the indication, that a reset of the TechProfileConfig/Removal is ongoing |
| 990 | func (onuTP *onuUniTechProf) setProfileResetting(ctx context.Context, aUniID uint8, aTpID uint8, aState bool) { |
| 991 | uniTpKey := uniTP{uniID: aUniID, tpID: aTpID} |
| 992 | onuTP.mutexTPState.Lock() |
| 993 | defer onuTP.mutexTPState.Unlock() |
| 994 | onuTP.tpProfileResetting[uniTpKey] = aState |
| 995 | } |
| 996 | |
| 997 | // getProfileResetting returns true, if the the according indication for started reset procedure is set |
| 998 | func (onuTP *onuUniTechProf) getProfileResetting(aUniTpKey uniTP) bool { |
| 999 | onuTP.mutexTPState.RLock() |
| 1000 | defer onuTP.mutexTPState.RUnlock() |
| 1001 | if isResetting, exist := onuTP.tpProfileResetting[aUniTpKey]; exist { |
| 1002 | return isResetting |
| 1003 | } |
| 1004 | return false |
| 1005 | } |