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