mpagenko | dff5dda | 2020-08-28 11:52:01 +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/binary" |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 23 | "fmt" |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 24 | "net" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 25 | "strconv" |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 26 | "sync" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 27 | "time" |
| 28 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 29 | gp "github.com/google/gopacket" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 30 | "github.com/looplab/fsm" |
| 31 | "github.com/opencord/omci-lib-go" |
| 32 | me "github.com/opencord/omci-lib-go/generated" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 33 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
| 34 | of "github.com/opencord/voltha-protos/v4/go/openflow_13" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 35 | ) |
| 36 | |
| 37 | const ( |
| 38 | // internal predefined values |
| 39 | cDefaultDownstreamMode = 0 |
| 40 | cDefaultTpid = 0x8100 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 41 | cVtfdTableSize = 12 //as per G.988 |
| 42 | cMaxAllowedFlows = cVtfdTableSize //which might be under discussion, for the moment connected to limit of VLAN's within VTFD |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 43 | ) |
| 44 | |
| 45 | const ( |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 46 | // internal offsets for requestEvent according to definition in onu_device_entry::OnuDeviceEvent |
| 47 | cDeviceEventOffsetAddWithKvStore = 0 //OmciVlanFilterAddDone - OmciVlanFilterAddDone cannot use because of lint |
| 48 | cDeviceEventOffsetAddNoKvStore = OmciVlanFilterAddDoneNoKvStore - OmciVlanFilterAddDone |
| 49 | cDeviceEventOffsetRemoveWithKvStore = OmciVlanFilterRemDone - OmciVlanFilterAddDone |
| 50 | cDeviceEventOffsetRemoveNoKvStore = OmciVlanFilterRemDoneNoKvStore - OmciVlanFilterAddDone |
| 51 | ) |
| 52 | |
| 53 | const ( |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 54 | // bit mask offsets for EVTOCD VlanTaggingOperationTable related to 32 bits (4 bytes) |
| 55 | cFilterPrioOffset = 28 |
| 56 | cFilterVidOffset = 15 |
| 57 | cFilterTpidOffset = 12 |
| 58 | cFilterEtherTypeOffset = 0 |
| 59 | cTreatTTROffset = 30 |
| 60 | cTreatPrioOffset = 16 |
| 61 | cTreatVidOffset = 3 |
| 62 | cTreatTpidOffset = 0 |
| 63 | ) |
| 64 | const ( |
| 65 | // byte offsets for EVTOCD VlanTaggingOperationTable related to overall 16 byte size with slice byte 0 as first Byte (MSB) |
| 66 | cFilterOuterOffset = 0 |
| 67 | cFilterInnerOffset = 4 |
| 68 | cTreatOuterOffset = 8 |
| 69 | cTreatInnerOffset = 12 |
| 70 | ) |
| 71 | const ( |
| 72 | // basic values used within EVTOCD VlanTaggingOperationTable in respect to their bitfields |
| 73 | cPrioIgnoreTag uint32 = 15 |
| 74 | cPrioDefaultFilter uint32 = 14 |
| 75 | cPrioDoNotFilter uint32 = 8 |
| 76 | cDoNotFilterVid uint32 = 4096 |
| 77 | cDoNotFilterTPID uint32 = 0 |
| 78 | cDoNotFilterEtherType uint32 = 0 |
| 79 | cDoNotAddPrio uint32 = 15 |
| 80 | cCopyPrioFromInner uint32 = 8 |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 81 | //cDontCarePrio uint32 = 0 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 82 | cDontCareVid uint32 = 0 |
| 83 | cDontCareTpid uint32 = 0 |
| 84 | cSetOutputTpidCopyDei uint32 = 4 |
| 85 | ) |
| 86 | |
| 87 | const ( |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 88 | // events of config UNI port VLAN FSM |
mpagenko | 535d6ef | 2021-02-26 13:15:34 +0000 | [diff] [blame] | 89 | vlanEvStart = "vlanEvStart" |
| 90 | vlanEvWaitTechProf = "vlanEvWaitTechProf" |
| 91 | vlanEvCancelOutstandingConfig = "vlanEvCancelOutstandingConfig" |
| 92 | vlanEvContinueConfig = "vlanEvContinueConfig" |
| 93 | vlanEvStartConfig = "vlanEvStartConfig" |
| 94 | vlanEvRxConfigVtfd = "vlanEvRxConfigVtfd" |
| 95 | vlanEvRxConfigEvtocd = "vlanEvRxConfigEvtocd" |
| 96 | vlanEvWaitTPIncr = "vlanEvWaitTPIncr" |
| 97 | vlanEvIncrFlowConfig = "vlanEvIncrFlowConfig" |
| 98 | vlanEvRenew = "vlanEvRenew" |
| 99 | vlanEvRemFlowConfig = "vlanEvRemFlowConfig" |
| 100 | vlanEvRemFlowDone = "vlanEvRemFlowDone" |
| 101 | vlanEvFlowDataRemoved = "vlanEvFlowDataRemoved" |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 102 | //vlanEvTimeoutSimple = "vlanEvTimeoutSimple" |
| 103 | //vlanEvTimeoutMids = "vlanEvTimeoutMids" |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 104 | vlanEvReset = "vlanEvReset" |
| 105 | vlanEvRestart = "vlanEvRestart" |
| 106 | vlanEvSkipOmciConfig = "vlanEvSkipOmciConfig" |
| 107 | vlanEvSkipIncFlowConfig = "vlanEvSkipIncFlowConfig" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 108 | ) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 109 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 110 | const ( |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 111 | // states of config UNI port VLAN FSM |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 112 | vlanStDisabled = "vlanStDisabled" |
| 113 | vlanStStarting = "vlanStStarting" |
| 114 | vlanStWaitingTechProf = "vlanStWaitingTechProf" |
| 115 | vlanStConfigVtfd = "vlanStConfigVtfd" |
| 116 | vlanStConfigEvtocd = "vlanStConfigEvtocd" |
| 117 | vlanStConfigDone = "vlanStConfigDone" |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 118 | vlanStIncrFlowWaitTP = "vlanStIncrFlowWaitTP" |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 119 | vlanStConfigIncrFlow = "vlanStConfigIncrFlow" |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 120 | vlanStRemoveFlow = "vlanStRemoveFlow" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 121 | vlanStCleanupDone = "vlanStCleanupDone" |
| 122 | vlanStResetting = "vlanStResetting" |
| 123 | ) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 124 | const cVlanFsmIdleState = vlanStConfigDone // state where no OMCI activity is done (for a longer time) |
| 125 | const cVlanFsmConfiguredState = vlanStConfigDone // state that indicates that at least some valid user related VLAN configuration should exist |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 126 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 127 | type uniVlanRuleParams struct { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 128 | TpID uint8 `json:"tp_id"` |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 129 | MatchVid uint32 `json:"match_vid"` //use uint32 types for allowing immediate bitshifting |
| 130 | MatchPcp uint32 `json:"match_pcp"` |
| 131 | TagsToRemove uint32 `json:"tags_to_remove"` |
| 132 | SetVid uint32 `json:"set_vid"` |
| 133 | SetPcp uint32 `json:"set_pcp"` |
| 134 | } |
| 135 | |
| 136 | type uniVlanFlowParams struct { |
| 137 | CookieSlice []uint64 `json:"cookie_slice"` |
| 138 | VlanRuleParams uniVlanRuleParams `json:"vlan_rule_params"` |
| 139 | } |
| 140 | |
| 141 | type uniRemoveVlanFlowParams struct { |
| 142 | cookie uint64 //just the last cookie valid for removal |
| 143 | vlanRuleParams uniVlanRuleParams |
| 144 | } |
| 145 | |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 146 | //UniVlanConfigFsm defines the structure for the state machine for configuration of the VLAN related setting via OMCI |
| 147 | // builds upon 'VLAN rules' that are derived from multiple flows |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 148 | type UniVlanConfigFsm struct { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 149 | pDeviceHandler *deviceHandler |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 150 | deviceID string |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 151 | pOmciCC *omciCC |
| 152 | pOnuUniPort *onuUniPort |
| 153 | pUniTechProf *onuUniTechProf |
| 154 | pOnuDB *onuDeviceDB |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 155 | requestEvent OnuDeviceEvent |
| 156 | omciMIdsResponseReceived chan bool //seperate channel needed for checking multiInstance OMCI message responses |
| 157 | pAdaptFsm *AdapterFsm |
| 158 | acceptIncrementalEvtoOption bool |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 159 | clearPersistency bool |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 160 | isCanceled bool |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 161 | isAwaitingResponse bool |
| 162 | mutexIsAwaitingResponse sync.RWMutex |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 163 | mutexFlowParams sync.RWMutex |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 164 | chCookieDeleted chan bool //channel to indicate that a specific cookie (related to the active rule) was deleted |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 165 | actualUniVlanConfigRule uniVlanRuleParams |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 166 | uniVlanFlowParamsSlice []uniVlanFlowParams |
| 167 | uniRemoveFlowsSlice []uniRemoveVlanFlowParams |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 168 | numUniFlows uint8 // expected number of flows should be less than 12 |
| 169 | configuredUniFlow uint8 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 170 | numRemoveFlows uint8 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 171 | numVlanFilterEntries uint8 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 172 | vlanFilterList [cVtfdTableSize]uint16 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 173 | evtocdID uint16 |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 174 | mutexPLastTxMeInstance sync.RWMutex |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 175 | pLastTxMeInstance *me.ManagedEntity |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 176 | requestEventOffset uint8 |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 177 | TpIDWaitingFor uint8 |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 178 | signalOnFlowDelete bool |
| 179 | flowDeleteChannel chan<- bool |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 180 | //cookie value that indicates that a rule to add is delayed by waiting for deletion of some other existing rule with the same cookie |
| 181 | delayNewRuleCookie uint64 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 182 | } |
| 183 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 184 | //NewUniVlanConfigFsm is the 'constructor' for the state machine to config the PON ANI ports |
| 185 | // of ONU UNI ports via OMCI |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 186 | func NewUniVlanConfigFsm(ctx context.Context, apDeviceHandler *deviceHandler, apDevOmciCC *omciCC, apUniPort *onuUniPort, |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 187 | apUniTechProf *onuUniTechProf, apOnuDB *onuDeviceDB, aTechProfileID uint8, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 188 | aRequestEvent OnuDeviceEvent, aName string, aCommChannel chan Message, aAcceptIncrementalEvto bool, |
| 189 | aCookieSlice []uint64, aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) *UniVlanConfigFsm { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 190 | instFsm := &UniVlanConfigFsm{ |
| 191 | pDeviceHandler: apDeviceHandler, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 192 | deviceID: apDeviceHandler.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 193 | pOmciCC: apDevOmciCC, |
| 194 | pOnuUniPort: apUniPort, |
| 195 | pUniTechProf: apUniTechProf, |
| 196 | pOnuDB: apOnuDB, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 197 | requestEvent: aRequestEvent, |
| 198 | acceptIncrementalEvtoOption: aAcceptIncrementalEvto, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 199 | numUniFlows: 0, |
| 200 | configuredUniFlow: 0, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 201 | numRemoveFlows: 0, |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 202 | clearPersistency: true, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 203 | } |
| 204 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 205 | instFsm.pAdaptFsm = NewAdapterFsm(aName, instFsm.deviceID, aCommChannel) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 206 | if instFsm.pAdaptFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 207 | logger.Errorw(ctx, "UniVlanConfigFsm's AdapterFsm could not be instantiated!!", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 208 | "device-id": instFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 209 | return nil |
| 210 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 211 | instFsm.pAdaptFsm.pFsm = fsm.NewFSM( |
| 212 | vlanStDisabled, |
| 213 | fsm.Events{ |
| 214 | {Name: vlanEvStart, Src: []string{vlanStDisabled}, Dst: vlanStStarting}, |
| 215 | {Name: vlanEvWaitTechProf, Src: []string{vlanStStarting}, Dst: vlanStWaitingTechProf}, |
mpagenko | 535d6ef | 2021-02-26 13:15:34 +0000 | [diff] [blame] | 216 | {Name: vlanEvCancelOutstandingConfig, Src: []string{vlanStWaitingTechProf}, Dst: vlanStConfigDone}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 217 | {Name: vlanEvContinueConfig, Src: []string{vlanStWaitingTechProf}, Dst: vlanStConfigVtfd}, |
| 218 | {Name: vlanEvStartConfig, Src: []string{vlanStStarting}, Dst: vlanStConfigVtfd}, |
| 219 | {Name: vlanEvRxConfigVtfd, Src: []string{vlanStConfigVtfd}, Dst: vlanStConfigEvtocd}, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 220 | {Name: vlanEvRxConfigEvtocd, Src: []string{vlanStConfigEvtocd, vlanStConfigIncrFlow}, |
| 221 | Dst: vlanStConfigDone}, |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 222 | {Name: vlanEvRenew, Src: []string{vlanStConfigDone}, Dst: vlanStStarting}, |
| 223 | {Name: vlanEvWaitTPIncr, Src: []string{vlanStConfigDone}, Dst: vlanStIncrFlowWaitTP}, |
| 224 | {Name: vlanEvIncrFlowConfig, Src: []string{vlanStConfigDone, vlanStIncrFlowWaitTP}, |
| 225 | Dst: vlanStConfigIncrFlow}, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 226 | {Name: vlanEvRemFlowConfig, Src: []string{vlanStConfigDone}, Dst: vlanStRemoveFlow}, |
| 227 | {Name: vlanEvRemFlowDone, Src: []string{vlanStRemoveFlow}, Dst: vlanStCleanupDone}, |
| 228 | {Name: vlanEvFlowDataRemoved, Src: []string{vlanStCleanupDone}, Dst: vlanStConfigDone}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 229 | /* |
| 230 | {Name: vlanEvTimeoutSimple, Src: []string{ |
| 231 | vlanStCreatingDot1PMapper, vlanStCreatingMBPCD, vlanStSettingTconts, vlanStSettingDot1PMapper}, Dst: vlanStStarting}, |
| 232 | {Name: vlanEvTimeoutMids, Src: []string{ |
| 233 | vlanStCreatingGemNCTPs, vlanStCreatingGemIWs, vlanStSettingPQs}, Dst: vlanStStarting}, |
| 234 | */ |
| 235 | // exceptional treatment for all states except vlanStResetting |
| 236 | {Name: vlanEvReset, Src: []string{vlanStStarting, vlanStWaitingTechProf, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 237 | vlanStConfigVtfd, vlanStConfigEvtocd, vlanStConfigDone, vlanStConfigIncrFlow, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 238 | vlanStRemoveFlow, vlanStCleanupDone}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 239 | Dst: vlanStResetting}, |
| 240 | // the only way to get to resource-cleared disabled state again is via "resseting" |
| 241 | {Name: vlanEvRestart, Src: []string{vlanStResetting}, Dst: vlanStDisabled}, |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 242 | // transitions for reconcile handling according to VOL-3834 |
| 243 | {Name: vlanEvSkipOmciConfig, Src: []string{vlanStStarting}, Dst: vlanStConfigDone}, |
| 244 | {Name: vlanEvSkipOmciConfig, Src: []string{vlanStConfigDone}, Dst: vlanStConfigIncrFlow}, |
| 245 | {Name: vlanEvSkipIncFlowConfig, Src: []string{vlanStConfigIncrFlow}, Dst: vlanStConfigDone}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 246 | }, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 247 | fsm.Callbacks{ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 248 | "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(ctx, e) }, |
| 249 | "enter_" + vlanStStarting: func(e *fsm.Event) { instFsm.enterConfigStarting(ctx, e) }, |
| 250 | "enter_" + vlanStConfigVtfd: func(e *fsm.Event) { instFsm.enterConfigVtfd(ctx, e) }, |
| 251 | "enter_" + vlanStConfigEvtocd: func(e *fsm.Event) { instFsm.enterConfigEvtocd(ctx, e) }, |
| 252 | "enter_" + vlanStConfigDone: func(e *fsm.Event) { instFsm.enterVlanConfigDone(ctx, e) }, |
| 253 | "enter_" + vlanStConfigIncrFlow: func(e *fsm.Event) { instFsm.enterConfigIncrFlow(ctx, e) }, |
| 254 | "enter_" + vlanStRemoveFlow: func(e *fsm.Event) { instFsm.enterRemoveFlow(ctx, e) }, |
| 255 | "enter_" + vlanStCleanupDone: func(e *fsm.Event) { instFsm.enterVlanCleanupDone(ctx, e) }, |
| 256 | "enter_" + vlanStResetting: func(e *fsm.Event) { instFsm.enterResetting(ctx, e) }, |
| 257 | "enter_" + vlanStDisabled: func(e *fsm.Event) { instFsm.enterDisabled(ctx, e) }, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 258 | }, |
| 259 | ) |
| 260 | if instFsm.pAdaptFsm.pFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 261 | logger.Errorw(ctx, "UniVlanConfigFsm's Base FSM could not be instantiated!!", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 262 | "device-id": instFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 263 | return nil |
| 264 | } |
| 265 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 266 | _ = instFsm.initUniFlowParams(ctx, aTechProfileID, aCookieSlice, aMatchVlan, aSetVlan, aSetPcp) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 267 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 268 | logger.Debugw(ctx, "UniVlanConfigFsm created", log.Fields{"device-id": instFsm.deviceID, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 269 | "accIncrEvto": instFsm.acceptIncrementalEvtoOption}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 270 | return instFsm |
| 271 | } |
| 272 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 273 | //initUniFlowParams is a simplified form of SetUniFlowParams() used for first flow parameters configuration |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 274 | func (oFsm *UniVlanConfigFsm) initUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 275 | aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) error { |
| 276 | loRuleParams := uniVlanRuleParams{ |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 277 | TpID: aTpID, |
| 278 | MatchVid: uint32(aMatchVlan), |
| 279 | SetVid: uint32(aSetVlan), |
| 280 | SetPcp: uint32(aSetPcp), |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 281 | } |
| 282 | // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 283 | loRuleParams.TagsToRemove = 1 //one tag to remove as default setting |
| 284 | loRuleParams.MatchPcp = cPrioDoNotFilter // do not Filter on prio as default |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 285 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 286 | if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 287 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 288 | loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 289 | //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther) |
| 290 | } else { |
| 291 | if !oFsm.acceptIncrementalEvtoOption { |
| 292 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 293 | loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 297 | if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 298 | // no prio/vid filtering requested |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 299 | loRuleParams.TagsToRemove = 0 //no tag pop action |
| 300 | loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering |
| 301 | if loRuleParams.SetPcp == cCopyPrioFromInner { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 302 | //in case of no filtering and configured PrioCopy ensure default prio setting to 0 |
| 303 | // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged |
| 304 | // might collide with NoMatchVid/CopyPrio(/setVid) setting |
| 305 | // this was some precondition setting taken over from py adapter .. |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 306 | loRuleParams.SetPcp = 0 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 307 | } |
| 308 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 309 | |
| 310 | loFlowParams := uniVlanFlowParams{VlanRuleParams: loRuleParams} |
| 311 | loFlowParams.CookieSlice = make([]uint64, 0) |
| 312 | loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...) |
| 313 | |
| 314 | //no mutex protection is required for initial access and adding the first flow is always possible |
| 315 | oFsm.uniVlanFlowParamsSlice = make([]uniVlanFlowParams, 0) |
| 316 | oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 317 | logger.Debugw(ctx, "first UniVlanConfigFsm flow added", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 318 | "Cookies": oFsm.uniVlanFlowParamsSlice[0].CookieSlice, |
| 319 | "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16), |
| 320 | "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16), |
| 321 | "SetPcp": loRuleParams.SetPcp, |
| 322 | "device-id": oFsm.deviceID}) |
| 323 | oFsm.numUniFlows = 1 |
| 324 | oFsm.uniRemoveFlowsSlice = make([]uniRemoveVlanFlowParams, 0) //initially nothing to remove |
| 325 | |
| 326 | //permanently store flow config for reconcile case |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 327 | if err := oFsm.pDeviceHandler.storePersUniFlowConfig(ctx, oFsm.pOnuUniPort.uniID, |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 328 | &oFsm.uniVlanFlowParamsSlice, true); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 329 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 330 | return err |
| 331 | } |
| 332 | |
| 333 | return nil |
| 334 | } |
| 335 | |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 336 | //CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 337 | func (oFsm *UniVlanConfigFsm) CancelProcessing(ctx context.Context) { |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 338 | //mutex protection is required for possible concurrent access to FSM members |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 339 | oFsm.mutexIsAwaitingResponse.Lock() |
| 340 | oFsm.isCanceled = true |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 341 | if oFsm.isAwaitingResponse { |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 342 | //attention: for an unbuffered channel the sender is blocked until the value is received (processed)! |
| 343 | // accordingly the mutex must be released before sending to channel here (mutex acquired in receiver) |
| 344 | oFsm.mutexIsAwaitingResponse.Unlock() |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 345 | //use channel to indicate that the response waiting shall be aborted |
| 346 | oFsm.omciMIdsResponseReceived <- false |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 347 | } else { |
| 348 | oFsm.mutexIsAwaitingResponse.Unlock() |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 349 | } |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 350 | |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 351 | // in any case (even if it might be automatically requested by above cancellation of waiting) ensure resetting the FSM |
| 352 | pAdaptFsm := oFsm.pAdaptFsm |
| 353 | if pAdaptFsm != nil { |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 354 | if fsmErr := pAdaptFsm.pFsm.Event(vlanEvReset); fsmErr != nil { |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 355 | logger.Errorw(ctx, "reset-event failed in UniVlanConfigFsm!", |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 356 | log.Fields{"fsmState": oFsm.pAdaptFsm.pFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 357 | } |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 361 | //GetWaitingTpID returns the TpId that the FSM might be waiting for continuation (0 if none) |
| 362 | func (oFsm *UniVlanConfigFsm) GetWaitingTpID() uint8 { |
| 363 | //mutex protection is required for possible concurrent access to FSM members |
| 364 | oFsm.mutexFlowParams.RLock() |
| 365 | defer oFsm.mutexFlowParams.RUnlock() |
| 366 | return oFsm.TpIDWaitingFor |
| 367 | } |
| 368 | |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 369 | //RequestClearPersistency sets the internal flag to not clear persistency data (false=NoClear) |
| 370 | func (oFsm *UniVlanConfigFsm) RequestClearPersistency(aClear bool) { |
| 371 | //mutex protection is required for possible concurrent access to FSM members |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 372 | oFsm.mutexFlowParams.Lock() |
| 373 | defer oFsm.mutexFlowParams.Unlock() |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 374 | oFsm.clearPersistency = aClear |
| 375 | } |
| 376 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 377 | //SetUniFlowParams verifies on existence of flow parameters to be configured, |
| 378 | // optionally udates the cookie list or appends a new flow if there is space |
| 379 | // if possible the FSM is trigggerd to start with the processing |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 380 | // ignore complexity by now |
| 381 | // nolint: gocyclo |
| 382 | func (oFsm *UniVlanConfigFsm) SetUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 383 | aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) error { |
| 384 | loRuleParams := uniVlanRuleParams{ |
| 385 | TpID: aTpID, |
| 386 | MatchVid: uint32(aMatchVlan), |
| 387 | SetVid: uint32(aSetVlan), |
| 388 | SetPcp: uint32(aSetPcp), |
| 389 | } |
| 390 | // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters |
| 391 | loRuleParams.TagsToRemove = 1 //one tag to remove as default setting |
| 392 | loRuleParams.MatchPcp = cPrioDoNotFilter // do not Filter on prio as default |
| 393 | |
| 394 | if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 395 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
| 396 | loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
| 397 | //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther) |
| 398 | } else { |
| 399 | if !oFsm.acceptIncrementalEvtoOption { |
| 400 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
| 401 | loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 406 | // no prio/vid filtering requested |
| 407 | loRuleParams.TagsToRemove = 0 //no tag pop action |
| 408 | loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering |
| 409 | if loRuleParams.SetPcp == cCopyPrioFromInner { |
| 410 | //in case of no filtering and configured PrioCopy ensure default prio setting to 0 |
| 411 | // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged |
| 412 | // might collide with NoMatchVid/CopyPrio(/setVid) setting |
| 413 | // this was some precondition setting taken over from py adapter .. |
| 414 | loRuleParams.SetPcp = 0 |
| 415 | } |
| 416 | } |
| 417 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 418 | flowEntryMatch := false |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 419 | flowCookieModify := false |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 420 | requestAppendRule := false |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 421 | //mutex protection is required for possible concurrent access to FSM members |
| 422 | oFsm.mutexFlowParams.Lock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 423 | for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
| 424 | //TODO: Verify if using e.g. hashes for the structures here for comparison may generate |
| 425 | // countable run time optimization (perhaps with including the hash in kvStore storage?) |
| 426 | if storedUniFlowParams.VlanRuleParams == loRuleParams { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 427 | flowEntryMatch = true |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 428 | logger.Debugw(ctx, "UniVlanConfigFsm flow setting - rule already exists", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 429 | "device-id": oFsm.deviceID}) |
| 430 | var cookieMatch bool |
| 431 | for _, newCookie := range aCookieSlice { // for all cookies available in the arguments |
| 432 | cookieMatch = false |
| 433 | for _, cookie := range storedUniFlowParams.CookieSlice { |
| 434 | if cookie == newCookie { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 435 | logger.Debugw(ctx, "UniVlanConfigFsm flow setting - and cookie already exists", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 436 | "device-id": oFsm.deviceID, "cookie": cookie}) |
| 437 | cookieMatch = true |
| 438 | break //found new cookie - no further search for this requested cookie |
| 439 | } |
| 440 | } |
| 441 | if !cookieMatch { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 442 | delayedCookie := oFsm.delayNewRuleForCookie(ctx, aCookieSlice) |
| 443 | if delayedCookie != 0 { |
| 444 | //a delay for adding the cookie to this rule is requested |
| 445 | // take care of the mutex which is already locked here, need to unlock/lock accordingly to prevent deadlock in suspension |
| 446 | oFsm.mutexFlowParams.Unlock() |
| 447 | oFsm.suspendNewRule(ctx) |
| 448 | flowCookieModify, requestAppendRule = oFsm.reviseFlowConstellation(ctx, delayedCookie, loRuleParams) |
| 449 | oFsm.mutexFlowParams.Lock() |
| 450 | } else { |
| 451 | logger.Debugw(ctx, "UniVlanConfigFsm flow setting -adding new cookie", log.Fields{ |
| 452 | "device-id": oFsm.deviceID, "cookie": newCookie}) |
| 453 | //as range works with copies of the slice we have to write to the original slice!! |
| 454 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(oFsm.uniVlanFlowParamsSlice[flow].CookieSlice, |
| 455 | newCookie) |
| 456 | flowCookieModify = true |
| 457 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 458 | } |
| 459 | } //for all new cookies |
| 460 | break // found rule - no further rule search |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 461 | } |
| 462 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 463 | oFsm.mutexFlowParams.Unlock() |
| 464 | |
| 465 | if !flowEntryMatch { //it is (was) a new rule |
| 466 | delayedCookie := oFsm.suspendIfRequiredNewRule(ctx, aCookieSlice) |
| 467 | requestAppendRule = true //default assumption here is that rule is to be appended |
| 468 | flowCookieModify = true //and that the the flow data base is to be updated |
| 469 | if delayedCookie != 0 { //it was suspended |
| 470 | flowCookieModify, requestAppendRule = oFsm.reviseFlowConstellation(ctx, delayedCookie, loRuleParams) |
| 471 | } |
| 472 | } |
| 473 | kvStoreWrite := false //default setting is to not write to kvStore immediately - will be done on FSM execution finally |
| 474 | if requestAppendRule { |
| 475 | oFsm.mutexFlowParams.Lock() |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 476 | if oFsm.numUniFlows < cMaxAllowedFlows { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 477 | loFlowParams := uniVlanFlowParams{VlanRuleParams: loRuleParams} |
| 478 | loFlowParams.CookieSlice = make([]uint64, 0) |
| 479 | loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...) |
| 480 | oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 481 | logger.Debugw(ctx, "UniVlanConfigFsm flow add", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 482 | "Cookies": oFsm.uniVlanFlowParamsSlice[oFsm.numUniFlows].CookieSlice, |
| 483 | "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16), |
| 484 | "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16), |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 485 | "SetPcp": loRuleParams.SetPcp, "numberofFlows": oFsm.numUniFlows + 1, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 486 | "device-id": oFsm.deviceID}) |
| 487 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 488 | oFsm.numUniFlows++ |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 489 | pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm |
| 490 | |
| 491 | if oFsm.pDeviceHandler.isSkipOnuConfigReconciling() { |
| 492 | logger.Debugw(ctx, "reconciling - skip omci-config of additional vlan rule", |
| 493 | log.Fields{"fsmState": oFsm.pAdaptFsm.pFsm.Current(), "device-id": oFsm.deviceID}) |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 494 | //attention: take care to release the mutexFlowParams when calling the FSM directly - |
| 495 | // synchronous FSM 'event/state' functions may rely on this mutex |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 496 | oFsm.mutexFlowParams.Unlock() |
| 497 | if pConfigVlanStateBaseFsm.Is(vlanStConfigDone) { |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 498 | if fsmErr := pConfigVlanStateBaseFsm.Event(vlanEvSkipOmciConfig); fsmErr != nil { |
| 499 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!", |
| 500 | log.Fields{"fsmState": oFsm.pAdaptFsm.pFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
| 501 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 502 | } |
| 503 | return nil |
| 504 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 505 | // note: theoretical it would be possible to clear the same rule from the remove slice |
| 506 | // (for entries that have not yet been started with removal) |
| 507 | // but that is getting quite complicated - maybe a future optimization in case it should prove reasonable |
| 508 | // anyway the precondition here is that the FSM checks for rules to delete first and adds new rules afterwards |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 509 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 510 | if pConfigVlanStateBaseFsm.Is(vlanStConfigDone) { |
| 511 | //have to re-trigger the FSM to proceed with outstanding incremental flow configuration |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 512 | if oFsm.configuredUniFlow == 0 { |
| 513 | // this is a restart with a complete new flow, we can re-use the initial flow config control |
| 514 | // including the check, if the related techProfile is (still) available (probably also removed in between) |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 515 | //attention: take care to release the mutexFlowParams when calling the FSM directly - |
| 516 | // synchronous FSM 'event/state' functions may rely on this mutex |
| 517 | oFsm.mutexFlowParams.Unlock() |
| 518 | if fsmErr := pConfigVlanStateBaseFsm.Event(vlanEvRenew); fsmErr != nil { |
| 519 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!", |
| 520 | log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
| 521 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 522 | } else { |
| 523 | //some further flows are to be configured |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 524 | //store the actual rule that shall be worked upon in the following transient states |
| 525 | oFsm.actualUniVlanConfigRule = oFsm.uniVlanFlowParamsSlice[oFsm.configuredUniFlow].VlanRuleParams |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 526 | //tpId of the next rule to be configured |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 527 | tpID := oFsm.actualUniVlanConfigRule.TpID |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 528 | loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.uniID, tpID) |
| 529 | oFsm.TpIDWaitingFor = tpID |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 530 | logger.Debugw(ctx, "UniVlanConfigFsm - incremental config request (on setConfig)", log.Fields{ |
| 531 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, |
| 532 | "set-Vlan": oFsm.actualUniVlanConfigRule.SetVid, "tp-id": tpID, "ProfDone": loTechProfDone}) |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 533 | |
| 534 | //attention: take care to release the mutexFlowParams when calling the FSM directly - |
| 535 | // synchronous FSM 'event/state' functions may rely on this mutex |
| 536 | oFsm.mutexFlowParams.Unlock() |
| 537 | var fsmErr error |
| 538 | if loTechProfDone { |
| 539 | // let the vlan processing continue with next rule |
| 540 | fsmErr = pConfigVlanStateBaseFsm.Event(vlanEvIncrFlowConfig) |
| 541 | } else { |
| 542 | // set to waiting for Techprofile |
| 543 | fsmErr = pConfigVlanStateBaseFsm.Event(vlanEvWaitTPIncr) |
| 544 | } |
| 545 | if fsmErr != nil { |
| 546 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!", |
| 547 | log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
| 548 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 549 | } |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 550 | } else { |
| 551 | // if not in the appropriate state a new entry will be automatically considered later |
| 552 | // when the configDone state is reached |
| 553 | oFsm.mutexFlowParams.Unlock() |
| 554 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 555 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 556 | logger.Errorw(ctx, "UniVlanConfigFsm flow limit exceeded", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 557 | "device-id": oFsm.deviceID, "flow-number": oFsm.numUniFlows}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 558 | oFsm.mutexFlowParams.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 559 | return fmt.Errorf(" UniVlanConfigFsm flow limit exceeded %s", oFsm.deviceID) |
| 560 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 561 | } else { |
| 562 | // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 563 | kvStoreWrite = true // ensure actual data write to kvStore immediately (no FSM activity) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 564 | oFsm.mutexFlowParams.RLock() |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 565 | if oFsm.numUniFlows == oFsm.configuredUniFlow { |
| 566 | //all requested rules really have been configured |
| 567 | // state transition notification is checked in deviceHandler |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 568 | oFsm.mutexFlowParams.RUnlock() |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 569 | if oFsm.pDeviceHandler != nil { |
| 570 | //also the related TechProfile was already configured |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 571 | logger.Debugw(ctx, "UniVlanConfigFsm rule already set - send immediate add-success event for reason update", log.Fields{ |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 572 | "device-id": oFsm.deviceID}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 573 | // success indication without the need to write to kvStore (done already below with updated data from storePersUniFlowConfig()) |
| 574 | go oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetAddNoKvStore)) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 575 | } |
| 576 | } else { |
| 577 | // avoid device reason update as the rule config connected to this flow may still be in progress |
| 578 | // and the device reason should only be updated on success of rule config |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 579 | logger.Debugw(ctx, "UniVlanConfigFsm rule already set but configuration ongoing, suppress early add-success event for reason update", |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 580 | log.Fields{"device-id": oFsm.deviceID, |
| 581 | "NumberofRules": oFsm.numUniFlows, "Configured rules": oFsm.configuredUniFlow}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 582 | oFsm.mutexFlowParams.RUnlock() |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 583 | } |
| 584 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 585 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 586 | if flowCookieModify { // some change was done to the flow entries |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 587 | //permanently store flow config for reconcile case |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 588 | oFsm.mutexFlowParams.RLock() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 589 | if err := oFsm.pDeviceHandler.storePersUniFlowConfig(ctx, oFsm.pOnuUniPort.uniID, |
| 590 | &oFsm.uniVlanFlowParamsSlice, kvStoreWrite); err != nil { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 591 | oFsm.mutexFlowParams.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 592 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 593 | return err |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 594 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 595 | oFsm.mutexFlowParams.RUnlock() |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 596 | } |
| 597 | return nil |
| 598 | } |
| 599 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 600 | // VOL-3828 flow config sequence workaround ########### start ########## |
| 601 | func (oFsm *UniVlanConfigFsm) delayNewRuleForCookie(ctx context.Context, aCookieSlice []uint64) uint64 { |
| 602 | //assumes mutexFlowParams.Lock() protection from caller! |
| 603 | if oFsm.delayNewRuleCookie == 0 && len(aCookieSlice) == 1 { |
| 604 | // if not already waiting, limitation for this workaround is to just have one overlapping cookie/rule |
| 605 | // suspend check is done only of there is only one cookie in the request |
| 606 | // background: more elements only expected in reconcile use case, where no conflicting sequence is to be expected |
| 607 | newCookie := aCookieSlice[0] |
| 608 | for _, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
| 609 | for _, cookie := range storedUniFlowParams.CookieSlice { |
| 610 | if cookie == newCookie { |
| 611 | logger.Debugw(ctx, "UniVlanConfigFsm flow setting - new cookie still exists for some rule", log.Fields{ |
| 612 | "device-id": oFsm.deviceID, "cookie": cookie, "exists with SetVlan": storedUniFlowParams.VlanRuleParams.SetVid}) |
| 613 | oFsm.delayNewRuleCookie = newCookie |
| 614 | return newCookie //found new cookie in some existing rule |
| 615 | } |
| 616 | } // for all stored cookies of the actual inspected rule |
| 617 | } //for all rules |
| 618 | } |
| 619 | return 0 //no delay requested |
| 620 | } |
| 621 | func (oFsm *UniVlanConfigFsm) suspendNewRule(ctx context.Context) { |
| 622 | oFsm.mutexFlowParams.RLock() |
| 623 | logger.Infow(ctx, "Need to suspend adding this rule as long as the cookie is still connected to some other rule", log.Fields{ |
| 624 | "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie}) |
| 625 | oFsm.mutexFlowParams.RUnlock() |
| 626 | select { |
| 627 | case <-oFsm.chCookieDeleted: |
| 628 | logger.Infow(ctx, "resume adding this rule after having deleted cookie in some other rule", log.Fields{ |
| 629 | "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie}) |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 630 | case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 631 | logger.Errorw(ctx, "timeout waiting for deletion of cookie in some other rule, just try to continue", log.Fields{ |
| 632 | "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie}) |
| 633 | } |
| 634 | oFsm.mutexFlowParams.Lock() |
| 635 | oFsm.delayNewRuleCookie = 0 |
| 636 | oFsm.mutexFlowParams.Unlock() |
| 637 | } |
| 638 | func (oFsm *UniVlanConfigFsm) suspendIfRequiredNewRule(ctx context.Context, aCookieSlice []uint64) uint64 { |
| 639 | oFsm.mutexFlowParams.Lock() |
| 640 | delayedCookie := oFsm.delayNewRuleForCookie(ctx, aCookieSlice) |
| 641 | oFsm.mutexFlowParams.Unlock() |
| 642 | |
| 643 | if delayedCookie != 0 { |
| 644 | oFsm.suspendNewRule(ctx) |
| 645 | } |
| 646 | return delayedCookie |
| 647 | } |
| 648 | |
| 649 | //returns flowModified, RuleAppendRequest |
| 650 | func (oFsm *UniVlanConfigFsm) reviseFlowConstellation(ctx context.Context, aCookie uint64, aUniVlanRuleParams uniVlanRuleParams) (bool, bool) { |
| 651 | flowEntryMatch := false |
| 652 | oFsm.mutexFlowParams.Lock() |
| 653 | defer oFsm.mutexFlowParams.Unlock() |
| 654 | for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
| 655 | if storedUniFlowParams.VlanRuleParams == aUniVlanRuleParams { |
| 656 | flowEntryMatch = true |
| 657 | logger.Debugw(ctx, "UniVlanConfigFsm flow revise - rule already exists", log.Fields{ |
| 658 | "device-id": oFsm.deviceID}) |
| 659 | cookieMatch := false |
| 660 | for _, cookie := range storedUniFlowParams.CookieSlice { |
| 661 | if cookie == aCookie { |
| 662 | logger.Debugw(ctx, "UniVlanConfigFsm flow revise - and cookie already exists", log.Fields{ |
| 663 | "device-id": oFsm.deviceID, "cookie": cookie}) |
| 664 | cookieMatch = true |
| 665 | break //found new cookie - no further search for this requested cookie |
| 666 | } |
| 667 | } |
| 668 | if !cookieMatch { |
| 669 | logger.Debugw(ctx, "UniVlanConfigFsm flow revise -adding new cookie", log.Fields{ |
| 670 | "device-id": oFsm.deviceID, "cookie": aCookie}) |
| 671 | //as range works with copies of the slice we have to write to the original slice!! |
| 672 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(oFsm.uniVlanFlowParamsSlice[flow].CookieSlice, |
| 673 | aCookie) |
| 674 | return true, false //flowModified, NoRuleAppend |
| 675 | } |
| 676 | break // found rule - no further rule search |
| 677 | } |
| 678 | } |
| 679 | if !flowEntryMatch { //it is a new rule |
| 680 | return true, true //flowModified, RuleAppend |
| 681 | } |
| 682 | return false, false //flowNotModified, NoRuleAppend |
| 683 | } |
| 684 | |
| 685 | // VOL-3828 flow config sequence workaround ########### end ########## |
| 686 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 687 | //RemoveUniFlowParams verifies on existence of flow cookie, |
| 688 | // if found removes cookie from flow cookie list and if this is empty |
| 689 | // initiates removal of the flow related configuration from the ONU (via OMCI) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 690 | func (oFsm *UniVlanConfigFsm) RemoveUniFlowParams(ctx context.Context, aCookie uint64) error { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 691 | var deletedCookie uint64 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 692 | flowCookieMatch := false |
| 693 | //mutex protection is required for possible concurrent access to FSM members |
| 694 | oFsm.mutexFlowParams.Lock() |
| 695 | defer oFsm.mutexFlowParams.Unlock() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 696 | remove_loop: |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 697 | for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
| 698 | for i, cookie := range storedUniFlowParams.CookieSlice { |
| 699 | if cookie == aCookie { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 700 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - cookie found", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 701 | "device-id": oFsm.deviceID, "cookie": cookie}) |
| 702 | flowCookieMatch = true |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 703 | deletedCookie = aCookie |
| 704 | kvStoreWrite := false //default setting is to not write to kvStore immediately - will be done on FSM execution finally |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 705 | //remove the cookie from the cookie slice and verify it is getting empty |
| 706 | if len(storedUniFlowParams.CookieSlice) == 1 { |
mpagenko | 535d6ef | 2021-02-26 13:15:34 +0000 | [diff] [blame] | 707 | pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm |
| 708 | var cancelPendingConfig bool = false |
| 709 | var loRemoveParams uniRemoveVlanFlowParams = uniRemoveVlanFlowParams{} |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 710 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - full flow removal", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 711 | "device-id": oFsm.deviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 712 | //rwCore flow recovery may be the reason for this delete, in which case the flowToBeDeleted may be the same |
mpagenko | 535d6ef | 2021-02-26 13:15:34 +0000 | [diff] [blame] | 713 | // as the one still waiting in the FSM as toAdd but waiting for TechProfileConfig |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 714 | // so we have to check if we have to abort the outstanding AddRequest and regard the current DelRequest as done |
mpagenko | 535d6ef | 2021-02-26 13:15:34 +0000 | [diff] [blame] | 715 | // if the Fsm is in some other transient (config) state, we will reach the DelRequest later and correctly process it then |
| 716 | if pConfigVlanStateBaseFsm.Is(vlanStWaitingTechProf) { |
| 717 | logger.Debugw(ctx, "UniVlanConfigFsm was waiting for TechProf config with this rule, aborting the outstanding config", |
| 718 | log.Fields{"device-id": oFsm.deviceID}) |
| 719 | cancelPendingConfig = true |
| 720 | } else { |
| 721 | //create a new element for the removeVlanFlow slice |
| 722 | loRemoveParams = uniRemoveVlanFlowParams{ |
| 723 | vlanRuleParams: storedUniFlowParams.VlanRuleParams, |
| 724 | cookie: aCookie, |
| 725 | } |
| 726 | oFsm.uniRemoveFlowsSlice = append(oFsm.uniRemoveFlowsSlice, loRemoveParams) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 727 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 728 | |
| 729 | //and remove the actual element from the addVlanFlow slice |
| 730 | // oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = nil //automatically done by garbage collector |
| 731 | if len(oFsm.uniVlanFlowParamsSlice) <= 1 { |
| 732 | oFsm.numUniFlows = 0 //no more flows |
| 733 | oFsm.configuredUniFlow = 0 //no more flows configured |
| 734 | oFsm.uniVlanFlowParamsSlice = nil //reset the slice |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 735 | //at this point it is evident that no flow anymore refers to a still possibly active Techprofile |
mpagenko | 535d6ef | 2021-02-26 13:15:34 +0000 | [diff] [blame] | 736 | //request that this profile gets deleted before a new flow add is allowed (except for some aborted add) |
| 737 | if !cancelPendingConfig { |
| 738 | oFsm.pUniTechProf.setProfileToDelete(oFsm.pOnuUniPort.uniID, loRemoveParams.vlanRuleParams.TpID, true) |
| 739 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 740 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - no more flows", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 741 | "device-id": oFsm.deviceID}) |
| 742 | } else { |
| 743 | oFsm.numUniFlows-- |
| 744 | if oFsm.configuredUniFlow > 0 { |
| 745 | oFsm.configuredUniFlow-- |
| 746 | //TODO!! might be needed to consider still outstanding configure requests .. |
| 747 | // so a flow at removal might still not be configured !?! |
| 748 | } |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 749 | usedTpID := storedUniFlowParams.VlanRuleParams.TpID |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 750 | //cut off the requested flow by slicing out this element |
| 751 | oFsm.uniVlanFlowParamsSlice = append( |
| 752 | oFsm.uniVlanFlowParamsSlice[:flow], oFsm.uniVlanFlowParamsSlice[flow+1:]...) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 753 | //here we have to check, if there are still other flows referencing to the actual ProfileId |
| 754 | // before we can request that this profile gets deleted before a new flow add is allowed |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 755 | // (needed to extract to function due to lint complexity) |
mpagenko | 535d6ef | 2021-02-26 13:15:34 +0000 | [diff] [blame] | 756 | if !cancelPendingConfig { |
| 757 | oFsm.updateTechProfileToDelete(ctx, usedTpID) |
| 758 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 759 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - specific flow removed from data", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 760 | "device-id": oFsm.deviceID}) |
| 761 | } |
| 762 | //trigger the FSM to remove the relevant rule |
mpagenko | 535d6ef | 2021-02-26 13:15:34 +0000 | [diff] [blame] | 763 | if cancelPendingConfig { |
| 764 | oFsm.requestEventOffset = uint8(cDeviceEventOffsetRemoveWithKvStore) //offset for last flow-remove activity (with kvStore request) |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 765 | //attention: take care to release and re-take the mutexFlowParams when calling the FSM directly - |
| 766 | // synchronous FSM 'event/state' functions may rely on this mutex |
| 767 | oFsm.mutexFlowParams.Unlock() |
| 768 | if fsmErr := pConfigVlanStateBaseFsm.Event(vlanEvCancelOutstandingConfig); fsmErr != nil { |
| 769 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!", |
| 770 | log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
| 771 | } |
| 772 | oFsm.mutexFlowParams.Lock() |
mpagenko | 535d6ef | 2021-02-26 13:15:34 +0000 | [diff] [blame] | 773 | } else { |
| 774 | if pConfigVlanStateBaseFsm.Is(vlanStConfigDone) { |
| 775 | logger.Debugw(ctx, "UniVlanConfigFsm rule removal request", log.Fields{ |
| 776 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, |
| 777 | "tp-id": loRemoveParams.vlanRuleParams.TpID, |
| 778 | "set-Vlan": loRemoveParams.vlanRuleParams.SetVid}) |
| 779 | //have to re-trigger the FSM to proceed with outstanding incremental flow configuration |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 780 | //attention: take care to release and re-take the mutexFlowParams when calling the FSM directly - |
| 781 | // synchronous FSM 'event/state' functions may rely on this mutex |
| 782 | oFsm.mutexFlowParams.Unlock() |
| 783 | if fsmErr := pConfigVlanStateBaseFsm.Event(vlanEvRemFlowConfig); fsmErr != nil { |
| 784 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!", |
| 785 | log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
| 786 | } |
| 787 | oFsm.mutexFlowParams.Lock() |
mpagenko | 535d6ef | 2021-02-26 13:15:34 +0000 | [diff] [blame] | 788 | } // if not in the appropriate state a new entry will be automatically considered later |
| 789 | // when the configDone state is reached |
| 790 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 791 | } else { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 792 | //cut off the requested cookie by slicing out this element |
| 793 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append( |
| 794 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[:i], |
| 795 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[i+1:]...) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 796 | // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 797 | kvStoreWrite = true // ensure actual data write to kvStore immediately (no FSM activity) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 798 | // state transition notification is checked in deviceHandler |
| 799 | if oFsm.pDeviceHandler != nil { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 800 | // success indication without the need to write to kvStore (done already below with updated data from storePersUniFlowConfig()) |
| 801 | go oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetRemoveNoKvStore)) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 802 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 803 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - rule persists with still valid cookies", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 804 | "device-id": oFsm.deviceID, "cookies": oFsm.uniVlanFlowParamsSlice[flow].CookieSlice}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 805 | if deletedCookie == oFsm.delayNewRuleCookie { |
| 806 | //the delayedNewCookie is the one that is currently deleted, but the rule still exist with other cookies |
| 807 | //as long as there are further cookies for this rule indicate there is still some cookie to be deleted |
| 808 | //simply use the first one |
| 809 | oFsm.delayNewRuleCookie = oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[0] |
| 810 | logger.Debugw(ctx, "UniVlanConfigFsm remaining cookie awaited for deletion before new rule add", log.Fields{ |
| 811 | "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie}) |
| 812 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 813 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 814 | //permanently store the modified flow config for reconcile case |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 815 | if oFsm.pDeviceHandler != nil { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 816 | if err := oFsm.pDeviceHandler.storePersUniFlowConfig(ctx, oFsm.pOnuUniPort.uniID, |
| 817 | &oFsm.uniVlanFlowParamsSlice, kvStoreWrite); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 818 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 819 | return err |
| 820 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 821 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 822 | break remove_loop //found the cookie - no further search for this requested cookie |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 823 | } |
| 824 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 825 | } //search all flows |
| 826 | if !flowCookieMatch { //some cookie remove-request for a cookie that does not exist in the FSM data |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 827 | logger.Warnw(ctx, "UniVlanConfigFsm flow removal - remove-cookie not found", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 828 | "device-id": oFsm.deviceID, "remove-cookie": aCookie}) |
| 829 | // but accept the request with success as no such cookie (flow) does exist |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 830 | // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately |
| 831 | // state transition notification is checked in deviceHandler |
| 832 | if oFsm.pDeviceHandler != nil { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 833 | // success indication without the need to write to kvStore (no change) |
| 834 | go oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetRemoveNoKvStore)) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 835 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 836 | return nil |
| 837 | } //unknown cookie |
| 838 | |
| 839 | return nil |
| 840 | } |
| 841 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 842 | func (oFsm *UniVlanConfigFsm) updateTechProfileToDelete(ctx context.Context, usedTpID uint8) { |
| 843 | //here we have to check, if there are still other flows referencing to the actual ProfileId |
| 844 | // before we can request that this profile gets deleted before a new flow add is allowed |
| 845 | tpIDInOtherFlows := false |
| 846 | for _, tpUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
| 847 | if tpUniFlowParams.VlanRuleParams.TpID == usedTpID { |
| 848 | tpIDInOtherFlows = true |
| 849 | break // search loop can be left |
| 850 | } |
| 851 | } |
| 852 | if tpIDInOtherFlows { |
| 853 | logger.Debugw(ctx, "UniVlanConfigFsm tp-id used in deleted flow is still used in other flows", log.Fields{ |
| 854 | "device-id": oFsm.deviceID, "tp-id": usedTpID}) |
| 855 | } else { |
| 856 | logger.Debugw(ctx, "UniVlanConfigFsm tp-id used in deleted flow is not used anymore", log.Fields{ |
| 857 | "device-id": oFsm.deviceID, "tp-id": usedTpID}) |
| 858 | //request that this profile gets deleted before a new flow add is allowed |
| 859 | oFsm.pUniTechProf.setProfileToDelete(oFsm.pOnuUniPort.uniID, usedTpID, true) |
| 860 | } |
| 861 | } |
| 862 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 863 | func (oFsm *UniVlanConfigFsm) enterConfigStarting(ctx context.Context, e *fsm.Event) { |
| 864 | logger.Debugw(ctx, "UniVlanConfigFsm start", log.Fields{"in state": e.FSM.Current(), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 865 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 866 | |
| 867 | // this FSM is not intended for re-start, needs always new creation for a new run |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 868 | // (self-destroying - compare enterDisabled()) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 869 | oFsm.omciMIdsResponseReceived = make(chan bool) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 870 | oFsm.chCookieDeleted = make(chan bool) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 871 | // start go routine for processing of LockState messages |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 872 | go oFsm.processOmciVlanMessages(ctx) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 873 | //let the state machine run forward from here directly |
| 874 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 875 | if pConfigVlanStateAFsm != nil { |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 876 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 877 | if oFsm.pDeviceHandler.isSkipOnuConfigReconciling() { |
| 878 | logger.Debugw(ctx, "reconciling - skip omci-config of vlan rule", |
| 879 | log.Fields{"fsmState": oFsm.pAdaptFsm.pFsm.Current(), "device-id": oFsm.deviceID}) |
| 880 | go func(a_pAFsm *AdapterFsm) { |
| 881 | _ = a_pAFsm.pFsm.Event(vlanEvSkipOmciConfig) |
| 882 | }(pConfigVlanStateAFsm) |
| 883 | return |
| 884 | } |
| 885 | oFsm.mutexFlowParams.Lock() |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 886 | //possibly the entry is not valid anymore based on intermediate delete requests |
| 887 | //just a basic protection ... |
| 888 | if len(oFsm.uniVlanFlowParamsSlice) == 0 { |
| 889 | oFsm.mutexFlowParams.Unlock() |
| 890 | logger.Debugw(ctx, "UniVlanConfigFsm start: no rule entry anymore available", log.Fields{ |
| 891 | "device-id": oFsm.deviceID}) |
| 892 | // Can't call FSM Event directly, decoupling it |
| 893 | go func(a_pAFsm *AdapterFsm) { |
| 894 | _ = a_pAFsm.pFsm.Event(vlanEvReset) |
| 895 | }(pConfigVlanStateAFsm) |
| 896 | return |
| 897 | } |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 898 | //access to uniVlanFlowParamsSlice is done on first element only here per definition |
| 899 | //store the actual rule that shall be worked upon in the following transient states |
| 900 | oFsm.actualUniVlanConfigRule = oFsm.uniVlanFlowParamsSlice[0].VlanRuleParams |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 901 | tpID := oFsm.actualUniVlanConfigRule.TpID |
| 902 | oFsm.TpIDWaitingFor = tpID |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 903 | loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.uniID, uint8(tpID)) |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 904 | logger.Debugw(ctx, "UniVlanConfigFsm - start with first rule", log.Fields{ |
| 905 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, |
| 906 | "set-Vlan": oFsm.actualUniVlanConfigRule.SetVid, "tp-id": tpID, "ProfDone": loTechProfDone}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 907 | //cmp also usage in EVTOCDE create in omci_cc |
| 908 | oFsm.evtocdID = macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo) |
mpagenko | 535d6ef | 2021-02-26 13:15:34 +0000 | [diff] [blame] | 909 | oFsm.mutexFlowParams.Unlock() |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 910 | // Can't call FSM Event directly, decoupling it |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 911 | go func(aPAFsm *AdapterFsm, aTechProfDone bool) { |
| 912 | if aPAFsm != nil && aPAFsm.pFsm != nil { |
| 913 | if aTechProfDone { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 914 | // let the vlan processing begin |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 915 | _ = aPAFsm.pFsm.Event(vlanEvStartConfig) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 916 | } else { |
| 917 | // set to waiting for Techprofile |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 918 | _ = aPAFsm.pFsm.Event(vlanEvWaitTechProf) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 919 | } |
| 920 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 921 | }(pConfigVlanStateAFsm, loTechProfDone) |
| 922 | } else { |
| 923 | logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{ |
| 924 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 925 | //should never happen, else: recovery would be needed from outside the FSM |
| 926 | return |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 930 | func (oFsm *UniVlanConfigFsm) enterConfigVtfd(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 931 | //mutex protection is required for possible concurrent access to FSM members |
| 932 | oFsm.mutexFlowParams.Lock() |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 933 | oFsm.TpIDWaitingFor = 0 //reset indication to avoid misinterpretation |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 934 | if oFsm.actualUniVlanConfigRule.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 935 | // meaning transparent setup - no specific VTFD setting required |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 936 | oFsm.mutexFlowParams.Unlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 937 | logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD config required", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 938 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 939 | // let the FSM proceed ... (from within this state all internal pointers may be expected to be correct) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 940 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 941 | // Can't call FSM Event directly, decoupling it |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 942 | go func(a_pAFsm *AdapterFsm) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 943 | _ = a_pAFsm.pFsm.Event(vlanEvRxConfigVtfd) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 944 | }(pConfigVlanStateAFsm) |
| 945 | } else { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 946 | // This attribute uniquely identifies each instance of this managed entity. Through an identical ID, |
| 947 | // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME. |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 948 | vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + uint16(oFsm.actualUniVlanConfigRule.TpID) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 949 | logger.Debugw(ctx, "UniVlanConfigFsm create VTFD", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 950 | "EntitytId": strconv.FormatInt(int64(vtfdID), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 951 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 952 | // setVid is assumed to be masked already by the caller to 12 bit |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 953 | oFsm.vlanFilterList[0] = uint16(oFsm.actualUniVlanConfigRule.SetVid) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 954 | oFsm.mutexFlowParams.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 955 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 956 | vtfdFilterList[0] = oFsm.vlanFilterList[0] |
| 957 | oFsm.numVlanFilterEntries = 1 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 958 | meParams := me.ParamData{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 959 | EntityID: vtfdID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 960 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 961 | "VlanFilterList": vtfdFilterList, //omci lib wants a slice for serialization |
| 962 | "ForwardOperation": uint8(0x10), //VID investigation |
| 963 | "NumberOfEntries": oFsm.numVlanFilterEntries, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 964 | }, |
| 965 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 966 | logger.Debugw(ctx, "UniVlanConfigFsm sendcreate VTFD", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 967 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 968 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 969 | meInstance, err := oFsm.pOmciCC.sendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 970 | oFsm.pAdaptFsm.commChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 971 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 972 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 973 | logger.Errorw(ctx, "VTFD create failed, aborting UniVlanConfig FSM!", |
| 974 | log.Fields{"device-id": oFsm.deviceID}) |
| 975 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 976 | if pConfigVlanStateAFsm != nil { |
| 977 | go func(a_pAFsm *AdapterFsm) { |
| 978 | _ = a_pAFsm.pFsm.Event(vlanEvReset) |
| 979 | }(pConfigVlanStateAFsm) |
| 980 | } |
| 981 | return |
| 982 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 983 | //accept also nil as (error) return value for writing to LastTx |
| 984 | // - this avoids misinterpretation of new received OMCI messages |
| 985 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 986 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 987 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 988 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 989 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 993 | func (oFsm *UniVlanConfigFsm) enterConfigEvtocd(ctx context.Context, e *fsm.Event) { |
| 994 | logger.Debugw(ctx, "UniVlanConfigFsm - start config EVTOCD loop", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 995 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 996 | oFsm.requestEventOffset = uint8(cDeviceEventOffsetAddWithKvStore) //0 offset for last flow-add activity |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 997 | go func() { |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 998 | //using the first element in the slice because it's the first flow per definition here |
| 999 | errEvto := oFsm.performConfigEvtocdEntries(ctx, 0) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1000 | //This is correct passing scenario |
| 1001 | if errEvto == nil { |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1002 | tpID := oFsm.actualUniVlanConfigRule.TpID |
| 1003 | vlanID := oFsm.actualUniVlanConfigRule.SetVid |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1004 | for _, gemPort := range oFsm.pUniTechProf.getMulticastGemPorts(ctx, oFsm.pOnuUniPort.uniID, uint8(tpID)) { |
| 1005 | logger.Infow(ctx, "Setting multicast MEs, with first flow", log.Fields{"deviceID": oFsm.deviceID, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1006 | "techProfile": tpID, "gemPort": gemPort, "vlanID": vlanID, "configuredUniFlow": oFsm.configuredUniFlow}) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1007 | errCreateAllMulticastME := oFsm.performSettingMulticastME(ctx, tpID, gemPort, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1008 | vlanID) |
| 1009 | if errCreateAllMulticastME != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1010 | logger.Errorw(ctx, "Multicast ME create failed, aborting AniConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1011 | log.Fields{"device-id": oFsm.deviceID}) |
| 1012 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1013 | } |
| 1014 | } |
| 1015 | //TODO Possibly insert new state for multicast --> possibly another jira/later time. |
| 1016 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigEvtocd) |
| 1017 | } |
| 1018 | }() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1021 | func (oFsm *UniVlanConfigFsm) enterVlanConfigDone(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1022 | |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1023 | oFsm.mutexFlowParams.RLock() |
| 1024 | defer oFsm.mutexFlowParams.RUnlock() |
| 1025 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1026 | logger.Infow(ctx, "UniVlanConfigFsm config done - checking on more flows", log.Fields{ |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1027 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID, |
| 1028 | "overall-uni-rules": oFsm.numUniFlows, "configured-uni-rules": oFsm.configuredUniFlow}) |
| 1029 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 1030 | if pConfigVlanStateAFsm == nil { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1031 | logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{ |
| 1032 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 1033 | //should never happen, else: recovery would be needed from outside the FSM |
| 1034 | return |
| 1035 | } |
| 1036 | pConfigVlanStateBaseFsm := pConfigVlanStateAFsm.pFsm |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1037 | if len(oFsm.uniRemoveFlowsSlice) > 0 { |
| 1038 | //some further flows are to be removed, removal always starts with the first element |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1039 | logger.Debugw(ctx, "UniVlanConfigFsm rule removal from ConfigDone", log.Fields{ |
| 1040 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, |
| 1041 | "tp-id": oFsm.uniRemoveFlowsSlice[0].vlanRuleParams.TpID, |
| 1042 | "set-Vlan": oFsm.uniRemoveFlowsSlice[0].vlanRuleParams.SetVid}) |
| 1043 | // Can't call FSM Event directly, decoupling it |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1044 | go func(a_pBaseFsm *fsm.FSM) { |
| 1045 | _ = a_pBaseFsm.Event(vlanEvRemFlowConfig) |
| 1046 | }(pConfigVlanStateBaseFsm) |
| 1047 | return |
| 1048 | } |
Holger Hildebrandt | 1b8f4ad | 2021-03-25 15:53:51 +0000 | [diff] [blame] | 1049 | if oFsm.pDeviceHandler.isSkipOnuConfigReconciling() { |
| 1050 | oFsm.configuredUniFlow = oFsm.numUniFlows |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 1051 | if !oFsm.pDeviceHandler.isReconcilingFlows() { |
| 1052 | logger.Debugw(ctx, "reconciling - flow processing finished", log.Fields{"device-id": oFsm.deviceID}) |
| 1053 | oFsm.pDeviceHandler.chReconcilingFlowsFinished <- true |
| 1054 | } |
Holger Hildebrandt | 1b8f4ad | 2021-03-25 15:53:51 +0000 | [diff] [blame] | 1055 | logger.Debugw(ctx, "reconciling - skip enterVlanConfigDone processing", |
| 1056 | log.Fields{"numUniFlows": oFsm.numUniFlows, "configuredUniFlow": oFsm.configuredUniFlow, "device-id": oFsm.deviceID}) |
| 1057 | return |
| 1058 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1059 | if oFsm.numUniFlows > oFsm.configuredUniFlow { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1060 | if oFsm.configuredUniFlow == 0 { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1061 | // this is a restart with a complete new flow, we can re-use the initial flow config control |
| 1062 | // including the check, if the related techProfile is (still) available (probably also removed in between) |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1063 | // Can't call FSM Event directly, decoupling it |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1064 | go func(a_pBaseFsm *fsm.FSM) { |
| 1065 | _ = a_pBaseFsm.Event(vlanEvRenew) |
| 1066 | }(pConfigVlanStateBaseFsm) |
| 1067 | return |
| 1068 | } |
| 1069 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1070 | //some further flows are to be configured |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1071 | //store the actual rule that shall be worked upon in the following transient states |
| 1072 | oFsm.actualUniVlanConfigRule = oFsm.uniVlanFlowParamsSlice[oFsm.configuredUniFlow].VlanRuleParams |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1073 | //tpId of the next rule to be configured |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1074 | tpID := oFsm.actualUniVlanConfigRule.TpID |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1075 | oFsm.TpIDWaitingFor = tpID |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1076 | loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.uniID, tpID) |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1077 | logger.Debugw(ctx, "UniVlanConfigFsm - incremental config request", log.Fields{ |
| 1078 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, |
| 1079 | "set-Vlan": oFsm.actualUniVlanConfigRule.SetVid, "tp-id": tpID, "ProfDone": loTechProfDone}) |
| 1080 | // Can't call FSM Event directly, decoupling it |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1081 | go func(aPBaseFsm *fsm.FSM, aTechProfDone bool) { |
| 1082 | if aTechProfDone { |
| 1083 | // let the vlan processing continue with next rule |
| 1084 | _ = aPBaseFsm.Event(vlanEvIncrFlowConfig) |
| 1085 | } else { |
| 1086 | // set to waiting for Techprofile |
| 1087 | _ = aPBaseFsm.Event(vlanEvWaitTPIncr) |
| 1088 | } |
| 1089 | }(pConfigVlanStateBaseFsm, loTechProfDone) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1090 | return |
| 1091 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1092 | logger.Debugw(ctx, "UniVlanConfigFsm - VLAN config done: send dh event notification", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1093 | "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1094 | // it might appear that some flows are requested also after 'flowPushed' event has been generated ... |
| 1095 | // state transition notification is checked in deviceHandler |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1096 | // note: 'flowPushed' event is only generated if all 'pending' rules are configured |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1097 | if oFsm.pDeviceHandler != nil { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1098 | //making use of the add->remove successor enum assumption/definition |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1099 | go oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent(uint8(oFsm.requestEvent)+oFsm.requestEventOffset)) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1100 | } |
| 1101 | } |
| 1102 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1103 | func (oFsm *UniVlanConfigFsm) enterConfigIncrFlow(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1104 | |
| 1105 | if oFsm.pDeviceHandler.isSkipOnuConfigReconciling() { |
| 1106 | logger.Debugw(ctx, "reconciling - skip further processing for incremental flow", |
| 1107 | log.Fields{"fsmState": oFsm.pAdaptFsm.pFsm.Current(), "device-id": oFsm.deviceID}) |
| 1108 | go func(a_pBaseFsm *fsm.FSM) { |
| 1109 | _ = a_pBaseFsm.Event(vlanEvSkipIncFlowConfig) |
| 1110 | }(oFsm.pAdaptFsm.pFsm) |
| 1111 | return |
| 1112 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1113 | oFsm.mutexFlowParams.Lock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1114 | logger.Debugw(ctx, "UniVlanConfigFsm - start config further incremental flow", log.Fields{ |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 1115 | "in state": e.FSM.Current(), "recent flow-number": oFsm.configuredUniFlow, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1116 | "device-id": oFsm.deviceID}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1117 | oFsm.TpIDWaitingFor = 0 //reset indication to avoid misinterpretation |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1118 | |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1119 | if oFsm.actualUniVlanConfigRule.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1120 | // meaning transparent setup - no specific VTFD setting required |
| 1121 | oFsm.mutexFlowParams.Unlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1122 | logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD config required", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1123 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1124 | } else { |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 1125 | //TODO!!!: it was not really intended to keep this enter* FSM method waiting on OMCI response (preventing other state transitions) |
| 1126 | // so it would be conceptually better to wait for the response in background like for the other multi-entity processing |
| 1127 | // but as the OMCI sequence must be ensured, a separate new state would be required - perhaps later |
| 1128 | // in practice should have no influence by now as no other state transition is currently accepted (while cancel() is ensured) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1129 | if oFsm.numVlanFilterEntries == 0 { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1130 | // This attribute uniquely identifies each instance of this managed entity. Through an identical ID, |
| 1131 | // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME. |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1132 | vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + uint16(oFsm.actualUniVlanConfigRule.TpID) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1133 | //no VTFD yet created |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1134 | logger.Debugw(ctx, "UniVlanConfigFsm create VTFD", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1135 | "EntitytId": strconv.FormatInt(int64(vtfdID), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1136 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1137 | // 'SetVid' below is assumed to be masked already by the caller to 12 bit |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1138 | oFsm.vlanFilterList[0] = uint16(oFsm.actualUniVlanConfigRule.SetVid) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1139 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1140 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1141 | vtfdFilterList[0] = oFsm.vlanFilterList[0] |
| 1142 | oFsm.numVlanFilterEntries = 1 |
| 1143 | meParams := me.ParamData{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1144 | EntityID: vtfdID, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1145 | Attributes: me.AttributeValueMap{ |
| 1146 | "VlanFilterList": vtfdFilterList, |
| 1147 | "ForwardOperation": uint8(0x10), //VID investigation |
| 1148 | "NumberOfEntries": oFsm.numVlanFilterEntries, |
| 1149 | }, |
| 1150 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1151 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1152 | meInstance, err := oFsm.pOmciCC.sendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1153 | oFsm.pAdaptFsm.commChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1154 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1155 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1156 | logger.Errorw(ctx, "VTFD create failed, aborting UniVlanConfig FSM!", |
| 1157 | log.Fields{"device-id": oFsm.deviceID}) |
| 1158 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 1159 | if pConfigVlanStateAFsm != nil { |
| 1160 | go func(a_pAFsm *AdapterFsm) { |
| 1161 | _ = a_pAFsm.pFsm.Event(vlanEvReset) |
| 1162 | }(pConfigVlanStateAFsm) |
| 1163 | } |
| 1164 | return |
| 1165 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1166 | //accept also nil as (error) return value for writing to LastTx |
| 1167 | // - this avoids misinterpretation of new received OMCI messages |
| 1168 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 1169 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 1170 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1171 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1172 | oFsm.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1173 | } else { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1174 | // This attribute uniquely identifies each instance of this managed entity. Through an identical ID, |
| 1175 | // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME. |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1176 | vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1177 | uint16(oFsm.actualUniVlanConfigRule.TpID) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1178 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1179 | logger.Debugw(ctx, "UniVlanConfigFsm set VTFD", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1180 | "EntitytId": strconv.FormatInt(int64(vtfdID), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1181 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1182 | // setVid is assumed to be masked already by the caller to 12 bit |
| 1183 | oFsm.vlanFilterList[oFsm.numVlanFilterEntries] = |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1184 | uint16(oFsm.actualUniVlanConfigRule.SetVid) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1185 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1186 | |
| 1187 | // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME |
| 1188 | // VTFD has to be created afresh with a new entity ID that has the same entity ID as the MBPCD ME for every |
| 1189 | // new vlan associated with a different TP. |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1190 | vtfdFilterList[0] = uint16(oFsm.actualUniVlanConfigRule.SetVid) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1191 | |
| 1192 | oFsm.numVlanFilterEntries++ |
| 1193 | meParams := me.ParamData{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1194 | EntityID: vtfdID, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1195 | Attributes: me.AttributeValueMap{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1196 | "VlanFilterList": vtfdFilterList, |
| 1197 | "ForwardOperation": uint8(0x10), //VID investigation |
| 1198 | "NumberOfEntries": oFsm.numVlanFilterEntries, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1199 | }, |
| 1200 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1201 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1202 | meInstance, err := oFsm.pOmciCC.sendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1203 | oFsm.pAdaptFsm.commChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1204 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1205 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1206 | logger.Errorw(ctx, "UniVlanFsm create Vlan Tagging Filter ME result error", |
| 1207 | log.Fields{"device-id": oFsm.deviceID, "Error": err}) |
| 1208 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1209 | return |
| 1210 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1211 | //accept also nil as (error) return value for writing to LastTx |
| 1212 | // - this avoids misinterpretation of new received OMCI messages |
| 1213 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 1214 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 1215 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1216 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1217 | oFsm.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1218 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1219 | oFsm.mutexFlowParams.Unlock() |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1220 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1221 | err := oFsm.waitforOmciResponse(ctx) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1222 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1223 | logger.Errorw(ctx, "VTFD create/set failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1224 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1225 | pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1226 | // Can't call FSM Event directly, decoupling it |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1227 | go func(a_pBaseFsm *fsm.FSM) { |
| 1228 | _ = a_pBaseFsm.Event(vlanEvReset) |
| 1229 | }(pConfigVlanStateBaseFsm) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1230 | return |
| 1231 | } |
| 1232 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1233 | oFsm.mutexFlowParams.Lock() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1234 | oFsm.requestEventOffset = uint8(cDeviceEventOffsetAddWithKvStore) //0 offset for last flow-add activity |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1235 | oFsm.mutexFlowParams.Unlock() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1236 | go func() { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1237 | oFsm.mutexFlowParams.RLock() |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1238 | tpID := oFsm.actualUniVlanConfigRule.TpID |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1239 | configuredUniFlow := oFsm.configuredUniFlow |
| 1240 | oFsm.mutexFlowParams.RUnlock() |
| 1241 | errEvto := oFsm.performConfigEvtocdEntries(ctx, configuredUniFlow) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1242 | //This is correct passing scenario |
| 1243 | if errEvto == nil { |
| 1244 | //TODO Possibly insert new state for multicast --> possibly another jira/later time. |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1245 | for _, gemPort := range oFsm.pUniTechProf.getMulticastGemPorts(ctx, oFsm.pOnuUniPort.uniID, uint8(tpID)) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1246 | oFsm.mutexFlowParams.RLock() |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1247 | vlanID := oFsm.actualUniVlanConfigRule.SetVid |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1248 | logger.Infow(ctx, "Setting multicast MEs for additional flows", log.Fields{"deviceID": oFsm.deviceID, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1249 | "techProfile": tpID, "gemPort": gemPort, |
| 1250 | "vlanID": vlanID, "configuredUniFlow": oFsm.configuredUniFlow}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1251 | oFsm.mutexFlowParams.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1252 | errCreateAllMulticastME := oFsm.performSettingMulticastME(ctx, tpID, gemPort, vlanID) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1253 | if errCreateAllMulticastME != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1254 | logger.Errorw(ctx, "Multicast ME create failed, aborting AniConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1255 | log.Fields{"device-id": oFsm.deviceID}) |
| 1256 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1257 | } |
| 1258 | } |
| 1259 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigEvtocd) |
| 1260 | } |
| 1261 | }() |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1264 | func (oFsm *UniVlanConfigFsm) enterRemoveFlow(ctx context.Context, e *fsm.Event) { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1265 | oFsm.mutexFlowParams.RLock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1266 | logger.Debugw(ctx, "UniVlanConfigFsm - start removing the top remove-flow", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1267 | "in state": e.FSM.Current(), "with last cookie": oFsm.uniRemoveFlowsSlice[0].cookie, |
| 1268 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1269 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1270 | pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1271 | loAllowSpecificOmciConfig := oFsm.pDeviceHandler.isReadyForOmciConfig() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1272 | loVlanEntryClear := uint8(0) |
| 1273 | loVlanEntryRmPos := uint8(0x80) //with indication 'invalid' in bit 7 |
| 1274 | //shallow copy is sufficient as no reference variables are used within struct |
| 1275 | loRuleParams := oFsm.uniRemoveFlowsSlice[0].vlanRuleParams |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1276 | oFsm.mutexFlowParams.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1277 | logger.Debugw(ctx, "UniVlanConfigFsm - remove-flow parameters are", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1278 | "match vid": loRuleParams.MatchVid, "match Pcp": loRuleParams.MatchPcp, |
| 1279 | "set vid": strconv.FormatInt(int64(loRuleParams.SetVid), 16), |
| 1280 | "device-id": oFsm.deviceID}) |
| 1281 | |
| 1282 | if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 1283 | // meaning transparent setup - no specific VTFD setting required |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1284 | logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD removal required for transparent flow", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1285 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 1286 | } else { |
| 1287 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization and 're-copy' |
| 1288 | if oFsm.numVlanFilterEntries == 1 { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1289 | vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + uint16(loRuleParams.TpID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1290 | //only one active VLAN entry (hopefully the SetVID we want to remove - should be, but not verified ..) |
| 1291 | // so we can just delete the VTFD entry |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1292 | logger.Debugw(ctx, "UniVlanConfigFsm: VTFD delete (no more vlan filters)", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1293 | log.Fields{"current vlan list": oFsm.vlanFilterList, |
| 1294 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1295 | loVlanEntryClear = 1 //full VlanFilter clear request |
| 1296 | if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1297 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1298 | meInstance, err := oFsm.pOmciCC.sendDeleteVtfd(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1299 | oFsm.pAdaptFsm.commChan, vtfdID) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1300 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1301 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1302 | logger.Errorw(ctx, "UniVlanFsm delete Vlan Tagging Filter ME result error", |
| 1303 | log.Fields{"device-id": oFsm.deviceID, "Error": err}) |
| 1304 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1305 | return |
| 1306 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1307 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1308 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1309 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1310 | logger.Debugw(ctx, "UniVlanConfigFsm delete VTFD OMCI handling skipped based on device state", log.Fields{ |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1311 | "device-id": oFsm.deviceID, "device-state": oFsm.pDeviceHandler.getDeviceReasonString()}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1312 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1313 | } else { |
| 1314 | //many VTFD already should exists - find and remove the one concerned by the actual remove rule |
| 1315 | // by updating the VTFD per set command with new valid list |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1316 | logger.Debugw(ctx, "UniVlanConfigFsm: VTFD removal of requested VLAN from the list on OMCI", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1317 | log.Fields{"current vlan list": oFsm.vlanFilterList, |
| 1318 | "set-vlan": loRuleParams.SetVid, "device-id": oFsm.deviceID}) |
| 1319 | for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ { |
| 1320 | if loRuleParams.SetVid == uint32(oFsm.vlanFilterList[i]) { |
| 1321 | loVlanEntryRmPos = i |
| 1322 | break //abort search |
| 1323 | } |
| 1324 | } |
| 1325 | if loVlanEntryRmPos < cVtfdTableSize { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1326 | vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + uint16(loRuleParams.TpID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1327 | //valid entry was found - to be eclipsed |
| 1328 | loVlanEntryClear = 2 //VlanFilter remove request for a specific entry |
| 1329 | for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ { |
| 1330 | if i < loVlanEntryRmPos { |
| 1331 | vtfdFilterList[i] = oFsm.vlanFilterList[i] //copy original |
| 1332 | } else if i < (cVtfdTableSize - 1) { |
| 1333 | vtfdFilterList[i] = oFsm.vlanFilterList[i+1] //copy successor (including 0 elements) |
| 1334 | } else { |
| 1335 | vtfdFilterList[i] = 0 //set last byte if needed |
| 1336 | } |
| 1337 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1338 | logger.Debugw(ctx, "UniVlanConfigFsm set VTFD", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1339 | "EntitytId": strconv.FormatInt(int64(vtfdID), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1340 | "new vlan list": vtfdFilterList, "device-id": oFsm.deviceID}) |
| 1341 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1342 | if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1343 | // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1344 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1345 | meInstance, err := oFsm.pOmciCC.sendDeleteVtfd(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1346 | oFsm.pAdaptFsm.commChan, vtfdID) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1347 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1348 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1349 | logger.Errorw(ctx, "UniVlanFsm delete Vlan Tagging Filter ME result error", |
| 1350 | log.Fields{"device-id": oFsm.deviceID, "Error": err}) |
| 1351 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1352 | return |
| 1353 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1354 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1355 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1356 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1357 | logger.Debugw(ctx, "UniVlanConfigFsm set VTFD OMCI handling skipped based on device state", log.Fields{ |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1358 | "device-id": oFsm.deviceID, "device-state": oFsm.pDeviceHandler.getDeviceReasonString()}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1359 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1360 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1361 | logger.Warnw(ctx, "UniVlanConfigFsm: requested VLAN for removal not found in list - ignore and continue (no VTFD set)", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1362 | log.Fields{"device-id": oFsm.deviceID}) |
| 1363 | } |
| 1364 | } |
| 1365 | if loVlanEntryClear > 0 { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1366 | if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state |
| 1367 | //waiting on response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1368 | err := oFsm.waitforOmciResponse(ctx) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1369 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1370 | logger.Errorw(ctx, "VTFD delete/reset failed, aborting VlanConfig FSM!", |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1371 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1372 | // Can't call FSM Event directly, decoupling it |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1373 | go func(a_pBaseFsm *fsm.FSM) { |
| 1374 | _ = a_pBaseFsm.Event(vlanEvReset) |
| 1375 | }(pConfigVlanStateBaseFsm) |
| 1376 | return |
| 1377 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1380 | oFsm.mutexFlowParams.Lock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1381 | if loVlanEntryClear == 1 { |
| 1382 | oFsm.vlanFilterList[0] = 0 //first entry is the only that can contain the previous only-one element |
| 1383 | oFsm.numVlanFilterEntries = 0 |
| 1384 | } else if loVlanEntryClear == 2 { |
| 1385 | // new VlanFilterList should be one entry smaller now - copy from last configured entry |
| 1386 | // this loop now includes the 0 element on previous last valid entry |
| 1387 | for i := uint8(0); i <= oFsm.numVlanFilterEntries; i++ { |
| 1388 | oFsm.vlanFilterList[i] = vtfdFilterList[i] |
| 1389 | } |
| 1390 | oFsm.numVlanFilterEntries-- |
| 1391 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1392 | oFsm.mutexFlowParams.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1393 | } |
| 1394 | } |
| 1395 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1396 | if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1397 | go oFsm.removeEvtocdEntries(ctx, loRuleParams) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1398 | } else { |
| 1399 | // OMCI processing is not done, expectation is to have the ONU in some basic config state accordingly |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1400 | logger.Debugw(ctx, "UniVlanConfigFsm remove EVTOCD OMCI handling skipped based on device state", log.Fields{ |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1401 | "device-id": oFsm.deviceID}) |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1402 | // Can't call FSM Event directly, decoupling it |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1403 | go func(a_pBaseFsm *fsm.FSM) { |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 1404 | _ = a_pBaseFsm.Event(vlanEvRemFlowDone, loRuleParams.TpID) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1405 | }(pConfigVlanStateBaseFsm) |
| 1406 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1409 | func (oFsm *UniVlanConfigFsm) enterVlanCleanupDone(ctx context.Context, e *fsm.Event) { |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 1410 | var tpID uint8 |
| 1411 | // Extract the tpID |
| 1412 | if len(e.Args) > 0 { |
| 1413 | tpID = e.Args[0].(uint8) |
| 1414 | logger.Debugw(ctx, "UniVlanConfigFsm - flow removed for tp id", log.Fields{"device-id": oFsm.deviceID, "tpID": e.Args[0].(uint8)}) |
| 1415 | } else { |
| 1416 | logger.Warnw(ctx, "UniVlanConfigFsm - tp id not available", log.Fields{"device-id": oFsm.deviceID}) |
| 1417 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1418 | oFsm.mutexFlowParams.Lock() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1419 | deletedCookie := oFsm.uniRemoveFlowsSlice[0].cookie |
| 1420 | logger.Debugw(ctx, "UniVlanConfigFsm - removing the removal data", log.Fields{ |
| 1421 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID, |
| 1422 | "removed cookie": deletedCookie, "waitForDeleteCookie": oFsm.delayNewRuleCookie}) |
| 1423 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1424 | if len(oFsm.uniRemoveFlowsSlice) <= 1 { |
| 1425 | oFsm.uniRemoveFlowsSlice = nil //reset the slice |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1426 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - last remove-flow deleted", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1427 | "device-id": oFsm.deviceID}) |
| 1428 | } else { |
| 1429 | //cut off the actual flow by slicing out the first element |
| 1430 | oFsm.uniRemoveFlowsSlice = append( |
| 1431 | oFsm.uniRemoveFlowsSlice[:0], |
| 1432 | oFsm.uniRemoveFlowsSlice[1:]...) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1433 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - specific flow deleted from data", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1434 | "device-id": oFsm.deviceID}) |
| 1435 | } |
| 1436 | oFsm.mutexFlowParams.Unlock() |
| 1437 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1438 | oFsm.requestEventOffset = uint8(cDeviceEventOffsetRemoveWithKvStore) //offset for last flow-remove activity (with kvStore request) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1439 | //return to the basic config verification state |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1440 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 1441 | if pConfigVlanStateAFsm != nil { |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1442 | // Can't call FSM Event directly, decoupling it |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1443 | go func(a_pAFsm *AdapterFsm) { |
| 1444 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1445 | _ = a_pAFsm.pFsm.Event(vlanEvFlowDataRemoved) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1446 | } |
| 1447 | }(pConfigVlanStateAFsm) |
| 1448 | } |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 1449 | |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 1450 | oFsm.mutexFlowParams.Lock() |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 1451 | noOfFlowRem := len(oFsm.uniRemoveFlowsSlice) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1452 | if deletedCookie == oFsm.delayNewRuleCookie { |
| 1453 | // flush the channel CookieDeleted to ensure it is not lingering from some previous (aborted) activity |
| 1454 | select { |
| 1455 | case <-oFsm.chCookieDeleted: |
| 1456 | logger.Debug(ctx, "flushed CookieDeleted") |
| 1457 | default: |
| 1458 | } |
| 1459 | oFsm.chCookieDeleted <- true // let the waiting AddFlow thread continue |
| 1460 | } |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 1461 | // If all pending flow-removes are completed and TP ID is valid go on processing any pending TP delete |
| 1462 | if oFsm.signalOnFlowDelete && noOfFlowRem == 0 && tpID > 0 { |
| 1463 | logger.Debugw(ctx, "signal flow removal for pending TP delete", log.Fields{"device-id": oFsm.deviceID, "tpID": tpID}) |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 1464 | // If we are here then all flows are removed. |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 1465 | if len(oFsm.flowDeleteChannel) == 0 { //channel not yet in use |
| 1466 | oFsm.flowDeleteChannel <- true |
| 1467 | oFsm.signalOnFlowDelete = false |
| 1468 | } |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 1469 | } |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 1470 | oFsm.mutexFlowParams.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1473 | func (oFsm *UniVlanConfigFsm) enterResetting(ctx context.Context, e *fsm.Event) { |
| 1474 | logger.Debugw(ctx, "UniVlanConfigFsm resetting", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1475 | |
| 1476 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 1477 | if pConfigVlanStateAFsm != nil { |
| 1478 | // abort running message processing |
| 1479 | fsmAbortMsg := Message{ |
| 1480 | Type: TestMsg, |
| 1481 | Data: TestMessage{ |
| 1482 | TestMessageVal: AbortMessageProcessing, |
| 1483 | }, |
| 1484 | } |
| 1485 | pConfigVlanStateAFsm.commChan <- fsmAbortMsg |
| 1486 | |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1487 | //try to restart the FSM to 'disabled' |
| 1488 | // Can't call FSM Event directly, decoupling it |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1489 | go func(a_pAFsm *AdapterFsm) { |
| 1490 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1491 | _ = a_pAFsm.pFsm.Event(vlanEvRestart) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1492 | } |
| 1493 | }(pConfigVlanStateAFsm) |
| 1494 | } |
| 1495 | } |
| 1496 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1497 | func (oFsm *UniVlanConfigFsm) enterDisabled(ctx context.Context, e *fsm.Event) { |
| 1498 | logger.Debugw(ctx, "UniVlanConfigFsm enters disabled state", log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1499 | oFsm.mutexPLastTxMeInstance.Lock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1500 | oFsm.pLastTxMeInstance = nil |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1501 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1502 | if oFsm.pDeviceHandler != nil { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1503 | //TODO: to clarify with improved error treatment for VlanConfigFsm (timeout,reception) errors |
| 1504 | // current code removes the complete FSM including all flow/rule configuration done so far |
| 1505 | // this might be a bit to much, it would require fully new flow config from rwCore (at least on OnuDown/up) |
| 1506 | // maybe a more sophisticated approach is possible without clearing the data |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1507 | oFsm.mutexFlowParams.RLock() |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1508 | if oFsm.clearPersistency { |
| 1509 | //permanently remove possibly stored persistent data |
| 1510 | if len(oFsm.uniVlanFlowParamsSlice) > 0 { |
| 1511 | var emptySlice = make([]uniVlanFlowParams, 0) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1512 | _ = oFsm.pDeviceHandler.storePersUniFlowConfig(ctx, oFsm.pOnuUniPort.uniID, &emptySlice, true) //ignore errors |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1513 | } |
| 1514 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1515 | logger.Debugw(ctx, "UniVlanConfigFsm persistency data not cleared", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1516 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1517 | if oFsm.delayNewRuleCookie != 0 { |
| 1518 | // looks like the waiting AddFlow is stuck |
| 1519 | oFsm.chCookieDeleted <- true // let the waiting AddFlow thread continue/treminate |
| 1520 | } |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1521 | oFsm.mutexFlowParams.RUnlock() |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1522 | //request removal of 'reference' in the Handler (completely clear the FSM and its data) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1523 | go oFsm.pDeviceHandler.RemoveVlanFilterFsm(ctx, oFsm.pOnuUniPort) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1524 | } |
| 1525 | } |
| 1526 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1527 | func (oFsm *UniVlanConfigFsm) processOmciVlanMessages(ctx context.Context) { //ctx context.Context? |
| 1528 | logger.Debugw(ctx, "Start UniVlanConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1529 | loop: |
| 1530 | for { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1531 | // case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1532 | // logger.Info(ctx,"MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1533 | // break loop |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1534 | message, ok := <-oFsm.pAdaptFsm.commChan |
| 1535 | if !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1536 | logger.Info(ctx, "UniVlanConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1537 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
| 1538 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1539 | break loop |
| 1540 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1541 | logger.Debugw(ctx, "UniVlanConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1542 | |
| 1543 | switch message.Type { |
| 1544 | case TestMsg: |
| 1545 | msg, _ := message.Data.(TestMessage) |
| 1546 | if msg.TestMessageVal == AbortMessageProcessing { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1547 | logger.Infow(ctx, "UniVlanConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1548 | break loop |
| 1549 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1550 | logger.Warnw(ctx, "UniVlanConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1551 | case OMCI: |
| 1552 | msg, _ := message.Data.(OmciMessage) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1553 | oFsm.handleOmciVlanConfigMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1554 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1555 | logger.Warn(ctx, "UniVlanConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1556 | "message.Type": message.Type}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1557 | } |
| 1558 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1559 | logger.Infow(ctx, "End UniVlanConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1562 | func (oFsm *UniVlanConfigFsm) handleOmciVlanConfigMessage(ctx context.Context, msg OmciMessage) { |
| 1563 | logger.Debugw(ctx, "Rx OMCI UniVlanConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1564 | "msgType": msg.OmciMsg.MessageType}) |
| 1565 | |
| 1566 | switch msg.OmciMsg.MessageType { |
| 1567 | case omci.CreateResponseType: |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1568 | { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-( |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1569 | if err := oFsm.handleOmciCreateResponseMessage(ctx, msg.OmciPacket); err != nil { |
| 1570 | logger.Warnw(ctx, "CreateResponse handling aborted", log.Fields{"err": err}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1571 | return |
| 1572 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1573 | } //CreateResponseType |
| 1574 | case omci.SetResponseType: |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1575 | { //leave that here as direct code as most often used |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1576 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 1577 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1578 | logger.Errorw(ctx, "Omci Msg layer could not be detected for SetResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1579 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1580 | return |
| 1581 | } |
| 1582 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 1583 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1584 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for SetResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1585 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1586 | return |
| 1587 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1588 | logger.Debugw(ctx, "UniVlanConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1589 | if msgObj.Result != me.Success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1590 | logger.Errorw(ctx, "UniVlanConfigFsm Omci SetResponse Error - later: drive FSM to abort state ?", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1591 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1592 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 1593 | return |
| 1594 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1595 | oFsm.mutexPLastTxMeInstance.RLock() |
| 1596 | if oFsm.pLastTxMeInstance != nil { |
| 1597 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 1598 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 1599 | switch oFsm.pLastTxMeInstance.GetName() { |
| 1600 | case "VlanTaggingFilterData", "ExtendedVlanTaggingOperationConfigurationData", "MulticastOperationsProfile": |
| 1601 | { // let the MultiEntity config proceed by stopping the wait function |
| 1602 | oFsm.mutexPLastTxMeInstance.RUnlock() |
| 1603 | oFsm.omciMIdsResponseReceived <- true |
| 1604 | return |
| 1605 | } |
| 1606 | default: |
| 1607 | { |
| 1608 | logger.Warnw(ctx, "Unsupported ME name received!", |
| 1609 | log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID}) |
| 1610 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1611 | } |
| 1612 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1613 | } else { |
| 1614 | logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1615 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1616 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1617 | } //SetResponseType |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1618 | case omci.DeleteResponseType: |
| 1619 | { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-( |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1620 | if err := oFsm.handleOmciDeleteResponseMessage(ctx, msg.OmciPacket); err != nil { |
| 1621 | logger.Warnw(ctx, "DeleteResponse handling aborted", log.Fields{"err": err}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1622 | return |
| 1623 | } |
| 1624 | } //DeleteResponseType |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1625 | default: |
| 1626 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1627 | logger.Errorw(ctx, "Rx OMCI unhandled MsgType", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1628 | log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1629 | return |
| 1630 | } |
| 1631 | } |
| 1632 | } |
| 1633 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1634 | func (oFsm *UniVlanConfigFsm) handleOmciCreateResponseMessage(ctx context.Context, apOmciPacket *gp.Packet) error { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1635 | msgLayer := (*apOmciPacket).Layer(omci.LayerTypeCreateResponse) |
| 1636 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1637 | logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1638 | log.Fields{"device-id": oFsm.deviceID}) |
| 1639 | return fmt.Errorf("omci msg layer could not be detected for CreateResponse for device-id %x", |
| 1640 | oFsm.deviceID) |
| 1641 | } |
| 1642 | msgObj, msgOk := msgLayer.(*omci.CreateResponse) |
| 1643 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1644 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1645 | log.Fields{"device-id": oFsm.deviceID}) |
| 1646 | return fmt.Errorf("omci msg layer could not be assigned for CreateResponse for device-id %x", |
| 1647 | oFsm.deviceID) |
| 1648 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1649 | logger.Debugw(ctx, "UniVlanConfigFsm CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1650 | if msgObj.Result != me.Success && msgObj.Result != me.InstanceExists { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1651 | logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": oFsm.deviceID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1652 | "Error": msgObj.Result}) |
| 1653 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 1654 | return fmt.Errorf("omci CreateResponse Error for device-id %x", |
| 1655 | oFsm.deviceID) |
| 1656 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1657 | oFsm.mutexPLastTxMeInstance.RLock() |
| 1658 | if oFsm.pLastTxMeInstance != nil { |
| 1659 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 1660 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 1661 | // to satisfy StaticCodeAnalysis I had to move the small processing into a separate method :-( |
| 1662 | switch oFsm.pLastTxMeInstance.GetName() { |
| 1663 | case "VlanTaggingFilterData", "MulticastOperationsProfile", |
| 1664 | "MulticastSubscriberConfigInfo", "MacBridgePortConfigurationData", |
| 1665 | "ExtendedVlanTaggingOperationConfigurationData": |
| 1666 | { |
| 1667 | oFsm.mutexPLastTxMeInstance.RUnlock() |
| 1668 | if oFsm.pAdaptFsm.pFsm.Current() == vlanStConfigVtfd { |
| 1669 | // Only if CreateResponse is received from first flow entry - let the FSM proceed ... |
| 1670 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigVtfd) |
| 1671 | } else { // let the MultiEntity config proceed by stopping the wait function |
| 1672 | oFsm.omciMIdsResponseReceived <- true |
| 1673 | } |
| 1674 | return nil |
| 1675 | } |
| 1676 | default: |
| 1677 | { |
| 1678 | logger.Warnw(ctx, "Unsupported ME name received!", |
| 1679 | log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1680 | } |
| 1681 | } |
| 1682 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1683 | } else { |
| 1684 | logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1685 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1686 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1687 | return nil |
| 1688 | } |
| 1689 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1690 | func (oFsm *UniVlanConfigFsm) handleOmciDeleteResponseMessage(ctx context.Context, apOmciPacket *gp.Packet) error { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1691 | msgLayer := (*apOmciPacket).Layer(omci.LayerTypeDeleteResponse) |
| 1692 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1693 | logger.Errorw(ctx, "UniVlanConfigFsm - Omci Msg layer could not be detected for DeleteResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1694 | log.Fields{"device-id": oFsm.deviceID}) |
| 1695 | return fmt.Errorf("omci msg layer could not be detected for DeleteResponse for device-id %x", |
| 1696 | oFsm.deviceID) |
| 1697 | } |
| 1698 | msgObj, msgOk := msgLayer.(*omci.DeleteResponse) |
| 1699 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1700 | logger.Errorw(ctx, "UniVlanConfigFsm - Omci Msg layer could not be assigned for DeleteResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1701 | log.Fields{"device-id": oFsm.deviceID}) |
| 1702 | return fmt.Errorf("omci msg layer could not be assigned for DeleteResponse for device-id %x", |
| 1703 | oFsm.deviceID) |
| 1704 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1705 | logger.Debugw(ctx, "UniVlanConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1706 | if msgObj.Result != me.Success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1707 | logger.Errorw(ctx, "UniVlanConfigFsm - Omci DeleteResponse Error - later: drive FSM to abort state ?", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1708 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 1709 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 1710 | return fmt.Errorf("omci DeleteResponse Error for device-id %x", |
| 1711 | oFsm.deviceID) |
| 1712 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1713 | oFsm.mutexPLastTxMeInstance.RLock() |
| 1714 | if oFsm.pLastTxMeInstance != nil { |
| 1715 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 1716 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 1717 | switch oFsm.pLastTxMeInstance.GetName() { |
| 1718 | case "VlanTaggingFilterData", "ExtendedVlanTaggingOperationConfigurationData": |
| 1719 | { // let the MultiEntity config proceed by stopping the wait function |
| 1720 | oFsm.mutexPLastTxMeInstance.RUnlock() |
| 1721 | oFsm.omciMIdsResponseReceived <- true |
| 1722 | return nil |
| 1723 | } |
| 1724 | default: |
| 1725 | { |
| 1726 | logger.Warnw(ctx, "Unsupported ME name received!", |
| 1727 | log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID}) |
| 1728 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1729 | } |
| 1730 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1731 | } else { |
| 1732 | logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1733 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1734 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1735 | return nil |
| 1736 | } |
| 1737 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1738 | func (oFsm *UniVlanConfigFsm) performConfigEvtocdEntries(ctx context.Context, aFlowEntryNo uint8) error { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1739 | if aFlowEntryNo == 0 { |
| 1740 | // EthType set only at first flow element |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1741 | // EVTOCD ME is expected to exist at this point already from MIB-Download (with AssociationType/Pointer) |
| 1742 | // we need to extend the configuration by EthType definition and, to be sure, downstream 'inverse' mode |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1743 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Create::EVTOCD", log.Fields{ |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1744 | "EntitytId": strconv.FormatInt(int64(oFsm.evtocdID), 16), |
| 1745 | "i/oEthType": strconv.FormatInt(int64(cDefaultTpid), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1746 | "device-id": oFsm.deviceID}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1747 | associationType := 2 // default to uniPPTP |
| 1748 | if oFsm.pOnuUniPort.portType == uniVEIP { |
| 1749 | associationType = 10 |
| 1750 | } |
| 1751 | // Create the EVTOCD ME |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1752 | meParams := me.ParamData{ |
| 1753 | EntityID: oFsm.evtocdID, |
| 1754 | Attributes: me.AttributeValueMap{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1755 | "AssociationType": uint8(associationType), |
| 1756 | "AssociatedMePointer": oFsm.pOnuUniPort.entityID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1757 | }, |
| 1758 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1759 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1760 | meInstance, err := oFsm.pOmciCC.sendCreateEvtocdVar(context.TODO(), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, |
| 1761 | true, oFsm.pAdaptFsm.commChan, meParams) |
| 1762 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1763 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1764 | logger.Errorw(ctx, "CreateEvtocdVar create failed, aborting UniVlanConfigFsm!", |
| 1765 | log.Fields{"device-id": oFsm.deviceID}) |
| 1766 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1767 | return fmt.Errorf("evtocd instance create failed %s, error %s", oFsm.deviceID, err) |
| 1768 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1769 | //accept also nil as (error) return value for writing to LastTx |
| 1770 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1771 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1772 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1773 | |
| 1774 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1775 | err = oFsm.waitforOmciResponse(ctx) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1776 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1777 | logger.Errorw(ctx, "Evtocd create failed, aborting VlanConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1778 | log.Fields{"device-id": oFsm.deviceID}) |
| 1779 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1780 | return fmt.Errorf("evtocd create failed %s, error %s", oFsm.deviceID, err) |
| 1781 | } |
| 1782 | |
| 1783 | // Set the EVTOCD ME default params |
| 1784 | meParams = me.ParamData{ |
| 1785 | EntityID: oFsm.evtocdID, |
| 1786 | Attributes: me.AttributeValueMap{ |
| 1787 | "InputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base |
| 1788 | "OutputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base |
| 1789 | "DownstreamMode": uint8(cDefaultDownstreamMode), |
| 1790 | }, |
| 1791 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1792 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1793 | meInstance, err = oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), |
| 1794 | oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1795 | oFsm.pAdaptFsm.commChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1796 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1797 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1798 | logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!", |
| 1799 | log.Fields{"device-id": oFsm.deviceID}) |
| 1800 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1801 | return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err) |
| 1802 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1803 | //accept also nil as (error) return value for writing to LastTx |
| 1804 | // - this avoids misinterpretation of new received OMCI messages |
| 1805 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1806 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1807 | |
| 1808 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1809 | err = oFsm.waitforOmciResponse(ctx) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1810 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1811 | logger.Errorw(ctx, "Evtocd set TPID failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1812 | log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1813 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1814 | return fmt.Errorf("evtocd set TPID failed %s, error %s", oFsm.deviceID, err) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1815 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1816 | } //first flow element |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1817 | |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1818 | oFsm.mutexFlowParams.RLock() |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1819 | if oFsm.actualUniVlanConfigRule.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1820 | //transparent transmission required |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1821 | oFsm.mutexFlowParams.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1822 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD single tagged transparent rule", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1823 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1824 | sliceEvtocdRule := make([]uint8, 16) |
| 1825 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 1826 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 1827 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 1828 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 1829 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 1830 | |
| 1831 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 1832 | cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule |
| 1833 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 1834 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 1835 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 1836 | |
| 1837 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 1838 | 0<<cTreatTTROffset| // Do not pop any tags |
| 1839 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 1840 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 1841 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 1842 | |
| 1843 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 1844 | cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag |
| 1845 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 1846 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 1847 | |
| 1848 | meParams := me.ParamData{ |
| 1849 | EntityID: oFsm.evtocdID, |
| 1850 | Attributes: me.AttributeValueMap{ |
| 1851 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 1852 | }, |
| 1853 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1854 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1855 | meInstance, err := oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), |
| 1856 | oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1857 | oFsm.pAdaptFsm.commChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1858 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1859 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1860 | logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!", |
| 1861 | log.Fields{"device-id": oFsm.deviceID}) |
| 1862 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1863 | return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err) |
| 1864 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1865 | //accept also nil as (error) return value for writing to LastTx |
| 1866 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1867 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1868 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1869 | |
| 1870 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1871 | err = oFsm.waitforOmciResponse(ctx) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1872 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1873 | logger.Errorw(ctx, "Evtocd set transparent singletagged rule failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1874 | log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1875 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1876 | return fmt.Errorf("evtocd set transparent singletagged rule failed %s, error %s", oFsm.deviceID, err) |
| 1877 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1878 | } |
| 1879 | } else { |
| 1880 | // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario |
| 1881 | if oFsm.acceptIncrementalEvtoOption { |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1882 | matchPcp := oFsm.actualUniVlanConfigRule.MatchPcp |
| 1883 | matchVid := oFsm.actualUniVlanConfigRule.MatchVid |
| 1884 | setPcp := oFsm.actualUniVlanConfigRule.SetPcp |
| 1885 | setVid := oFsm.actualUniVlanConfigRule.SetVid |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1886 | // this defines VID translation scenario: singletagged->singletagged (if not transparent) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1887 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD single tagged translation rule", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1888 | "match-pcp": matchPcp, "match-vid": matchVid, "set-pcp": setPcp, "set-vid:": setVid, "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1889 | sliceEvtocdRule := make([]uint8, 16) |
| 1890 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 1891 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 1892 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 1893 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 1894 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 1895 | |
| 1896 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1897 | oFsm.actualUniVlanConfigRule.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN |
| 1898 | oFsm.actualUniVlanConfigRule.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1899 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 1900 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 1901 | |
| 1902 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1903 | oFsm.actualUniVlanConfigRule.TagsToRemove<<cTreatTTROffset| // either 1 or 0 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1904 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 1905 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 1906 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 1907 | |
| 1908 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1909 | oFsm.actualUniVlanConfigRule.SetPcp<<cTreatPrioOffset| // as configured in flow |
| 1910 | oFsm.actualUniVlanConfigRule.SetVid<<cTreatVidOffset| //as configured in flow |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1911 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1912 | oFsm.mutexFlowParams.RUnlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1913 | |
| 1914 | meParams := me.ParamData{ |
| 1915 | EntityID: oFsm.evtocdID, |
| 1916 | Attributes: me.AttributeValueMap{ |
| 1917 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 1918 | }, |
| 1919 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1920 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1921 | meInstance, err := oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), |
| 1922 | oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1923 | oFsm.pAdaptFsm.commChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1924 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame^] | 1925 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1926 | logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!", |
| 1927 | log.Fields{"device-id": oFsm.deviceID}) |
| 1928 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1929 | return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err) |
| 1930 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1931 | //accept also nil as (error) return value for writing to LastTx |
| 1932 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1933 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [ |