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