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