blob: 03cacf9d962eff17fe3d606d006862104b8fc708 [file] [log] [blame]
mpagenkodff5dda2020-08-28 11:52:01 +00001/*
2 * Copyright 2020-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000017//Package avcfg provides anig and vlan configuration functionality
18package avcfg
mpagenkodff5dda2020-08-28 11:52:01 +000019
20import (
21 "context"
22 "encoding/binary"
mpagenkof582d6a2021-06-18 15:58:10 +000023 "errors"
Andrea Campanella6515c582020-10-05 11:25:00 +020024 "fmt"
ozgecanetsiab5000ef2020-11-27 14:38:20 +030025 "net"
mpagenkodff5dda2020-08-28 11:52:01 +000026 "strconv"
Holger Hildebrandt394c5522020-09-11 11:23:01 +000027 "sync"
mpagenkodff5dda2020-08-28 11:52:01 +000028 "time"
29
khenaidoo7d3c5582021-08-11 18:09:44 -040030 meters "github.com/opencord/voltha-lib-go/v7/pkg/meters"
31 "github.com/opencord/voltha-protos/v5/go/voltha"
ozgecanetsia82b91a62021-05-21 18:54:49 +030032
mpagenko01e726e2020-10-23 09:45:29 +000033 gp "github.com/google/gopacket"
mpagenkodff5dda2020-08-28 11:52:01 +000034 "github.com/looplab/fsm"
35 "github.com/opencord/omci-lib-go"
36 me "github.com/opencord/omci-lib-go/generated"
khenaidoo7d3c5582021-08-11 18:09:44 -040037 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000038 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
39 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb"
khenaidoo7d3c5582021-08-11 18:09:44 -040040 of "github.com/opencord/voltha-protos/v5/go/openflow_13"
mpagenkodff5dda2020-08-28 11:52:01 +000041)
42
43const (
44 // internal predefined values
45 cDefaultDownstreamMode = 0
46 cDefaultTpid = 0x8100
mpagenko01e726e2020-10-23 09:45:29 +000047 cVtfdTableSize = 12 //as per G.988
48 cMaxAllowedFlows = cVtfdTableSize //which might be under discussion, for the moment connected to limit of VLAN's within VTFD
mpagenkodff5dda2020-08-28 11:52:01 +000049)
50
51const (
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000052 // internal offsets for requestEvent according to definition in onu_device_entry::cmn.OnuDeviceEvent
mpagenkof1fc3862021-02-16 10:09:52 +000053 cDeviceEventOffsetAddWithKvStore = 0 //OmciVlanFilterAddDone - OmciVlanFilterAddDone cannot use because of lint
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000054 cDeviceEventOffsetAddNoKvStore = cmn.OmciVlanFilterAddDoneNoKvStore - cmn.OmciVlanFilterAddDone
55 cDeviceEventOffsetRemoveWithKvStore = cmn.OmciVlanFilterRemDone - cmn.OmciVlanFilterAddDone
56 cDeviceEventOffsetRemoveNoKvStore = cmn.OmciVlanFilterRemDoneNoKvStore - cmn.OmciVlanFilterAddDone
mpagenkof1fc3862021-02-16 10:09:52 +000057)
58
59const (
mpagenkodff5dda2020-08-28 11:52:01 +000060 // bit mask offsets for EVTOCD VlanTaggingOperationTable related to 32 bits (4 bytes)
61 cFilterPrioOffset = 28
62 cFilterVidOffset = 15
63 cFilterTpidOffset = 12
64 cFilterEtherTypeOffset = 0
65 cTreatTTROffset = 30
66 cTreatPrioOffset = 16
67 cTreatVidOffset = 3
68 cTreatTpidOffset = 0
69)
70const (
71 // byte offsets for EVTOCD VlanTaggingOperationTable related to overall 16 byte size with slice byte 0 as first Byte (MSB)
72 cFilterOuterOffset = 0
73 cFilterInnerOffset = 4
74 cTreatOuterOffset = 8
75 cTreatInnerOffset = 12
76)
77const (
78 // basic values used within EVTOCD VlanTaggingOperationTable in respect to their bitfields
79 cPrioIgnoreTag uint32 = 15
80 cPrioDefaultFilter uint32 = 14
81 cPrioDoNotFilter uint32 = 8
82 cDoNotFilterVid uint32 = 4096
83 cDoNotFilterTPID uint32 = 0
84 cDoNotFilterEtherType uint32 = 0
85 cDoNotAddPrio uint32 = 15
86 cCopyPrioFromInner uint32 = 8
Himani Chawla4d908332020-08-31 12:30:20 +053087 //cDontCarePrio uint32 = 0
mpagenkodff5dda2020-08-28 11:52:01 +000088 cDontCareVid uint32 = 0
89 cDontCareTpid uint32 = 0
90 cSetOutputTpidCopyDei uint32 = 4
91)
92
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000093// events of config UNI port VLAN FSM
mpagenkodff5dda2020-08-28 11:52:01 +000094const (
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000095 VlanEvStart = "VlanEvStart"
96 VlanEvPrepareDone = "VlanEvPrepareDone"
97 VlanEvWaitTechProf = "VlanEvWaitTechProf"
98 VlanEvCancelOutstandingConfig = "VlanEvCancelOutstandingConfig"
99 VlanEvContinueConfig = "VlanEvContinueConfig"
100 VlanEvStartConfig = "VlanEvStartConfig"
101 VlanEvRxConfigVtfd = "VlanEvRxConfigVtfd"
102 VlanEvRxConfigEvtocd = "VlanEvRxConfigEvtocd"
103 VlanEvWaitTPIncr = "VlanEvWaitTPIncr"
104 VlanEvIncrFlowConfig = "VlanEvIncrFlowConfig"
105 VlanEvRenew = "VlanEvRenew"
106 VlanEvRemFlowConfig = "VlanEvRemFlowConfig"
107 VlanEvRemFlowDone = "VlanEvRemFlowDone"
108 VlanEvFlowDataRemoved = "VlanEvFlowDataRemoved"
109 //VlanEvTimeoutSimple = "VlanEvTimeoutSimple"
110 //VlanEvTimeoutMids = "VlanEvTimeoutMids"
111 VlanEvReset = "VlanEvReset"
112 VlanEvRestart = "VlanEvRestart"
113 VlanEvSkipOmciConfig = "VlanEvSkipOmciConfig"
114 VlanEvSkipIncFlowConfig = "VlanEvSkipIncFlowConfig"
mpagenkodff5dda2020-08-28 11:52:01 +0000115)
mpagenko01e726e2020-10-23 09:45:29 +0000116
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000117// states of config UNI port VLAN FSM
mpagenkodff5dda2020-08-28 11:52:01 +0000118const (
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000119 VlanStDisabled = "VlanStDisabled"
120 VlanStPreparing = "VlanStPreparing"
121 VlanStStarting = "VlanStStarting"
122 VlanStWaitingTechProf = "VlanStWaitingTechProf"
123 VlanStConfigVtfd = "VlanStConfigVtfd"
124 VlanStConfigEvtocd = "VlanStConfigEvtocd"
125 VlanStConfigDone = "VlanStConfigDone"
126 VlanStIncrFlowWaitTP = "VlanStIncrFlowWaitTP"
127 VlanStConfigIncrFlow = "VlanStConfigIncrFlow"
128 VlanStRemoveFlow = "VlanStRemoveFlow"
129 VlanStCleanupDone = "VlanStCleanupDone"
130 VlanStResetting = "VlanStResetting"
mpagenkodff5dda2020-08-28 11:52:01 +0000131)
132
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000133// CVlanFsmIdleState - TODO: add comment
134const CVlanFsmIdleState = VlanStConfigDone // state where no OMCI activity is done (for a longer time)
135// CVlanFsmConfiguredState - TODO: add comment
136const CVlanFsmConfiguredState = VlanStConfigDone // state that indicates that at least some valid user related VLAN configuration should exist
mpagenko01e726e2020-10-23 09:45:29 +0000137
138type uniRemoveVlanFlowParams struct {
mpagenkof1d21d12021-06-11 13:14:45 +0000139 isSuspendedOnAdd bool
140 removeChannel chan bool
141 cookie uint64 //just the last cookie valid for removal
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000142 vlanRuleParams cmn.UniVlanRuleParams
Girish Gowdrae95687a2021-09-08 16:30:58 -0700143 respChan *chan error
mpagenko01e726e2020-10-23 09:45:29 +0000144}
145
mpagenkobb47bc22021-04-20 13:29:09 +0000146//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
mpagenkodff5dda2020-08-28 11:52:01 +0000148type UniVlanConfigFsm struct {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000149 pDeviceHandler cmn.IdeviceHandler
150 pOnuDeviceEntry cmn.IonuDeviceEntry
mpagenko01e726e2020-10-23 09:45:29 +0000151 deviceID string
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000152 pOmciCC *cmn.OmciCC
153 pOnuUniPort *cmn.OnuUniPort
154 pUniTechProf *OnuUniTechProf
155 pOnuDB *devdb.OnuDeviceDB
156 requestEvent cmn.OnuDeviceEvent
mpagenkodff5dda2020-08-28 11:52:01 +0000157 omciMIdsResponseReceived chan bool //seperate channel needed for checking multiInstance OMCI message responses
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000158 PAdaptFsm *cmn.AdapterFsm
mpagenkodff5dda2020-08-28 11:52:01 +0000159 acceptIncrementalEvtoOption bool
mpagenko2418ab02020-11-12 12:58:06 +0000160 clearPersistency bool
mpagenkocf48e452021-04-23 09:23:00 +0000161 isCanceled bool
mpagenko7d6bb022021-03-11 15:07:55 +0000162 isAwaitingResponse bool
163 mutexIsAwaitingResponse sync.RWMutex
mpagenko551a4d42020-12-08 18:09:20 +0000164 mutexFlowParams sync.RWMutex
mpagenkobb47bc22021-04-20 13:29:09 +0000165 chCookieDeleted chan bool //channel to indicate that a specific cookie (related to the active rule) was deleted
Girish Gowdrae95687a2021-09-08 16:30:58 -0700166 actualUniFlowParam cmn.UniVlanFlowParams
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000167 uniVlanFlowParamsSlice []cmn.UniVlanFlowParams
mpagenko01e726e2020-10-23 09:45:29 +0000168 uniRemoveFlowsSlice []uniRemoveVlanFlowParams
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000169 NumUniFlows uint8 // expected number of flows should be less than 12
170 ConfiguredUniFlow uint8
mpagenko01e726e2020-10-23 09:45:29 +0000171 numRemoveFlows uint8
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000172 numVlanFilterEntries uint8
mpagenko01e726e2020-10-23 09:45:29 +0000173 vlanFilterList [cVtfdTableSize]uint16
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000174 evtocdID uint16
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000175 mutexPLastTxMeInstance sync.RWMutex
mpagenko01e726e2020-10-23 09:45:29 +0000176 pLastTxMeInstance *me.ManagedEntity
mpagenkofc4f56e2020-11-04 17:17:49 +0000177 requestEventOffset uint8
mpagenko551a4d42020-12-08 18:09:20 +0000178 TpIDWaitingFor uint8
mpagenkobb47bc22021-04-20 13:29:09 +0000179 signalOnFlowDelete bool
180 flowDeleteChannel chan<- bool
mpagenkof1fc3862021-02-16 10:09:52 +0000181 //cookie value that indicates that a rule to add is delayed by waiting for deletion of some other existing rule with the same cookie
182 delayNewRuleCookie uint64
Andrea Campanellaf66ac6e2021-05-24 17:09:20 +0200183 // Used to indicate if the FSM is for a reconciling flow and if it's the last flow to be reconciled
184 // thus notification needs to be sent on chan.
185 lastFlowToReconcile bool
mpagenkodff5dda2020-08-28 11:52:01 +0000186}
187
mpagenko01e726e2020-10-23 09:45:29 +0000188//NewUniVlanConfigFsm is the 'constructor' for the state machine to config the PON ANI ports
189// of ONU UNI ports via OMCI
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000190func NewUniVlanConfigFsm(ctx context.Context, apDeviceHandler cmn.IdeviceHandler, apOnuDeviceEntry cmn.IonuDeviceEntry, apDevOmciCC *cmn.OmciCC, apUniPort *cmn.OnuUniPort,
191 apUniTechProf *OnuUniTechProf, apOnuDB *devdb.OnuDeviceDB, aTechProfileID uint8,
192 aRequestEvent cmn.OnuDeviceEvent, aName string, aCommChannel chan cmn.Message, aAcceptIncrementalEvto bool,
Girish Gowdrae95687a2021-09-08 16:30:58 -0700193 aCookieSlice []uint64, aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8, lastFlowToRec bool, aMeter *voltha.OfpMeterConfig, respChan *chan error) *UniVlanConfigFsm {
mpagenkodff5dda2020-08-28 11:52:01 +0000194 instFsm := &UniVlanConfigFsm{
195 pDeviceHandler: apDeviceHandler,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000196 pOnuDeviceEntry: apOnuDeviceEntry,
197 deviceID: apDeviceHandler.GetDeviceID(),
mpagenkodff5dda2020-08-28 11:52:01 +0000198 pOmciCC: apDevOmciCC,
199 pOnuUniPort: apUniPort,
200 pUniTechProf: apUniTechProf,
201 pOnuDB: apOnuDB,
mpagenkodff5dda2020-08-28 11:52:01 +0000202 requestEvent: aRequestEvent,
203 acceptIncrementalEvtoOption: aAcceptIncrementalEvto,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000204 NumUniFlows: 0,
205 ConfiguredUniFlow: 0,
mpagenko01e726e2020-10-23 09:45:29 +0000206 numRemoveFlows: 0,
mpagenko2418ab02020-11-12 12:58:06 +0000207 clearPersistency: true,
Andrea Campanellaf66ac6e2021-05-24 17:09:20 +0200208 lastFlowToReconcile: lastFlowToRec,
mpagenkodff5dda2020-08-28 11:52:01 +0000209 }
210
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000211 instFsm.PAdaptFsm = cmn.NewAdapterFsm(aName, instFsm.deviceID, aCommChannel)
212 if instFsm.PAdaptFsm == nil {
213 logger.Errorw(ctx, "UniVlanConfigFsm's cmn.AdapterFsm could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000214 "device-id": instFsm.deviceID})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700215 // Push response on the response channel
216 instFsm.PushReponseOnFlowResponseChannel(ctx, respChan, fmt.Errorf("adapter-fsm-could-not-be-instantiated"))
mpagenkodff5dda2020-08-28 11:52:01 +0000217 return nil
218 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000219 instFsm.PAdaptFsm.PFsm = fsm.NewFSM(
220 VlanStDisabled,
mpagenkodff5dda2020-08-28 11:52:01 +0000221 fsm.Events{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000222 {Name: VlanEvStart, Src: []string{VlanStDisabled}, Dst: VlanStPreparing},
223 {Name: VlanEvPrepareDone, Src: []string{VlanStPreparing}, Dst: VlanStStarting},
224 {Name: VlanEvWaitTechProf, Src: []string{VlanStStarting}, Dst: VlanStWaitingTechProf},
225 {Name: VlanEvCancelOutstandingConfig, Src: []string{VlanStWaitingTechProf}, Dst: VlanStConfigDone},
226 {Name: VlanEvContinueConfig, Src: []string{VlanStWaitingTechProf}, Dst: VlanStConfigVtfd},
227 {Name: VlanEvStartConfig, Src: []string{VlanStStarting}, Dst: VlanStConfigVtfd},
228 {Name: VlanEvRxConfigVtfd, Src: []string{VlanStConfigVtfd}, Dst: VlanStConfigEvtocd},
229 {Name: VlanEvRxConfigEvtocd, Src: []string{VlanStConfigEvtocd, VlanStConfigIncrFlow},
230 Dst: VlanStConfigDone},
231 {Name: VlanEvRenew, Src: []string{VlanStConfigDone}, Dst: VlanStStarting},
232 {Name: VlanEvWaitTPIncr, Src: []string{VlanStConfigDone}, Dst: VlanStIncrFlowWaitTP},
233 {Name: VlanEvIncrFlowConfig, Src: []string{VlanStConfigDone, VlanStIncrFlowWaitTP},
234 Dst: VlanStConfigIncrFlow},
235 {Name: VlanEvRemFlowConfig, Src: []string{VlanStConfigDone}, Dst: VlanStRemoveFlow},
236 {Name: VlanEvRemFlowDone, Src: []string{VlanStRemoveFlow}, Dst: VlanStCleanupDone},
237 {Name: VlanEvFlowDataRemoved, Src: []string{VlanStCleanupDone}, Dst: VlanStConfigDone},
mpagenkodff5dda2020-08-28 11:52:01 +0000238 /*
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000239 {Name: VlanEvTimeoutSimple, Src: []string{
240 VlanStCreatingDot1PMapper, VlanStCreatingMBPCD, VlanStSettingTconts, VlanStSettingDot1PMapper}, Dst: VlanStStarting},
241 {Name: VlanEvTimeoutMids, Src: []string{
242 VlanStCreatingGemNCTPs, VlanStCreatingGemIWs, VlanStSettingPQs}, Dst: VlanStStarting},
mpagenkodff5dda2020-08-28 11:52:01 +0000243 */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000244 // exceptional treatment for all states except VlanStResetting
245 {Name: VlanEvReset, Src: []string{VlanStStarting, VlanStWaitingTechProf,
246 VlanStConfigVtfd, VlanStConfigEvtocd, VlanStConfigDone, VlanStConfigIncrFlow,
247 VlanStRemoveFlow, VlanStCleanupDone},
248 Dst: VlanStResetting},
mpagenkodff5dda2020-08-28 11:52:01 +0000249 // the only way to get to resource-cleared disabled state again is via "resseting"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000250 {Name: VlanEvRestart, Src: []string{VlanStResetting}, Dst: VlanStDisabled},
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000251 // transitions for reconcile handling according to VOL-3834
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000252 {Name: VlanEvSkipOmciConfig, Src: []string{VlanStPreparing}, Dst: VlanStConfigDone},
253 {Name: VlanEvSkipOmciConfig, Src: []string{VlanStConfigDone}, Dst: VlanStConfigIncrFlow},
254 {Name: VlanEvSkipIncFlowConfig, Src: []string{VlanStConfigIncrFlow}, Dst: VlanStConfigDone},
mpagenkodff5dda2020-08-28 11:52:01 +0000255 },
mpagenkodff5dda2020-08-28 11:52:01 +0000256 fsm.Callbacks{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000257 "enter_state": func(e *fsm.Event) { instFsm.PAdaptFsm.LogFsmStateChange(ctx, e) },
258 "enter_" + VlanStPreparing: func(e *fsm.Event) { instFsm.enterPreparing(ctx, e) },
259 "enter_" + VlanStStarting: func(e *fsm.Event) { instFsm.enterConfigStarting(ctx, e) },
260 "enter_" + VlanStConfigVtfd: func(e *fsm.Event) { instFsm.enterConfigVtfd(ctx, e) },
261 "enter_" + VlanStConfigEvtocd: func(e *fsm.Event) { instFsm.enterConfigEvtocd(ctx, e) },
262 "enter_" + VlanStConfigDone: func(e *fsm.Event) { instFsm.enterVlanConfigDone(ctx, e) },
263 "enter_" + VlanStConfigIncrFlow: func(e *fsm.Event) { instFsm.enterConfigIncrFlow(ctx, e) },
264 "enter_" + VlanStRemoveFlow: func(e *fsm.Event) { instFsm.enterRemoveFlow(ctx, e) },
265 "enter_" + VlanStCleanupDone: func(e *fsm.Event) { instFsm.enterVlanCleanupDone(ctx, e) },
266 "enter_" + VlanStResetting: func(e *fsm.Event) { instFsm.enterResetting(ctx, e) },
267 "enter_" + VlanStDisabled: func(e *fsm.Event) { instFsm.enterDisabled(ctx, e) },
mpagenkodff5dda2020-08-28 11:52:01 +0000268 },
269 )
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000270 if instFsm.PAdaptFsm.PFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000271 logger.Errorw(ctx, "UniVlanConfigFsm's Base FSM could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000272 "device-id": instFsm.deviceID})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700273 // Push response on the response channel
274 instFsm.PushReponseOnFlowResponseChannel(ctx, respChan, fmt.Errorf("adapter-base-fsm-could-not-be-instantiated"))
mpagenkodff5dda2020-08-28 11:52:01 +0000275 return nil
276 }
277
Girish Gowdrae95687a2021-09-08 16:30:58 -0700278 _ = instFsm.initUniFlowParams(ctx, aTechProfileID, aCookieSlice, aMatchVlan, aSetVlan, aSetPcp, aMeter, respChan)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000279
dbainbri4d3a0dc2020-12-02 00:33:42 +0000280 logger.Debugw(ctx, "UniVlanConfigFsm created", log.Fields{"device-id": instFsm.deviceID,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000281 "accIncrEvto": instFsm.acceptIncrementalEvtoOption})
mpagenkodff5dda2020-08-28 11:52:01 +0000282 return instFsm
283}
284
mpagenko01e726e2020-10-23 09:45:29 +0000285//initUniFlowParams is a simplified form of SetUniFlowParams() used for first flow parameters configuration
mpagenko551a4d42020-12-08 18:09:20 +0000286func (oFsm *UniVlanConfigFsm) initUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64,
Girish Gowdrae95687a2021-09-08 16:30:58 -0700287 aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8, aMeter *voltha.OfpMeterConfig, respChan *chan error) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000288 loRuleParams := cmn.UniVlanRuleParams{
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000289 TpID: aTpID,
290 MatchVid: uint32(aMatchVlan),
291 SetVid: uint32(aSetVlan),
292 SetPcp: uint32(aSetPcp),
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000293 }
294 // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters
mpagenko01e726e2020-10-23 09:45:29 +0000295 loRuleParams.TagsToRemove = 1 //one tag to remove as default setting
296 loRuleParams.MatchPcp = cPrioDoNotFilter // do not Filter on prio as default
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000297
mpagenko01e726e2020-10-23 09:45:29 +0000298 if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000299 //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries
mpagenko01e726e2020-10-23 09:45:29 +0000300 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000301 //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther)
302 } else {
303 if !oFsm.acceptIncrementalEvtoOption {
304 //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries
mpagenko01e726e2020-10-23 09:45:29 +0000305 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000306 }
307 }
308
mpagenko01e726e2020-10-23 09:45:29 +0000309 if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000310 // no prio/vid filtering requested
mpagenko01e726e2020-10-23 09:45:29 +0000311 loRuleParams.TagsToRemove = 0 //no tag pop action
312 loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering
313 if loRuleParams.SetPcp == cCopyPrioFromInner {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000314 //in case of no filtering and configured PrioCopy ensure default prio setting to 0
315 // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged
316 // might collide with NoMatchVid/CopyPrio(/setVid) setting
317 // this was some precondition setting taken over from py adapter ..
mpagenko01e726e2020-10-23 09:45:29 +0000318 loRuleParams.SetPcp = 0
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000319 }
320 }
mpagenko01e726e2020-10-23 09:45:29 +0000321
Girish Gowdrae95687a2021-09-08 16:30:58 -0700322 loFlowParams := cmn.UniVlanFlowParams{VlanRuleParams: loRuleParams, RespChan: respChan}
mpagenko01e726e2020-10-23 09:45:29 +0000323 loFlowParams.CookieSlice = make([]uint64, 0)
324 loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...)
ozgecanetsia82b91a62021-05-21 18:54:49 +0300325 if aMeter != nil {
326 loFlowParams.Meter = aMeter
327 }
mpagenko01e726e2020-10-23 09:45:29 +0000328
329 //no mutex protection is required for initial access and adding the first flow is always possible
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000330 oFsm.uniVlanFlowParamsSlice = make([]cmn.UniVlanFlowParams, 0)
mpagenko01e726e2020-10-23 09:45:29 +0000331 oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000332 logger.Debugw(ctx, "first UniVlanConfigFsm flow added", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000333 "Cookies": oFsm.uniVlanFlowParamsSlice[0].CookieSlice,
334 "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16),
335 "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
336 "SetPcp": loRuleParams.SetPcp,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000337 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
Holger Hildebrandt968eb8f2021-09-17 07:41:12 +0000338
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000339 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandt968eb8f2021-09-17 07:41:12 +0000340 oFsm.reconcileVlanFilterList(ctx, uint16(loRuleParams.SetVid))
341 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000342 oFsm.NumUniFlows = 1
mpagenko01e726e2020-10-23 09:45:29 +0000343 oFsm.uniRemoveFlowsSlice = make([]uniRemoveVlanFlowParams, 0) //initially nothing to remove
344
345 //permanently store flow config for reconcile case
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000346 if err := oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID,
mpagenkof1fc3862021-02-16 10:09:52 +0000347 &oFsm.uniVlanFlowParamsSlice, true); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000348 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +0000349 return err
350 }
351
352 return nil
353}
354
mpagenko7d6bb022021-03-11 15:07:55 +0000355//CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM
mpagenko73143992021-04-09 15:17:10 +0000356func (oFsm *UniVlanConfigFsm) CancelProcessing(ctx context.Context) {
mpagenko7d6bb022021-03-11 15:07:55 +0000357 //mutex protection is required for possible concurrent access to FSM members
mpagenkocf48e452021-04-23 09:23:00 +0000358 oFsm.mutexIsAwaitingResponse.Lock()
359 oFsm.isCanceled = true
mpagenko7d6bb022021-03-11 15:07:55 +0000360 if oFsm.isAwaitingResponse {
mpagenkocf48e452021-04-23 09:23:00 +0000361 //attention: for an unbuffered channel the sender is blocked until the value is received (processed)!
362 // accordingly the mutex must be released before sending to channel here (mutex acquired in receiver)
363 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko7d6bb022021-03-11 15:07:55 +0000364 //use channel to indicate that the response waiting shall be aborted
365 oFsm.omciMIdsResponseReceived <- false
mpagenkocf48e452021-04-23 09:23:00 +0000366 } else {
367 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko7d6bb022021-03-11 15:07:55 +0000368 }
mpagenkocf48e452021-04-23 09:23:00 +0000369
mpagenko7d6bb022021-03-11 15:07:55 +0000370 // in any case (even if it might be automatically requested by above cancellation of waiting) ensure resetting the FSM
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000371 PAdaptFsm := oFsm.PAdaptFsm
372 if PAdaptFsm != nil {
373 if fsmErr := PAdaptFsm.PFsm.Event(VlanEvReset); fsmErr != nil {
mpagenkocf48e452021-04-23 09:23:00 +0000374 logger.Errorw(ctx, "reset-event failed in UniVlanConfigFsm!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000375 log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000376 }
mpagenko7d6bb022021-03-11 15:07:55 +0000377 }
378}
379
mpagenko551a4d42020-12-08 18:09:20 +0000380//GetWaitingTpID returns the TpId that the FSM might be waiting for continuation (0 if none)
381func (oFsm *UniVlanConfigFsm) GetWaitingTpID() uint8 {
382 //mutex protection is required for possible concurrent access to FSM members
383 oFsm.mutexFlowParams.RLock()
384 defer oFsm.mutexFlowParams.RUnlock()
385 return oFsm.TpIDWaitingFor
386}
387
mpagenko2418ab02020-11-12 12:58:06 +0000388//RequestClearPersistency sets the internal flag to not clear persistency data (false=NoClear)
389func (oFsm *UniVlanConfigFsm) RequestClearPersistency(aClear bool) {
390 //mutex protection is required for possible concurrent access to FSM members
mpagenko15ff4a52021-03-02 10:09:20 +0000391 oFsm.mutexFlowParams.Lock()
392 defer oFsm.mutexFlowParams.Unlock()
mpagenko2418ab02020-11-12 12:58:06 +0000393 oFsm.clearPersistency = aClear
394}
395
mpagenko01e726e2020-10-23 09:45:29 +0000396//SetUniFlowParams verifies on existence of flow parameters to be configured,
397// optionally udates the cookie list or appends a new flow if there is space
398// if possible the FSM is trigggerd to start with the processing
mpagenko551a4d42020-12-08 18:09:20 +0000399// ignore complexity by now
400// nolint: gocyclo
401func (oFsm *UniVlanConfigFsm) SetUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64,
Girish Gowdrae95687a2021-09-08 16:30:58 -0700402 aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8, lastFlowToReconcile bool, aMeter *voltha.OfpMeterConfig, respChan *chan error) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000403 loRuleParams := cmn.UniVlanRuleParams{
mpagenko01e726e2020-10-23 09:45:29 +0000404 TpID: aTpID,
405 MatchVid: uint32(aMatchVlan),
406 SetVid: uint32(aSetVlan),
407 SetPcp: uint32(aSetPcp),
408 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700409 var err error
mpagenko01e726e2020-10-23 09:45:29 +0000410 // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters
411 loRuleParams.TagsToRemove = 1 //one tag to remove as default setting
412 loRuleParams.MatchPcp = cPrioDoNotFilter // do not Filter on prio as default
mpagenko01e726e2020-10-23 09:45:29 +0000413 if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
414 //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries
415 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
416 //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther)
417 } else {
418 if !oFsm.acceptIncrementalEvtoOption {
419 //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries
420 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
421 }
422 }
423
424 if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
425 // no prio/vid filtering requested
426 loRuleParams.TagsToRemove = 0 //no tag pop action
427 loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering
428 if loRuleParams.SetPcp == cCopyPrioFromInner {
429 //in case of no filtering and configured PrioCopy ensure default prio setting to 0
430 // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged
431 // might collide with NoMatchVid/CopyPrio(/setVid) setting
432 // this was some precondition setting taken over from py adapter ..
433 loRuleParams.SetPcp = 0
434 }
435 }
436
mpagenkof1d21d12021-06-11 13:14:45 +0000437 //check if there is some ongoing delete-request running for this flow. If so, block here until this is finished.
438 // might be accordingly rwCore processing runs into timeout in specific situations - needs to be observed ...
439 // this is to protect uniVlanFlowParams from adding new or re-writing the same cookie to the rule currently under deletion
440 oFsm.mutexFlowParams.RLock()
441 if len(oFsm.uniRemoveFlowsSlice) > 0 {
442 for flow, removeUniFlowParams := range oFsm.uniRemoveFlowsSlice {
443 if removeUniFlowParams.vlanRuleParams == loRuleParams {
444 // the flow to add is the same as the one already in progress of deleting
445 logger.Infow(ctx, "UniVlanConfigFsm flow setting - suspending rule-add due to ongoing removal", log.Fields{
mpagenkof582d6a2021-06-18 15:58:10 +0000446 "device-id": oFsm.deviceID, "cookie": removeUniFlowParams.cookie, "remove-index": flow})
447 if flow >= len(oFsm.uniRemoveFlowsSlice) {
448 logger.Errorw(ctx, "abort UniVlanConfigFsm flow add - inconsistent RemoveFlowsSlice", log.Fields{
449 "device-id": oFsm.deviceID, "slice length": len(oFsm.uniRemoveFlowsSlice)})
450 oFsm.mutexFlowParams.RUnlock()
Girish Gowdrae95687a2021-09-08 16:30:58 -0700451 err = fmt.Errorf("abort UniVlanConfigFsm flow add - inconsistent RemoveFlowsSlice %s", oFsm.deviceID)
452 oFsm.PushReponseOnFlowResponseChannel(ctx, respChan, err)
453 return err
454
mpagenkof582d6a2021-06-18 15:58:10 +0000455 }
mpagenkof1d21d12021-06-11 13:14:45 +0000456 pRemoveParams := &oFsm.uniRemoveFlowsSlice[flow] //wants to modify the uniRemoveFlowsSlice element directly!
457 oFsm.mutexFlowParams.RUnlock()
458 if err := oFsm.suspendAddRule(ctx, pRemoveParams); err != nil {
459 logger.Errorw(ctx, "UniVlanConfigFsm suspension on add aborted - abort complete add-request", log.Fields{
460 "device-id": oFsm.deviceID, "cookie": removeUniFlowParams.cookie})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700461 err = fmt.Errorf("abort UniVlanConfigFsm suspension on add %s", oFsm.deviceID)
462 oFsm.PushReponseOnFlowResponseChannel(ctx, respChan, err)
463 return err
mpagenkof1d21d12021-06-11 13:14:45 +0000464 }
465 oFsm.mutexFlowParams.RLock()
mpagenkof582d6a2021-06-18 15:58:10 +0000466 break //this specific rule should only exist once per uniRemoveFlowsSlice
mpagenkof1d21d12021-06-11 13:14:45 +0000467 }
468 }
469 }
470 oFsm.mutexFlowParams.RUnlock()
471
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000472 flowEntryMatch := false
mpagenko01e726e2020-10-23 09:45:29 +0000473 flowCookieModify := false
mpagenkof1fc3862021-02-16 10:09:52 +0000474 requestAppendRule := false
Andrea Campanellaf66ac6e2021-05-24 17:09:20 +0200475 oFsm.lastFlowToReconcile = lastFlowToReconcile
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000476 //mutex protection is required for possible concurrent access to FSM members
477 oFsm.mutexFlowParams.Lock()
mpagenko01e726e2020-10-23 09:45:29 +0000478 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
479 //TODO: Verify if using e.g. hashes for the structures here for comparison may generate
480 // countable run time optimization (perhaps with including the hash in kvStore storage?)
481 if storedUniFlowParams.VlanRuleParams == loRuleParams {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000482 flowEntryMatch = true
dbainbri4d3a0dc2020-12-02 00:33:42 +0000483 logger.Debugw(ctx, "UniVlanConfigFsm flow setting - rule already exists", log.Fields{
ozgecanetsia82b91a62021-05-21 18:54:49 +0300484 "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16),
485 "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
486 "SetPcp": loRuleParams.SetPcp,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000487 "device-id": oFsm.deviceID, " uni-id": oFsm.pOnuUniPort.UniID})
mpagenko01e726e2020-10-23 09:45:29 +0000488 var cookieMatch bool
489 for _, newCookie := range aCookieSlice { // for all cookies available in the arguments
490 cookieMatch = false
491 for _, cookie := range storedUniFlowParams.CookieSlice {
492 if cookie == newCookie {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000493 logger.Debugw(ctx, "UniVlanConfigFsm flow setting - and cookie already exists", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000494 "device-id": oFsm.deviceID, "cookie": cookie})
495 cookieMatch = true
496 break //found new cookie - no further search for this requested cookie
497 }
498 }
499 if !cookieMatch {
mpagenkof1fc3862021-02-16 10:09:52 +0000500 delayedCookie := oFsm.delayNewRuleForCookie(ctx, aCookieSlice)
501 if delayedCookie != 0 {
502 //a delay for adding the cookie to this rule is requested
503 // take care of the mutex which is already locked here, need to unlock/lock accordingly to prevent deadlock in suspension
504 oFsm.mutexFlowParams.Unlock()
mpagenkobc4170a2021-08-17 16:42:10 +0000505 if deleteSuccess := oFsm.suspendNewRule(ctx); !deleteSuccess {
506 logger.Errorw(ctx, "UniVlanConfigFsm suspended add-cookie-to-rule aborted", log.Fields{
507 "device-id": oFsm.deviceID, "cookie": delayedCookie})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700508 err = fmt.Errorf(" UniVlanConfigFsm suspended add-cookie-to-rule aborted %s", oFsm.deviceID)
509 oFsm.PushReponseOnFlowResponseChannel(ctx, respChan, err)
510 return err
mpagenkobc4170a2021-08-17 16:42:10 +0000511 }
mpagenkobc4170a2021-08-17 16:42:10 +0000512 flowCookieModify, requestAppendRule = oFsm.reviseFlowConstellation(ctx, delayedCookie, loRuleParams)
mpagenkod6c05522021-08-23 15:59:06 +0000513 oFsm.mutexFlowParams.Lock()
mpagenkof1fc3862021-02-16 10:09:52 +0000514 } else {
515 logger.Debugw(ctx, "UniVlanConfigFsm flow setting -adding new cookie", log.Fields{
516 "device-id": oFsm.deviceID, "cookie": newCookie})
517 //as range works with copies of the slice we have to write to the original slice!!
518 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(oFsm.uniVlanFlowParamsSlice[flow].CookieSlice,
519 newCookie)
520 flowCookieModify = true
521 }
mpagenko01e726e2020-10-23 09:45:29 +0000522 }
523 } //for all new cookies
524 break // found rule - no further rule search
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000525 }
526 }
mpagenkof1fc3862021-02-16 10:09:52 +0000527 oFsm.mutexFlowParams.Unlock()
528
529 if !flowEntryMatch { //it is (was) a new rule
mpagenkobc4170a2021-08-17 16:42:10 +0000530 delayedCookie, deleteSuccess := oFsm.suspendIfRequiredNewRule(ctx, aCookieSlice)
531 if !deleteSuccess {
532 logger.Errorw(ctx, "UniVlanConfigFsm suspended add-new-rule aborted", log.Fields{
533 "device-id": oFsm.deviceID, "cookie": delayedCookie})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700534 err = fmt.Errorf(" UniVlanConfigFsm suspended add-new-rule aborted %s", oFsm.deviceID)
535 oFsm.PushReponseOnFlowResponseChannel(ctx, respChan, err)
536 return err
mpagenkobc4170a2021-08-17 16:42:10 +0000537 }
mpagenkof1fc3862021-02-16 10:09:52 +0000538 requestAppendRule = true //default assumption here is that rule is to be appended
539 flowCookieModify = true //and that the the flow data base is to be updated
540 if delayedCookie != 0 { //it was suspended
541 flowCookieModify, requestAppendRule = oFsm.reviseFlowConstellation(ctx, delayedCookie, loRuleParams)
542 }
543 }
544 kvStoreWrite := false //default setting is to not write to kvStore immediately - will be done on FSM execution finally
545 if requestAppendRule {
546 oFsm.mutexFlowParams.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000547 if oFsm.NumUniFlows < cMaxAllowedFlows {
Girish Gowdrae95687a2021-09-08 16:30:58 -0700548 loFlowParams := cmn.UniVlanFlowParams{VlanRuleParams: loRuleParams, RespChan: respChan}
mpagenko01e726e2020-10-23 09:45:29 +0000549 loFlowParams.CookieSlice = make([]uint64, 0)
550 loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...)
ozgecanetsia82b91a62021-05-21 18:54:49 +0300551 if aMeter != nil {
552 loFlowParams.Meter = aMeter
553 }
mpagenko01e726e2020-10-23 09:45:29 +0000554 oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000555 logger.Debugw(ctx, "UniVlanConfigFsm flow add", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000556 "Cookies": oFsm.uniVlanFlowParamsSlice[oFsm.NumUniFlows].CookieSlice,
mpagenko01e726e2020-10-23 09:45:29 +0000557 "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16),
558 "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000559 "SetPcp": loRuleParams.SetPcp, "numberofFlows": oFsm.NumUniFlows + 1,
560 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko01e726e2020-10-23 09:45:29 +0000561
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000562 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandt968eb8f2021-09-17 07:41:12 +0000563 oFsm.reconcileVlanFilterList(ctx, uint16(loRuleParams.SetVid))
564 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000565 oFsm.NumUniFlows++
566 pConfigVlanStateBaseFsm := oFsm.PAdaptFsm.PFsm
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000567
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000568 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000569 logger.Debugw(ctx, "reconciling - skip omci-config of additional vlan rule",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000570 log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID})
mpagenkobb47bc22021-04-20 13:29:09 +0000571 //attention: take care to release the mutexFlowParams when calling the FSM directly -
572 // synchronous FSM 'event/state' functions may rely on this mutex
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000573 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000574 if pConfigVlanStateBaseFsm.Is(VlanStConfigDone) {
575 if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvSkipOmciConfig); fsmErr != nil {
mpagenkobb47bc22021-04-20 13:29:09 +0000576 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000577 log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700578 err = fsmErr
579 oFsm.PushReponseOnFlowResponseChannel(ctx, respChan, err)
580 return err
mpagenkobb47bc22021-04-20 13:29:09 +0000581 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000582 }
583 return nil
584 }
mpagenko01e726e2020-10-23 09:45:29 +0000585 // note: theoretical it would be possible to clear the same rule from the remove slice
586 // (for entries that have not yet been started with removal)
587 // but that is getting quite complicated - maybe a future optimization in case it should prove reasonable
588 // anyway the precondition here is that the FSM checks for rules to delete first and adds new rules afterwards
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000589
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000590 if pConfigVlanStateBaseFsm.Is(VlanStConfigDone) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000591 //have to re-trigger the FSM to proceed with outstanding incremental flow configuration
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000592 if oFsm.ConfiguredUniFlow == 0 {
mpagenko551a4d42020-12-08 18:09:20 +0000593 // this is a restart with a complete new flow, we can re-use the initial flow config control
594 // including the check, if the related techProfile is (still) available (probably also removed in between)
mpagenkobb47bc22021-04-20 13:29:09 +0000595 //attention: take care to release the mutexFlowParams when calling the FSM directly -
596 // synchronous FSM 'event/state' functions may rely on this mutex
597 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000598 if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvRenew); fsmErr != nil {
mpagenkobb47bc22021-04-20 13:29:09 +0000599 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
600 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
601 }
mpagenko551a4d42020-12-08 18:09:20 +0000602 } else {
603 //some further flows are to be configured
mpagenko9a304ea2020-12-16 15:54:01 +0000604 //store the actual rule that shall be worked upon in the following transient states
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000605 if len(oFsm.uniVlanFlowParamsSlice) < int(oFsm.ConfiguredUniFlow) {
mpagenkof1d21d12021-06-11 13:14:45 +0000606 //check introduced after having observed some panic here
607 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm - inconsistent counter",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000608 log.Fields{"ConfiguredUniFlow": oFsm.ConfiguredUniFlow,
mpagenkof1d21d12021-06-11 13:14:45 +0000609 "sliceLen": len(oFsm.uniVlanFlowParamsSlice), "device-id": oFsm.deviceID})
610 oFsm.mutexFlowParams.Unlock()
Girish Gowdrae95687a2021-09-08 16:30:58 -0700611 err = fmt.Errorf("abort UniVlanConfigFsm on add due to internal counter mismatch %s", oFsm.deviceID)
612 oFsm.PushReponseOnFlowResponseChannel(ctx, respChan, err)
613 return err
mpagenkof1d21d12021-06-11 13:14:45 +0000614 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700615
616 oFsm.actualUniFlowParam = oFsm.uniVlanFlowParamsSlice[oFsm.ConfiguredUniFlow]
mpagenko551a4d42020-12-08 18:09:20 +0000617 //tpId of the next rule to be configured
Girish Gowdrae95687a2021-09-08 16:30:58 -0700618 tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID
mpagenko551a4d42020-12-08 18:09:20 +0000619 oFsm.TpIDWaitingFor = tpID
Girish Gowdrae95687a2021-09-08 16:30:58 -0700620 loSetVlan := oFsm.actualUniFlowParam.VlanRuleParams.SetVid
mpagenkobb47bc22021-04-20 13:29:09 +0000621 //attention: take care to release the mutexFlowParams when calling the FSM directly -
622 // synchronous FSM 'event/state' functions may rely on this mutex
mpagenko45cc6a32021-07-23 10:06:57 +0000623 // but it must be released already before calling getTechProfileDone() as it may already be locked
624 // by the techProfile processing call to VlanFsm.IsFlowRemovePending() (see VOL-4207)
mpagenkobb47bc22021-04-20 13:29:09 +0000625 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000626 loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.UniID, tpID)
mpagenko45cc6a32021-07-23 10:06:57 +0000627 logger.Debugw(ctx, "UniVlanConfigFsm - incremental config request (on setConfig)", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000628 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko45cc6a32021-07-23 10:06:57 +0000629 "set-Vlan": loSetVlan, "tp-id": tpID, "ProfDone": loTechProfDone})
630
mpagenkobb47bc22021-04-20 13:29:09 +0000631 var fsmErr error
632 if loTechProfDone {
633 // let the vlan processing continue with next rule
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000634 fsmErr = pConfigVlanStateBaseFsm.Event(VlanEvIncrFlowConfig)
mpagenkobb47bc22021-04-20 13:29:09 +0000635 } else {
636 // set to waiting for Techprofile
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000637 fsmErr = pConfigVlanStateBaseFsm.Event(VlanEvWaitTPIncr)
mpagenkobb47bc22021-04-20 13:29:09 +0000638 }
639 if fsmErr != nil {
640 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
641 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700642 oFsm.PushReponseOnFlowResponseChannel(ctx, respChan, fsmErr)
643 return fsmErr
mpagenkobb47bc22021-04-20 13:29:09 +0000644 }
mpagenko551a4d42020-12-08 18:09:20 +0000645 }
mpagenkobb47bc22021-04-20 13:29:09 +0000646 } else {
647 // if not in the appropriate state a new entry will be automatically considered later
648 // when the configDone state is reached
649 oFsm.mutexFlowParams.Unlock()
650 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000651 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000652 logger.Errorw(ctx, "UniVlanConfigFsm flow limit exceeded", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000653 "device-id": oFsm.deviceID, "flow-number": oFsm.NumUniFlows})
mpagenko15ff4a52021-03-02 10:09:20 +0000654 oFsm.mutexFlowParams.Unlock()
Girish Gowdrae95687a2021-09-08 16:30:58 -0700655 err = fmt.Errorf(" UniVlanConfigFsm flow limit exceeded %s", oFsm.deviceID)
656 oFsm.PushReponseOnFlowResponseChannel(ctx, respChan, err)
657 return err
mpagenko01e726e2020-10-23 09:45:29 +0000658 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000659 } else {
660 // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately
mpagenkof1fc3862021-02-16 10:09:52 +0000661 kvStoreWrite = true // ensure actual data write to kvStore immediately (no FSM activity)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700662 // push response on response channel as there is nothing to be done for this flow
663 oFsm.PushReponseOnFlowResponseChannel(ctx, respChan, nil)
664
mpagenko15ff4a52021-03-02 10:09:20 +0000665 oFsm.mutexFlowParams.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000666 if oFsm.NumUniFlows == oFsm.ConfiguredUniFlow {
mpagenkofc4f56e2020-11-04 17:17:49 +0000667 //all requested rules really have been configured
668 // state transition notification is checked in deviceHandler
mpagenko15ff4a52021-03-02 10:09:20 +0000669 oFsm.mutexFlowParams.RUnlock()
mpagenkofc4f56e2020-11-04 17:17:49 +0000670 if oFsm.pDeviceHandler != nil {
671 //also the related TechProfile was already configured
dbainbri4d3a0dc2020-12-02 00:33:42 +0000672 logger.Debugw(ctx, "UniVlanConfigFsm rule already set - send immediate add-success event for reason update", log.Fields{
mpagenkofc4f56e2020-11-04 17:17:49 +0000673 "device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000674 // success indication without the need to write to kvStore (done already below with updated data from StorePersUniFlowConfig())
675 go oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetAddNoKvStore))
mpagenkofc4f56e2020-11-04 17:17:49 +0000676 }
677 } else {
678 // avoid device reason update as the rule config connected to this flow may still be in progress
679 // and the device reason should only be updated on success of rule config
dbainbri4d3a0dc2020-12-02 00:33:42 +0000680 logger.Debugw(ctx, "UniVlanConfigFsm rule already set but configuration ongoing, suppress early add-success event for reason update",
mpagenkofc4f56e2020-11-04 17:17:49 +0000681 log.Fields{"device-id": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000682 "NumberofRules": oFsm.NumUniFlows, "Configured rules": oFsm.ConfiguredUniFlow})
mpagenko15ff4a52021-03-02 10:09:20 +0000683 oFsm.mutexFlowParams.RUnlock()
mpagenkofc4f56e2020-11-04 17:17:49 +0000684 }
685 }
mpagenko01e726e2020-10-23 09:45:29 +0000686
mpagenkof1fc3862021-02-16 10:09:52 +0000687 if flowCookieModify { // some change was done to the flow entries
mpagenko01e726e2020-10-23 09:45:29 +0000688 //permanently store flow config for reconcile case
mpagenko15ff4a52021-03-02 10:09:20 +0000689 oFsm.mutexFlowParams.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000690 if err := oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID,
mpagenkof1fc3862021-02-16 10:09:52 +0000691 &oFsm.uniVlanFlowParamsSlice, kvStoreWrite); err != nil {
mpagenko15ff4a52021-03-02 10:09:20 +0000692 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000693 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +0000694 return err
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000695 }
mpagenko15ff4a52021-03-02 10:09:20 +0000696 oFsm.mutexFlowParams.RUnlock()
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000697 }
698 return nil
699}
700
mpagenkof1d21d12021-06-11 13:14:45 +0000701func (oFsm *UniVlanConfigFsm) suspendAddRule(ctx context.Context, apRemoveFlowParams *uniRemoveVlanFlowParams) error {
702 oFsm.mutexFlowParams.Lock()
703 deleteChannel := apRemoveFlowParams.removeChannel
704 apRemoveFlowParams.isSuspendedOnAdd = true
705 oFsm.mutexFlowParams.Unlock()
706
707 // isSuspendedOnAdd is not reset here-after as the assumption is, that after
708 select {
709 case success := <-deleteChannel:
710 //no need to reset isSuspendedOnAdd as in this case the removeElement will be deleted completely
711 if success {
712 logger.Infow(ctx, "resume adding this rule after having completed deletion", log.Fields{
713 "device-id": oFsm.deviceID})
714 return nil
715 }
716 return fmt.Errorf("suspend aborted, also aborting add-activity: %s", oFsm.deviceID)
717 case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second):
718 oFsm.mutexFlowParams.Lock()
719 if apRemoveFlowParams != nil {
720 apRemoveFlowParams.isSuspendedOnAdd = false
721 }
722 oFsm.mutexFlowParams.Unlock()
mpagenkof582d6a2021-06-18 15:58:10 +0000723 logger.Errorw(ctx, "timeout waiting for deletion of rule, also aborting add-activity", log.Fields{
mpagenkof1d21d12021-06-11 13:14:45 +0000724 "device-id": oFsm.deviceID})
mpagenkof582d6a2021-06-18 15:58:10 +0000725 return fmt.Errorf("suspend aborted on timeout, also aborting add-activity: %s", oFsm.deviceID)
mpagenkof1d21d12021-06-11 13:14:45 +0000726 }
mpagenkof1d21d12021-06-11 13:14:45 +0000727}
728
mpagenkof1fc3862021-02-16 10:09:52 +0000729// VOL-3828 flow config sequence workaround ########### start ##########
730func (oFsm *UniVlanConfigFsm) delayNewRuleForCookie(ctx context.Context, aCookieSlice []uint64) uint64 {
731 //assumes mutexFlowParams.Lock() protection from caller!
732 if oFsm.delayNewRuleCookie == 0 && len(aCookieSlice) == 1 {
733 // if not already waiting, limitation for this workaround is to just have one overlapping cookie/rule
mpagenkof1d21d12021-06-11 13:14:45 +0000734 // suspend check is done only if there is only one cookie in the request
mpagenkof1fc3862021-02-16 10:09:52 +0000735 // background: more elements only expected in reconcile use case, where no conflicting sequence is to be expected
736 newCookie := aCookieSlice[0]
737 for _, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
738 for _, cookie := range storedUniFlowParams.CookieSlice {
739 if cookie == newCookie {
740 logger.Debugw(ctx, "UniVlanConfigFsm flow setting - new cookie still exists for some rule", log.Fields{
741 "device-id": oFsm.deviceID, "cookie": cookie, "exists with SetVlan": storedUniFlowParams.VlanRuleParams.SetVid})
742 oFsm.delayNewRuleCookie = newCookie
743 return newCookie //found new cookie in some existing rule
744 }
745 } // for all stored cookies of the actual inspected rule
746 } //for all rules
747 }
748 return 0 //no delay requested
749}
mpagenkobc4170a2021-08-17 16:42:10 +0000750func (oFsm *UniVlanConfigFsm) suspendNewRule(ctx context.Context) bool {
mpagenkof1fc3862021-02-16 10:09:52 +0000751 oFsm.mutexFlowParams.RLock()
752 logger.Infow(ctx, "Need to suspend adding this rule as long as the cookie is still connected to some other rule", log.Fields{
753 "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie})
754 oFsm.mutexFlowParams.RUnlock()
mpagenkobc4170a2021-08-17 16:42:10 +0000755 cookieDeleted := true //default assumption also for timeout (just try to continue as if removed)
mpagenkof1fc3862021-02-16 10:09:52 +0000756 select {
mpagenkobc4170a2021-08-17 16:42:10 +0000757 case cookieDeleted = <-oFsm.chCookieDeleted:
758 logger.Infow(ctx, "resume adding this rule after having deleted cookie in some other rule or abort", log.Fields{
759 "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie, "deleted": cookieDeleted})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000760 case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second):
mpagenkof1fc3862021-02-16 10:09:52 +0000761 logger.Errorw(ctx, "timeout waiting for deletion of cookie in some other rule, just try to continue", log.Fields{
762 "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie})
763 }
764 oFsm.mutexFlowParams.Lock()
765 oFsm.delayNewRuleCookie = 0
766 oFsm.mutexFlowParams.Unlock()
mpagenkobc4170a2021-08-17 16:42:10 +0000767 return cookieDeleted
mpagenkof1fc3862021-02-16 10:09:52 +0000768}
mpagenkobc4170a2021-08-17 16:42:10 +0000769func (oFsm *UniVlanConfigFsm) suspendIfRequiredNewRule(ctx context.Context, aCookieSlice []uint64) (uint64, bool) {
mpagenkof1fc3862021-02-16 10:09:52 +0000770 oFsm.mutexFlowParams.Lock()
771 delayedCookie := oFsm.delayNewRuleForCookie(ctx, aCookieSlice)
772 oFsm.mutexFlowParams.Unlock()
773
mpagenkobc4170a2021-08-17 16:42:10 +0000774 deleteSuccess := true
mpagenkof1fc3862021-02-16 10:09:52 +0000775 if delayedCookie != 0 {
mpagenkobc4170a2021-08-17 16:42:10 +0000776 deleteSuccess = oFsm.suspendNewRule(ctx)
mpagenkof1fc3862021-02-16 10:09:52 +0000777 }
mpagenkobc4170a2021-08-17 16:42:10 +0000778 return delayedCookie, deleteSuccess
mpagenkof1fc3862021-02-16 10:09:52 +0000779}
780
781//returns flowModified, RuleAppendRequest
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000782func (oFsm *UniVlanConfigFsm) reviseFlowConstellation(ctx context.Context, aCookie uint64, aUniVlanRuleParams cmn.UniVlanRuleParams) (bool, bool) {
mpagenkof1fc3862021-02-16 10:09:52 +0000783 flowEntryMatch := false
784 oFsm.mutexFlowParams.Lock()
785 defer oFsm.mutexFlowParams.Unlock()
786 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
787 if storedUniFlowParams.VlanRuleParams == aUniVlanRuleParams {
788 flowEntryMatch = true
789 logger.Debugw(ctx, "UniVlanConfigFsm flow revise - rule already exists", log.Fields{
790 "device-id": oFsm.deviceID})
791 cookieMatch := false
792 for _, cookie := range storedUniFlowParams.CookieSlice {
793 if cookie == aCookie {
794 logger.Debugw(ctx, "UniVlanConfigFsm flow revise - and cookie already exists", log.Fields{
795 "device-id": oFsm.deviceID, "cookie": cookie})
796 cookieMatch = true
797 break //found new cookie - no further search for this requested cookie
798 }
799 }
800 if !cookieMatch {
801 logger.Debugw(ctx, "UniVlanConfigFsm flow revise -adding new cookie", log.Fields{
802 "device-id": oFsm.deviceID, "cookie": aCookie})
803 //as range works with copies of the slice we have to write to the original slice!!
804 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(oFsm.uniVlanFlowParamsSlice[flow].CookieSlice,
805 aCookie)
806 return true, false //flowModified, NoRuleAppend
807 }
808 break // found rule - no further rule search
809 }
810 }
811 if !flowEntryMatch { //it is a new rule
812 return true, true //flowModified, RuleAppend
813 }
814 return false, false //flowNotModified, NoRuleAppend
815}
816
817// VOL-3828 flow config sequence workaround ########### end ##########
818
mpagenko01e726e2020-10-23 09:45:29 +0000819//RemoveUniFlowParams verifies on existence of flow cookie,
820// if found removes cookie from flow cookie list and if this is empty
821// initiates removal of the flow related configuration from the ONU (via OMCI)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700822func (oFsm *UniVlanConfigFsm) RemoveUniFlowParams(ctx context.Context, aCookie uint64, respChan *chan error) error {
mpagenkof1fc3862021-02-16 10:09:52 +0000823 var deletedCookie uint64
mpagenko01e726e2020-10-23 09:45:29 +0000824 flowCookieMatch := false
825 //mutex protection is required for possible concurrent access to FSM members
826 oFsm.mutexFlowParams.Lock()
827 defer oFsm.mutexFlowParams.Unlock()
mpagenkof1fc3862021-02-16 10:09:52 +0000828remove_loop:
mpagenko01e726e2020-10-23 09:45:29 +0000829 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
830 for i, cookie := range storedUniFlowParams.CookieSlice {
831 if cookie == aCookie {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000832 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - cookie found", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000833 "device-id": oFsm.deviceID, "cookie": cookie})
mpagenkof1fc3862021-02-16 10:09:52 +0000834 deletedCookie = aCookie
mpagenko01e726e2020-10-23 09:45:29 +0000835 //remove the cookie from the cookie slice and verify it is getting empty
836 if len(storedUniFlowParams.CookieSlice) == 1 {
mpagenkof582d6a2021-06-18 15:58:10 +0000837 // had to shift content to function due to sca complexity
Girish Gowdrae95687a2021-09-08 16:30:58 -0700838 flowCookieMatch = oFsm.removeRuleComplete(ctx, storedUniFlowParams, aCookie, respChan)
mpagenkodee02a62021-07-21 10:56:10 +0000839 //persistencyData write is now part of removeRuleComplete() (on success)
mpagenko01e726e2020-10-23 09:45:29 +0000840 } else {
mpagenkof582d6a2021-06-18 15:58:10 +0000841 flowCookieMatch = true
mpagenko01e726e2020-10-23 09:45:29 +0000842 //cut off the requested cookie by slicing out this element
843 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(
844 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[:i],
845 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[i+1:]...)
mpagenkofc4f56e2020-11-04 17:17:49 +0000846 // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately
847 // state transition notification is checked in deviceHandler
848 if oFsm.pDeviceHandler != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000849 // success indication without the need to write to kvStore (done already below with updated data from StorePersUniFlowConfig())
850 go oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetRemoveNoKvStore))
mpagenkofc4f56e2020-11-04 17:17:49 +0000851 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000852 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - rule persists with still valid cookies", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000853 "device-id": oFsm.deviceID, "cookies": oFsm.uniVlanFlowParamsSlice[flow].CookieSlice})
mpagenkof1fc3862021-02-16 10:09:52 +0000854 if deletedCookie == oFsm.delayNewRuleCookie {
855 //the delayedNewCookie is the one that is currently deleted, but the rule still exist with other cookies
856 //as long as there are further cookies for this rule indicate there is still some cookie to be deleted
857 //simply use the first one
858 oFsm.delayNewRuleCookie = oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[0]
859 logger.Debugw(ctx, "UniVlanConfigFsm remaining cookie awaited for deletion before new rule add", log.Fields{
860 "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie})
861 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700862 // Push response on the response channel
863 oFsm.PushReponseOnFlowResponseChannel(ctx, respChan, nil)
mpagenkodee02a62021-07-21 10:56:10 +0000864 //permanently store the modified flow config for reconcile case and immediately write to KvStore
865 if oFsm.pDeviceHandler != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000866 if err := oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID,
mpagenkodee02a62021-07-21 10:56:10 +0000867 &oFsm.uniVlanFlowParamsSlice, true); err != nil {
868 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
869 return err
870 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000871 }
mpagenko01e726e2020-10-23 09:45:29 +0000872 }
mpagenkof1fc3862021-02-16 10:09:52 +0000873 break remove_loop //found the cookie - no further search for this requested cookie
mpagenko01e726e2020-10-23 09:45:29 +0000874 }
875 }
mpagenko01e726e2020-10-23 09:45:29 +0000876 } //search all flows
877 if !flowCookieMatch { //some cookie remove-request for a cookie that does not exist in the FSM data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000878 logger.Warnw(ctx, "UniVlanConfigFsm flow removal - remove-cookie not found", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000879 "device-id": oFsm.deviceID, "remove-cookie": aCookie})
880 // but accept the request with success as no such cookie (flow) does exist
mpagenkofc4f56e2020-11-04 17:17:49 +0000881 // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately
882 // state transition notification is checked in deviceHandler
883 if oFsm.pDeviceHandler != nil {
mpagenkof1fc3862021-02-16 10:09:52 +0000884 // success indication without the need to write to kvStore (no change)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000885 go oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetRemoveNoKvStore))
mpagenkofc4f56e2020-11-04 17:17:49 +0000886 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700887 // Push response on the response channel
888 oFsm.PushReponseOnFlowResponseChannel(ctx, respChan, nil)
mpagenko01e726e2020-10-23 09:45:29 +0000889 return nil
890 } //unknown cookie
891
892 return nil
893}
894
mpagenkof582d6a2021-06-18 15:58:10 +0000895// removeRuleComplete initiates the complete removal of a VLAN rule (from single cookie element)
mpagenkodee02a62021-07-21 10:56:10 +0000896// requires mutexFlowParams to be locked at call
mpagenkof582d6a2021-06-18 15:58:10 +0000897func (oFsm *UniVlanConfigFsm) removeRuleComplete(ctx context.Context,
Girish Gowdrae95687a2021-09-08 16:30:58 -0700898 aUniFlowParams cmn.UniVlanFlowParams, aCookie uint64, respChan *chan error) bool {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000899 pConfigVlanStateBaseFsm := oFsm.PAdaptFsm.PFsm
mpagenkof582d6a2021-06-18 15:58:10 +0000900 var cancelPendingConfig bool = false
901 var loRemoveParams uniRemoveVlanFlowParams = uniRemoveVlanFlowParams{}
902 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - full flow removal", log.Fields{
903 "device-id": oFsm.deviceID})
904 //rwCore flow recovery may be the reason for this delete, in which case the flowToBeDeleted may be the same
905 // as the one still waiting in the FSM as toAdd but waiting for TechProfileConfig
906 // so we have to check if we have to abort the outstanding AddRequest and regard the current DelRequest as done
907 // if the Fsm is in some other transient (config) state, we will reach the DelRequest later and correctly process it then
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000908 if pConfigVlanStateBaseFsm.Is(VlanStWaitingTechProf) {
mpagenkof582d6a2021-06-18 15:58:10 +0000909 logger.Debugw(ctx, "UniVlanConfigFsm was waiting for TechProf config with add-request, just aborting the outstanding add",
910 log.Fields{"device-id": oFsm.deviceID})
911 cancelPendingConfig = true
912 } else {
913 //create a new element for the removeVlanFlow slice
914 loRemoveParams = uniRemoveVlanFlowParams{
915 vlanRuleParams: aUniFlowParams.VlanRuleParams,
916 cookie: aCookie,
Girish Gowdrae95687a2021-09-08 16:30:58 -0700917 respChan: respChan,
mpagenkof582d6a2021-06-18 15:58:10 +0000918 }
919 loRemoveParams.removeChannel = make(chan bool)
920 oFsm.uniRemoveFlowsSlice = append(oFsm.uniRemoveFlowsSlice, loRemoveParams)
921 }
922
923 usedTpID := aUniFlowParams.VlanRuleParams.TpID
924 if len(oFsm.uniVlanFlowParamsSlice) <= 1 {
925 //at this point it is evident that no flow anymore will refer to a still possibly active Techprofile
926 //request that this profile gets deleted before a new flow add is allowed (except for some aborted add)
927 if !cancelPendingConfig {
mpagenko3ce9fa02021-07-28 13:26:54 +0000928 // ensure mutexFlowParams not locked before calling some TPProcessing activity (that might already be pending on it)
929 oFsm.mutexFlowParams.Unlock()
mpagenkof582d6a2021-06-18 15:58:10 +0000930 logger.Debugw(ctx, "UniVlanConfigFsm flow removal requested - set TechProfile to-delete", log.Fields{
931 "device-id": oFsm.deviceID})
932 if oFsm.pUniTechProf != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000933 oFsm.pUniTechProf.SetProfileToDelete(oFsm.pOnuUniPort.UniID, usedTpID, true)
mpagenkof582d6a2021-06-18 15:58:10 +0000934 }
mpagenko3ce9fa02021-07-28 13:26:54 +0000935 oFsm.mutexFlowParams.Lock()
mpagenkof582d6a2021-06-18 15:58:10 +0000936 }
937 } else {
938 if !cancelPendingConfig {
939 oFsm.updateTechProfileToDelete(ctx, usedTpID)
940 }
941 }
942 //trigger the FSM to remove the relevant rule
943 if cancelPendingConfig {
944 //as the uniFlow parameters are already stored (for add) but no explicit removal is done anymore
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000945 // the paramSlice has to be updated with rule-removal, which also then updates NumUniFlows
mpagenkof582d6a2021-06-18 15:58:10 +0000946 //call from 'non-configured' state of the rules
947 if err := oFsm.removeFlowFromParamsSlice(ctx, aCookie, false); err != nil {
948 //something quite inconsistent detected, perhaps just try to recover with FSM reset
949 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000950 if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvReset); fsmErr != nil {
mpagenkof582d6a2021-06-18 15:58:10 +0000951 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
952 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
953 }
954 return false //data base update could not be done, return like cookie not found
955 }
956
957 oFsm.requestEventOffset = uint8(cDeviceEventOffsetRemoveWithKvStore) //offset for last flow-remove activity (with kvStore request)
958 //attention: take care to release and re-take the mutexFlowParams when calling the FSM directly -
959 // synchronous FSM 'event/state' functions may rely on this mutex
960 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000961 if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvCancelOutstandingConfig); fsmErr != nil {
mpagenkof582d6a2021-06-18 15:58:10 +0000962 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
963 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
964 }
965 oFsm.mutexFlowParams.Lock()
966 return true
967 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000968 if pConfigVlanStateBaseFsm.Is(VlanStConfigDone) {
mpagenkof582d6a2021-06-18 15:58:10 +0000969 logger.Debugw(ctx, "UniVlanConfigFsm rule removal request", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000970 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenkof582d6a2021-06-18 15:58:10 +0000971 "tp-id": loRemoveParams.vlanRuleParams.TpID,
972 "set-Vlan": loRemoveParams.vlanRuleParams.SetVid})
973 //have to re-trigger the FSM to proceed with outstanding incremental flow configuration
974 //attention: take care to release and re-take the mutexFlowParams when calling the FSM directly -
975 // synchronous FSM 'event/state' functions may rely on this mutex
976 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000977 if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvRemFlowConfig); fsmErr != nil {
mpagenkof582d6a2021-06-18 15:58:10 +0000978 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
979 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
980 }
981 oFsm.mutexFlowParams.Lock()
982 } // if not in the appropriate state a new entry will be automatically considered later
983 // when the configDone state is reached
984 return true
985}
986
mpagenkof1d21d12021-06-11 13:14:45 +0000987//removeFlowFromParamsSlice removes a flow from stored uniVlanFlowParamsSlice based on the cookie
988// it assumes that adding cookies for this flow (including the actual one to delete) was prevented
989// from the start of the deletion request to avoid to much interference
990// so when called, there can only be one cookie active for this flow
991// requires mutexFlowParams to be locked at call
mpagenkof582d6a2021-06-18 15:58:10 +0000992func (oFsm *UniVlanConfigFsm) removeFlowFromParamsSlice(ctx context.Context, aCookie uint64, aWasConfigured bool) error {
mpagenkof1d21d12021-06-11 13:14:45 +0000993 logger.Debugw(ctx, "UniVlanConfigFsm flow removal from ParamsSlice", log.Fields{
994 "device-id": oFsm.deviceID, "cookie": aCookie})
mpagenkof582d6a2021-06-18 15:58:10 +0000995 cookieFound := false
mpagenkof1d21d12021-06-11 13:14:45 +0000996removeFromSlice_loop:
997 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
mpagenkof582d6a2021-06-18 15:58:10 +0000998 // if UniFlowParams exists, cookieSlice should always have at least one element
999 cookieSliceLen := len(storedUniFlowParams.CookieSlice)
1000 if cookieSliceLen == 1 {
1001 if storedUniFlowParams.CookieSlice[0] == aCookie {
1002 cookieFound = true
mpagenkof1d21d12021-06-11 13:14:45 +00001003 }
mpagenkof582d6a2021-06-18 15:58:10 +00001004 } else if cookieSliceLen == 0 {
1005 errStr := "UniVlanConfigFsm unexpected cookie slice length 0 - removal in uniVlanFlowParamsSlice aborted"
1006 logger.Errorw(ctx, errStr, log.Fields{"device-id": oFsm.deviceID})
1007 return errors.New(errStr)
1008 } else {
1009 errStr := "UniVlanConfigFsm flow removal unexpected cookie slice length, but rule removal continued"
1010 logger.Errorw(ctx, errStr, log.Fields{
1011 "cookieSliceLen": len(oFsm.uniVlanFlowParamsSlice), "device-id": oFsm.deviceID})
1012 for _, cookie := range storedUniFlowParams.CookieSlice {
1013 if cookie == aCookie {
1014 cookieFound = true
1015 break
1016 }
1017 }
1018 }
1019 if cookieFound {
mpagenkof1d21d12021-06-11 13:14:45 +00001020 logger.Debugw(ctx, "UniVlanConfigFsm flow removal from ParamsSlice - cookie found", log.Fields{
1021 "device-id": oFsm.deviceID, "cookie": aCookie})
1022 //remove the actual element from the addVlanFlow slice
1023 // oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = nil //automatically done by garbage collector
1024 if len(oFsm.uniVlanFlowParamsSlice) <= 1 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001025 oFsm.NumUniFlows = 0 //no more flows
1026 oFsm.ConfiguredUniFlow = 0 //no more flows configured
mpagenkof1d21d12021-06-11 13:14:45 +00001027 oFsm.uniVlanFlowParamsSlice = nil //reset the slice
1028 //at this point it is evident that no flow anymore refers to a still possibly active Techprofile
1029 //request that this profile gets deleted before a new flow add is allowed
1030 logger.Debugw(ctx, "UniVlanConfigFsm flow removal from ParamsSlice - no more flows", log.Fields{
1031 "device-id": oFsm.deviceID})
1032 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001033 oFsm.NumUniFlows--
1034 if aWasConfigured && oFsm.ConfiguredUniFlow > 0 {
1035 oFsm.ConfiguredUniFlow--
mpagenkof1d21d12021-06-11 13:14:45 +00001036 }
Girish Gowdrae95687a2021-09-08 16:30:58 -07001037 if !aWasConfigured {
1038 // We did not actually process this flow but was removed before that.
1039 // Indicate success response for the flow to caller who is blocking on a response
1040 oFsm.PushReponseOnFlowResponseChannel(ctx, storedUniFlowParams.RespChan, nil)
1041 }
1042
mpagenkof1d21d12021-06-11 13:14:45 +00001043 //cut off the requested flow by slicing out this element
1044 oFsm.uniVlanFlowParamsSlice = append(
1045 oFsm.uniVlanFlowParamsSlice[:flow], oFsm.uniVlanFlowParamsSlice[flow+1:]...)
1046 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - specific flow removed from data", log.Fields{
1047 "device-id": oFsm.deviceID})
1048 }
1049 break removeFromSlice_loop //found the cookie - no further search for this requested cookie
1050 }
1051 } //search all flows
mpagenkof582d6a2021-06-18 15:58:10 +00001052 if !cookieFound {
1053 errStr := "UniVlanConfigFsm cookie for removal not found, internal counter not updated"
1054 logger.Errorw(ctx, errStr, log.Fields{"device-id": oFsm.deviceID})
1055 return errors.New(errStr)
1056 }
mpagenkodee02a62021-07-21 10:56:10 +00001057 //if the cookie was found and removed from uniVlanFlowParamsSlice above now write the modified persistency data
1058 // KVStore update will be done after reaching the requested FSM end state (not immediately here)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001059 if err := oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID,
mpagenkodee02a62021-07-21 10:56:10 +00001060 &oFsm.uniVlanFlowParamsSlice, false); err != nil {
1061 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
1062 return err
1063 }
mpagenkof582d6a2021-06-18 15:58:10 +00001064 return nil
mpagenkof1d21d12021-06-11 13:14:45 +00001065}
1066
1067// requires mutexFlowParams to be locked at call
mpagenkof1fc3862021-02-16 10:09:52 +00001068func (oFsm *UniVlanConfigFsm) updateTechProfileToDelete(ctx context.Context, usedTpID uint8) {
1069 //here we have to check, if there are still other flows referencing to the actual ProfileId
1070 // before we can request that this profile gets deleted before a new flow add is allowed
1071 tpIDInOtherFlows := false
1072 for _, tpUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
1073 if tpUniFlowParams.VlanRuleParams.TpID == usedTpID {
1074 tpIDInOtherFlows = true
1075 break // search loop can be left
1076 }
1077 }
1078 if tpIDInOtherFlows {
1079 logger.Debugw(ctx, "UniVlanConfigFsm tp-id used in deleted flow is still used in other flows", log.Fields{
1080 "device-id": oFsm.deviceID, "tp-id": usedTpID})
1081 } else {
mpagenkof1d21d12021-06-11 13:14:45 +00001082 logger.Debugw(ctx, "UniVlanConfigFsm tp-id used in deleted flow is not used anymore - set TechProfile to-delete", log.Fields{
mpagenkof1fc3862021-02-16 10:09:52 +00001083 "device-id": oFsm.deviceID, "tp-id": usedTpID})
mpagenko3ce9fa02021-07-28 13:26:54 +00001084 // ensure mutexFlowParams not locked before calling some TPProcessing activity (that might already be pending on it)
1085 oFsm.mutexFlowParams.Unlock()
mpagenkof1d21d12021-06-11 13:14:45 +00001086 if oFsm.pUniTechProf != nil {
1087 //request that this profile gets deleted before a new flow add is allowed
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001088 oFsm.pUniTechProf.SetProfileToDelete(oFsm.pOnuUniPort.UniID, usedTpID, true)
mpagenkof1d21d12021-06-11 13:14:45 +00001089 }
mpagenko3ce9fa02021-07-28 13:26:54 +00001090 oFsm.mutexFlowParams.Lock()
mpagenkof1fc3862021-02-16 10:09:52 +00001091 }
1092}
1093
mpagenkof1d21d12021-06-11 13:14:45 +00001094func (oFsm *UniVlanConfigFsm) enterPreparing(ctx context.Context, e *fsm.Event) {
1095 logger.Debugw(ctx, "UniVlanConfigFsm preparing", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001096
1097 // this FSM is not intended for re-start, needs always new creation for a new run
mpagenko01e726e2020-10-23 09:45:29 +00001098 // (self-destroying - compare enterDisabled())
mpagenkodff5dda2020-08-28 11:52:01 +00001099 oFsm.omciMIdsResponseReceived = make(chan bool)
mpagenkof1fc3862021-02-16 10:09:52 +00001100 oFsm.chCookieDeleted = make(chan bool)
mpagenkodff5dda2020-08-28 11:52:01 +00001101 // start go routine for processing of LockState messages
dbainbri4d3a0dc2020-12-02 00:33:42 +00001102 go oFsm.processOmciVlanMessages(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00001103 //let the state machine run forward from here directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001104 pConfigVlanStateAFsm := oFsm.PAdaptFsm
mpagenkodff5dda2020-08-28 11:52:01 +00001105 if pConfigVlanStateAFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001106 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001107 logger.Debugw(ctx, "reconciling - skip omci-config of vlan rule",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001108 log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID})
mpagenkof1d21d12021-06-11 13:14:45 +00001109 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001110 go func(a_pAFsm *cmn.AdapterFsm) {
1111 _ = a_pAFsm.PFsm.Event(VlanEvSkipOmciConfig)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001112 }(pConfigVlanStateAFsm)
1113 return
1114 }
mpagenkof1d21d12021-06-11 13:14:45 +00001115 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001116 go func(a_pAFsm *cmn.AdapterFsm) {
1117 _ = a_pAFsm.PFsm.Event(VlanEvPrepareDone)
mpagenkof1d21d12021-06-11 13:14:45 +00001118 }(pConfigVlanStateAFsm)
1119 return
1120 }
1121 logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{
1122 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
1123 //should never happen, else: recovery would be needed from outside the FSM
1124}
1125
1126func (oFsm *UniVlanConfigFsm) enterConfigStarting(ctx context.Context, e *fsm.Event) {
1127 logger.Debugw(ctx, "UniVlanConfigFsm start vlan configuration", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001128 pConfigVlanStateAFsm := oFsm.PAdaptFsm
mpagenkof1d21d12021-06-11 13:14:45 +00001129 if pConfigVlanStateAFsm != nil {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001130 oFsm.mutexFlowParams.Lock()
mpagenko9a304ea2020-12-16 15:54:01 +00001131 //possibly the entry is not valid anymore based on intermediate delete requests
1132 //just a basic protection ...
1133 if len(oFsm.uniVlanFlowParamsSlice) == 0 {
1134 oFsm.mutexFlowParams.Unlock()
1135 logger.Debugw(ctx, "UniVlanConfigFsm start: no rule entry anymore available", log.Fields{
1136 "device-id": oFsm.deviceID})
1137 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001138 go func(a_pAFsm *cmn.AdapterFsm) {
1139 _ = a_pAFsm.PFsm.Event(VlanEvReset)
mpagenko9a304ea2020-12-16 15:54:01 +00001140 }(pConfigVlanStateAFsm)
1141 return
1142 }
mpagenko9a304ea2020-12-16 15:54:01 +00001143 //access to uniVlanFlowParamsSlice is done on first element only here per definition
1144 //store the actual rule that shall be worked upon in the following transient states
Girish Gowdrae95687a2021-09-08 16:30:58 -07001145 oFsm.actualUniFlowParam = oFsm.uniVlanFlowParamsSlice[0]
1146 tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID
mpagenko9a304ea2020-12-16 15:54:01 +00001147 oFsm.TpIDWaitingFor = tpID
Girish Gowdra24dd1132021-07-06 15:25:40 -07001148 //cmp also usage in EVTOCDE create in omci_cc
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001149 oFsm.evtocdID = cmn.MacBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.MacBpNo)
Girish Gowdrae95687a2021-09-08 16:30:58 -07001150 loSetVlan := oFsm.actualUniFlowParam.VlanRuleParams.SetVid
mpagenko45cc6a32021-07-23 10:06:57 +00001151 //attention: take care to release the mutexFlowParams when calling the FSM directly -
1152 // synchronous FSM 'event/state' functions may rely on this mutex
1153 // but it must be released already before calling getTechProfileDone() as it may already be locked
1154 // by the techProfile processing call to VlanFsm.IsFlowRemovePending() (see VOL-4207)
Girish Gowdra24dd1132021-07-06 15:25:40 -07001155 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001156 loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.UniID, uint8(tpID))
mpagenko9a304ea2020-12-16 15:54:01 +00001157 logger.Debugw(ctx, "UniVlanConfigFsm - start with first rule", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001158 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko45cc6a32021-07-23 10:06:57 +00001159 "set-Vlan": loSetVlan, "tp-id": tpID, "ProfDone": loTechProfDone})
Girish Gowdra24dd1132021-07-06 15:25:40 -07001160
mpagenko9a304ea2020-12-16 15:54:01 +00001161 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001162 go func(aPAFsm *cmn.AdapterFsm, aTechProfDone bool) {
1163 if aPAFsm != nil && aPAFsm.PFsm != nil {
mpagenko551a4d42020-12-08 18:09:20 +00001164 if aTechProfDone {
mpagenkodff5dda2020-08-28 11:52:01 +00001165 // let the vlan processing begin
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001166 _ = aPAFsm.PFsm.Event(VlanEvStartConfig)
mpagenkodff5dda2020-08-28 11:52:01 +00001167 } else {
1168 // set to waiting for Techprofile
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001169 _ = aPAFsm.PFsm.Event(VlanEvWaitTechProf)
mpagenkodff5dda2020-08-28 11:52:01 +00001170 }
1171 }
mpagenko551a4d42020-12-08 18:09:20 +00001172 }(pConfigVlanStateAFsm, loTechProfDone)
1173 } else {
1174 logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{
1175 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
1176 //should never happen, else: recovery would be needed from outside the FSM
1177 return
mpagenkodff5dda2020-08-28 11:52:01 +00001178 }
1179}
1180
dbainbri4d3a0dc2020-12-02 00:33:42 +00001181func (oFsm *UniVlanConfigFsm) enterConfigVtfd(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001182 //mutex protection is required for possible concurrent access to FSM members
1183 oFsm.mutexFlowParams.Lock()
mpagenko551a4d42020-12-08 18:09:20 +00001184 oFsm.TpIDWaitingFor = 0 //reset indication to avoid misinterpretation
Girish Gowdrae95687a2021-09-08 16:30:58 -07001185 if oFsm.actualUniFlowParam.VlanRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
mpagenkodff5dda2020-08-28 11:52:01 +00001186 // meaning transparent setup - no specific VTFD setting required
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001187 oFsm.mutexFlowParams.Unlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001188 logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD config required", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001189 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001190 // let the FSM proceed ... (from within this state all internal pointers may be expected to be correct)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001191 pConfigVlanStateAFsm := oFsm.PAdaptFsm
mpagenko9a304ea2020-12-16 15:54:01 +00001192 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001193 go func(a_pAFsm *cmn.AdapterFsm) {
1194 _ = a_pAFsm.PFsm.Event(VlanEvRxConfigVtfd)
mpagenkodff5dda2020-08-28 11:52:01 +00001195 }(pConfigVlanStateAFsm)
1196 } else {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001197 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
1198 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
Girish Gowdrae95687a2021-09-08 16:30:58 -07001199 vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.actualUniFlowParam.VlanRuleParams.TpID))
dbainbri4d3a0dc2020-12-02 00:33:42 +00001200 logger.Debugw(ctx, "UniVlanConfigFsm create VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001201 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
Mahir Gunyel6781f962021-05-16 23:30:08 -07001202 "in state": e.FSM.Current(), "device-id": oFsm.deviceID,
Girish Gowdrae95687a2021-09-08 16:30:58 -07001203 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": oFsm.actualUniFlowParam.VlanRuleParams.TpID})
mpagenko01e726e2020-10-23 09:45:29 +00001204 // setVid is assumed to be masked already by the caller to 12 bit
Girish Gowdrae95687a2021-09-08 16:30:58 -07001205 oFsm.vlanFilterList[0] = uint16(oFsm.actualUniFlowParam.VlanRuleParams.SetVid)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001206 oFsm.mutexFlowParams.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00001207 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001208 vtfdFilterList[0] = oFsm.vlanFilterList[0]
1209 oFsm.numVlanFilterEntries = 1
mpagenkodff5dda2020-08-28 11:52:01 +00001210 meParams := me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001211 EntityID: vtfdID,
mpagenkodff5dda2020-08-28 11:52:01 +00001212 Attributes: me.AttributeValueMap{
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001213 "VlanFilterList": vtfdFilterList, //omci lib wants a slice for serialization
1214 "ForwardOperation": uint8(0x10), //VID investigation
1215 "NumberOfEntries": oFsm.numVlanFilterEntries,
mpagenkodff5dda2020-08-28 11:52:01 +00001216 },
1217 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001218 logger.Debugw(ctx, "UniVlanConfigFsm sendcreate VTFD", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001219 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001220 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001221 meInstance, err := oFsm.pOmciCC.SendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1222 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001223 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001224 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001225 logger.Errorw(ctx, "VTFD create failed, aborting UniVlanConfig FSM!",
1226 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001227 pConfigVlanStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001228 if pConfigVlanStateAFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001229 go func(a_pAFsm *cmn.AdapterFsm) {
1230 _ = a_pAFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001231 }(pConfigVlanStateAFsm)
1232 }
1233 return
1234 }
mpagenkodff5dda2020-08-28 11:52:01 +00001235 //accept also nil as (error) return value for writing to LastTx
1236 // - this avoids misinterpretation of new received OMCI messages
1237 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1238 // send shall return (dual format) error code that can be used here for immediate error treatment
1239 // (relevant to all used sendXX() methods in this (and other) FSM's)
mpagenko01e726e2020-10-23 09:45:29 +00001240 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001241 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001242 }
1243}
1244
dbainbri4d3a0dc2020-12-02 00:33:42 +00001245func (oFsm *UniVlanConfigFsm) enterConfigEvtocd(ctx context.Context, e *fsm.Event) {
1246 logger.Debugw(ctx, "UniVlanConfigFsm - start config EVTOCD loop", log.Fields{
mpagenkof1d21d12021-06-11 13:14:45 +00001247 "device-id": oFsm.deviceID})
mpagenkof1fc3862021-02-16 10:09:52 +00001248 oFsm.requestEventOffset = uint8(cDeviceEventOffsetAddWithKvStore) //0 offset for last flow-add activity
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001249 go func() {
mpagenko9a304ea2020-12-16 15:54:01 +00001250 //using the first element in the slice because it's the first flow per definition here
1251 errEvto := oFsm.performConfigEvtocdEntries(ctx, 0)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001252 //This is correct passing scenario
1253 if errEvto == nil {
mpagenkof1d21d12021-06-11 13:14:45 +00001254 oFsm.mutexFlowParams.RLock()
Girish Gowdrae95687a2021-09-08 16:30:58 -07001255 tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID
1256 vlanID := oFsm.actualUniFlowParam.VlanRuleParams.SetVid
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001257 configuredUniFlows := oFsm.ConfiguredUniFlow
mpagenko3ce9fa02021-07-28 13:26:54 +00001258 // ensure mutexFlowParams not locked before calling some TPProcessing activity (that might already be pending on it)
1259 oFsm.mutexFlowParams.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001260 for _, gemPort := range oFsm.pUniTechProf.getMulticastGemPorts(ctx, oFsm.pOnuUniPort.UniID, uint8(tpID)) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001261 logger.Infow(ctx, "Setting multicast MEs, with first flow", log.Fields{"deviceID": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001262 "techProfile": tpID, "gemPort": gemPort, "vlanID": vlanID, "ConfiguredUniFlow": configuredUniFlows})
dbainbri4d3a0dc2020-12-02 00:33:42 +00001263 errCreateAllMulticastME := oFsm.performSettingMulticastME(ctx, tpID, gemPort,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001264 vlanID)
1265 if errCreateAllMulticastME != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001266 logger.Errorw(ctx, "Multicast ME create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001267 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001268 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001269 }
1270 }
ozgecanetsia82b91a62021-05-21 18:54:49 +03001271 //If this first flow contains a meter, then create TD for related gems.
Girish Gowdrae95687a2021-09-08 16:30:58 -07001272 if oFsm.actualUniFlowParam.Meter != nil {
1273 logger.Debugw(ctx, "Creating Traffic Descriptor", log.Fields{"device-id": oFsm.deviceID, "meter": oFsm.actualUniFlowParam.Meter})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001274 for _, gemPort := range oFsm.pUniTechProf.getBidirectionalGemPortIDsForTP(ctx, oFsm.pOnuUniPort.UniID, tpID) {
Girish Gowdrae95687a2021-09-08 16:30:58 -07001275 logger.Debugw(ctx, "Creating Traffic Descriptor for gem", log.Fields{"device-id": oFsm.deviceID, "meter": oFsm.actualUniFlowParam.Meter, "gem": gemPort})
1276 errCreateTrafficDescriptor := oFsm.createTrafficDescriptor(ctx, oFsm.actualUniFlowParam.Meter, tpID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001277 oFsm.pOnuUniPort.UniID, gemPort)
ozgecanetsia82b91a62021-05-21 18:54:49 +03001278 if errCreateTrafficDescriptor != nil {
1279 logger.Errorw(ctx, "Create Traffic Descriptor create failed, aborting Ani Config FSM!",
1280 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001281 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsia82b91a62021-05-21 18:54:49 +03001282 }
1283 }
1284 }
1285
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001286 //TODO Possibly insert new state for multicast --> possibly another jira/later time.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001287 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvRxConfigEvtocd)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001288 }
1289 }()
mpagenkodff5dda2020-08-28 11:52:01 +00001290}
1291
dbainbri4d3a0dc2020-12-02 00:33:42 +00001292func (oFsm *UniVlanConfigFsm) enterVlanConfigDone(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001293
mpagenkof1d21d12021-06-11 13:14:45 +00001294 oFsm.mutexFlowParams.Lock()
mpagenko9a304ea2020-12-16 15:54:01 +00001295
mpagenkof1fc3862021-02-16 10:09:52 +00001296 logger.Infow(ctx, "UniVlanConfigFsm config done - checking on more flows", log.Fields{
mpagenkof1d21d12021-06-11 13:14:45 +00001297 "device-id": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001298 "overall-uni-rules": oFsm.NumUniFlows, "configured-uni-rules": oFsm.ConfiguredUniFlow})
Girish Gowdrae95687a2021-09-08 16:30:58 -07001299 if len(oFsm.uniVlanFlowParamsSlice) > 0 {
1300 oFsm.PushReponseOnFlowResponseChannel(ctx, oFsm.actualUniFlowParam.RespChan, nil)
1301 }
1302
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001303 pConfigVlanStateAFsm := oFsm.PAdaptFsm
mpagenko551a4d42020-12-08 18:09:20 +00001304 if pConfigVlanStateAFsm == nil {
mpagenkof1d21d12021-06-11 13:14:45 +00001305 oFsm.mutexFlowParams.Unlock()
mpagenko551a4d42020-12-08 18:09:20 +00001306 logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{
1307 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
1308 //should never happen, else: recovery would be needed from outside the FSM
1309 return
1310 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001311 pConfigVlanStateBaseFsm := pConfigVlanStateAFsm.PFsm
mpagenko01e726e2020-10-23 09:45:29 +00001312 if len(oFsm.uniRemoveFlowsSlice) > 0 {
1313 //some further flows are to be removed, removal always starts with the first element
mpagenko9a304ea2020-12-16 15:54:01 +00001314 logger.Debugw(ctx, "UniVlanConfigFsm rule removal from ConfigDone", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001315 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko9a304ea2020-12-16 15:54:01 +00001316 "tp-id": oFsm.uniRemoveFlowsSlice[0].vlanRuleParams.TpID,
1317 "set-Vlan": oFsm.uniRemoveFlowsSlice[0].vlanRuleParams.SetVid})
mpagenkof1d21d12021-06-11 13:14:45 +00001318 oFsm.mutexFlowParams.Unlock()
mpagenko9a304ea2020-12-16 15:54:01 +00001319 // Can't call FSM Event directly, decoupling it
mpagenko01e726e2020-10-23 09:45:29 +00001320 go func(a_pBaseFsm *fsm.FSM) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001321 _ = a_pBaseFsm.Event(VlanEvRemFlowConfig)
mpagenko01e726e2020-10-23 09:45:29 +00001322 }(pConfigVlanStateBaseFsm)
1323 return
1324 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001325 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
1326 oFsm.ConfiguredUniFlow = oFsm.NumUniFlows
Andrea Campanellaf66ac6e2021-05-24 17:09:20 +02001327 if oFsm.lastFlowToReconcile {
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001328 logger.Debugw(ctx, "reconciling - flow processing finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001329 oFsm.pOnuDeviceEntry.SetReconcilingFlows(false)
1330 oFsm.pOnuDeviceEntry.SetChReconcilingFlowsFinished(true)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001331 }
Holger Hildebrandt1b8f4ad2021-03-25 15:53:51 +00001332 logger.Debugw(ctx, "reconciling - skip enterVlanConfigDone processing",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001333 log.Fields{"NumUniFlows": oFsm.NumUniFlows, "ConfiguredUniFlow": oFsm.ConfiguredUniFlow, "device-id": oFsm.deviceID})
mpagenkof1d21d12021-06-11 13:14:45 +00001334 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt1b8f4ad2021-03-25 15:53:51 +00001335 return
1336 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001337 if oFsm.NumUniFlows > oFsm.ConfiguredUniFlow {
1338 if oFsm.ConfiguredUniFlow == 0 {
mpagenkof1d21d12021-06-11 13:14:45 +00001339 oFsm.mutexFlowParams.Unlock()
mpagenko551a4d42020-12-08 18:09:20 +00001340 // this is a restart with a complete new flow, we can re-use the initial flow config control
1341 // including the check, if the related techProfile is (still) available (probably also removed in between)
mpagenko9a304ea2020-12-16 15:54:01 +00001342 // Can't call FSM Event directly, decoupling it
mpagenko551a4d42020-12-08 18:09:20 +00001343 go func(a_pBaseFsm *fsm.FSM) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001344 _ = a_pBaseFsm.Event(VlanEvRenew)
mpagenko551a4d42020-12-08 18:09:20 +00001345 }(pConfigVlanStateBaseFsm)
1346 return
1347 }
1348
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001349 //some further flows are to be configured
mpagenko9a304ea2020-12-16 15:54:01 +00001350 //store the actual rule that shall be worked upon in the following transient states
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001351 if len(oFsm.uniVlanFlowParamsSlice) < int(oFsm.ConfiguredUniFlow) {
mpagenkof1d21d12021-06-11 13:14:45 +00001352 //check introduced after having observed some panic in this processing
1353 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm in ConfigDone - inconsistent counter",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001354 log.Fields{"ConfiguredUniFlow": oFsm.ConfiguredUniFlow,
mpagenkof1d21d12021-06-11 13:14:45 +00001355 "sliceLen": len(oFsm.uniVlanFlowParamsSlice), "device-id": oFsm.deviceID})
1356 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001357 go func(a_pAFsm *cmn.AdapterFsm) {
1358 _ = a_pAFsm.PFsm.Event(VlanEvReset)
mpagenkof1d21d12021-06-11 13:14:45 +00001359 }(pConfigVlanStateAFsm)
1360 return
1361 }
Girish Gowdrae95687a2021-09-08 16:30:58 -07001362 oFsm.actualUniFlowParam = oFsm.uniVlanFlowParamsSlice[oFsm.ConfiguredUniFlow]
mpagenko551a4d42020-12-08 18:09:20 +00001363 //tpId of the next rule to be configured
Girish Gowdrae95687a2021-09-08 16:30:58 -07001364 tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID
mpagenko551a4d42020-12-08 18:09:20 +00001365 oFsm.TpIDWaitingFor = tpID
Girish Gowdrae95687a2021-09-08 16:30:58 -07001366 loSetVlan := oFsm.actualUniFlowParam.VlanRuleParams.SetVid
mpagenko45cc6a32021-07-23 10:06:57 +00001367 //attention: take care to release the mutexFlowParams when calling the FSM directly -
1368 // synchronous FSM 'event/state' functions may rely on this mutex
1369 // but it must be released already before calling getTechProfileDone() as it may already be locked
1370 // by the techProfile processing call to VlanFsm.IsFlowRemovePending() (see VOL-4207)
1371 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001372 loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.UniID, tpID)
mpagenko9a304ea2020-12-16 15:54:01 +00001373 logger.Debugw(ctx, "UniVlanConfigFsm - incremental config request", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001374 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko45cc6a32021-07-23 10:06:57 +00001375 "set-Vlan": loSetVlan, "tp-id": tpID, "ProfDone": loTechProfDone})
1376
mpagenko9a304ea2020-12-16 15:54:01 +00001377 // Can't call FSM Event directly, decoupling it
mpagenko551a4d42020-12-08 18:09:20 +00001378 go func(aPBaseFsm *fsm.FSM, aTechProfDone bool) {
1379 if aTechProfDone {
1380 // let the vlan processing continue with next rule
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001381 _ = aPBaseFsm.Event(VlanEvIncrFlowConfig)
mpagenko551a4d42020-12-08 18:09:20 +00001382 } else {
1383 // set to waiting for Techprofile
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001384 _ = aPBaseFsm.Event(VlanEvWaitTPIncr)
mpagenko551a4d42020-12-08 18:09:20 +00001385 }
1386 }(pConfigVlanStateBaseFsm, loTechProfDone)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001387 return
1388 }
mpagenkof1d21d12021-06-11 13:14:45 +00001389 oFsm.mutexFlowParams.Unlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001390 logger.Debugw(ctx, "UniVlanConfigFsm - VLAN config done: send dh event notification", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001391 "device-id": oFsm.deviceID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001392 // it might appear that some flows are requested also after 'flowPushed' event has been generated ...
1393 // state transition notification is checked in deviceHandler
mpagenko551a4d42020-12-08 18:09:20 +00001394 // note: 'flowPushed' event is only generated if all 'pending' rules are configured
mpagenkodff5dda2020-08-28 11:52:01 +00001395 if oFsm.pDeviceHandler != nil {
mpagenkofc4f56e2020-11-04 17:17:49 +00001396 //making use of the add->remove successor enum assumption/definition
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001397 go oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent(uint8(oFsm.requestEvent)+oFsm.requestEventOffset))
mpagenkodff5dda2020-08-28 11:52:01 +00001398 }
1399}
1400
dbainbri4d3a0dc2020-12-02 00:33:42 +00001401func (oFsm *UniVlanConfigFsm) enterConfigIncrFlow(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001402
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001403 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001404 logger.Debugw(ctx, "reconciling - skip further processing for incremental flow",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001405 log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001406 go func(a_pBaseFsm *fsm.FSM) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001407 _ = a_pBaseFsm.Event(VlanEvSkipIncFlowConfig)
1408 }(oFsm.PAdaptFsm.PFsm)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001409 return
1410 }
mpagenko15ff4a52021-03-02 10:09:20 +00001411 oFsm.mutexFlowParams.Lock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001412 logger.Debugw(ctx, "UniVlanConfigFsm - start config further incremental flow", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001413 "recent flow-number": oFsm.ConfiguredUniFlow,
mpagenkof1d21d12021-06-11 13:14:45 +00001414 "device-id": oFsm.deviceID})
mpagenko551a4d42020-12-08 18:09:20 +00001415 oFsm.TpIDWaitingFor = 0 //reset indication to avoid misinterpretation
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001416
Girish Gowdrae95687a2021-09-08 16:30:58 -07001417 if oFsm.actualUniFlowParam.VlanRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001418 // meaning transparent setup - no specific VTFD setting required
dbainbri4d3a0dc2020-12-02 00:33:42 +00001419 logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD config required", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001420 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001421 } else {
mpagenkocf48e452021-04-23 09:23:00 +00001422 //TODO!!!: it was not really intended to keep this enter* FSM method waiting on OMCI response (preventing other state transitions)
1423 // so it would be conceptually better to wait for the response in background like for the other multi-entity processing
1424 // but as the OMCI sequence must be ensured, a separate new state would be required - perhaps later
1425 // in practice should have no influence by now as no other state transition is currently accepted (while cancel() is ensured)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001426 if oFsm.numVlanFilterEntries == 0 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001427 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
1428 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
Girish Gowdrae95687a2021-09-08 16:30:58 -07001429 vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.actualUniFlowParam.VlanRuleParams.TpID))
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001430 //no VTFD yet created
dbainbri4d3a0dc2020-12-02 00:33:42 +00001431 logger.Debugw(ctx, "UniVlanConfigFsm create VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001432 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenkof1d21d12021-06-11 13:14:45 +00001433 "device-id": oFsm.deviceID,
Girish Gowdrae95687a2021-09-08 16:30:58 -07001434 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": oFsm.actualUniFlowParam.VlanRuleParams.TpID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001435 // 'SetVid' below is assumed to be masked already by the caller to 12 bit
Girish Gowdrae95687a2021-09-08 16:30:58 -07001436 oFsm.vlanFilterList[0] = uint16(oFsm.actualUniFlowParam.VlanRuleParams.SetVid)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001437
mpagenko01e726e2020-10-23 09:45:29 +00001438 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001439 vtfdFilterList[0] = oFsm.vlanFilterList[0]
1440 oFsm.numVlanFilterEntries = 1
1441 meParams := me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001442 EntityID: vtfdID,
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001443 Attributes: me.AttributeValueMap{
1444 "VlanFilterList": vtfdFilterList,
1445 "ForwardOperation": uint8(0x10), //VID investigation
1446 "NumberOfEntries": oFsm.numVlanFilterEntries,
1447 },
1448 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001449 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001450 meInstance, err := oFsm.pOmciCC.SendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1451 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001452 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001453 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkof1d21d12021-06-11 13:14:45 +00001454 oFsm.mutexFlowParams.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001455 logger.Errorw(ctx, "VTFD create failed, aborting UniVlanConfig FSM!",
1456 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001457 pConfigVlanStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001458 if pConfigVlanStateAFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001459 go func(a_pAFsm *cmn.AdapterFsm) {
1460 _ = a_pAFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001461 }(pConfigVlanStateAFsm)
1462 }
1463 return
1464 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001465 //accept also nil as (error) return value for writing to LastTx
1466 // - this avoids misinterpretation of new received OMCI messages
1467 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1468 // send shall return (dual format) error code that can be used here for immediate error treatment
1469 // (relevant to all used sendXX() methods in this (and other) FSM's)
mpagenko01e726e2020-10-23 09:45:29 +00001470 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001471 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001472 } else {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001473 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
1474 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
Girish Gowdrae95687a2021-09-08 16:30:58 -07001475 vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.actualUniFlowParam.VlanRuleParams.TpID))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001476
dbainbri4d3a0dc2020-12-02 00:33:42 +00001477 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001478 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenkof1d21d12021-06-11 13:14:45 +00001479 "device-id": oFsm.deviceID,
Girish Gowdrae95687a2021-09-08 16:30:58 -07001480 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": oFsm.actualUniFlowParam.VlanRuleParams.TpID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001481 // setVid is assumed to be masked already by the caller to 12 bit
1482 oFsm.vlanFilterList[oFsm.numVlanFilterEntries] =
Girish Gowdrae95687a2021-09-08 16:30:58 -07001483 uint16(oFsm.actualUniFlowParam.VlanRuleParams.SetVid)
mpagenko01e726e2020-10-23 09:45:29 +00001484 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001485
1486 // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME
1487 // VTFD has to be created afresh with a new entity ID that has the same entity ID as the MBPCD ME for every
1488 // new vlan associated with a different TP.
Girish Gowdrae95687a2021-09-08 16:30:58 -07001489 vtfdFilterList[0] = uint16(oFsm.actualUniFlowParam.VlanRuleParams.SetVid)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001490
1491 oFsm.numVlanFilterEntries++
1492 meParams := me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001493 EntityID: vtfdID,
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001494 Attributes: me.AttributeValueMap{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001495 "VlanFilterList": vtfdFilterList,
1496 "ForwardOperation": uint8(0x10), //VID investigation
1497 "NumberOfEntries": oFsm.numVlanFilterEntries,
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001498 },
1499 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001500 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001501 meInstance, err := oFsm.pOmciCC.SendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1502 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001503 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001504 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkof1d21d12021-06-11 13:14:45 +00001505 oFsm.mutexFlowParams.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001506 logger.Errorw(ctx, "UniVlanFsm create Vlan Tagging Filter ME result error",
1507 log.Fields{"device-id": oFsm.deviceID, "Error": err})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001508 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001509 return
1510 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001511 //accept also nil as (error) return value for writing to LastTx
1512 // - this avoids misinterpretation of new received OMCI messages
1513 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1514 // send shall return (dual format) error code that can be used here for immediate error treatment
1515 // (relevant to all used sendXX() methods in this (and other) FSM's)
mpagenko01e726e2020-10-23 09:45:29 +00001516 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001517 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001518 }
1519 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001520 err := oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001521 if err != nil {
mpagenkof1d21d12021-06-11 13:14:45 +00001522 oFsm.mutexFlowParams.Unlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001523 logger.Errorw(ctx, "VTFD create/set failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001524 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001525 pConfigVlanStateBaseFsm := oFsm.PAdaptFsm.PFsm
mpagenko9a304ea2020-12-16 15:54:01 +00001526 // Can't call FSM Event directly, decoupling it
mpagenkofc4f56e2020-11-04 17:17:49 +00001527 go func(a_pBaseFsm *fsm.FSM) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001528 _ = a_pBaseFsm.Event(VlanEvReset)
mpagenkofc4f56e2020-11-04 17:17:49 +00001529 }(pConfigVlanStateBaseFsm)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001530 return
1531 }
1532 }
mpagenkof1d21d12021-06-11 13:14:45 +00001533
mpagenkof1fc3862021-02-16 10:09:52 +00001534 oFsm.requestEventOffset = uint8(cDeviceEventOffsetAddWithKvStore) //0 offset for last flow-add activity
mpagenko15ff4a52021-03-02 10:09:20 +00001535 oFsm.mutexFlowParams.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001536 go func() {
mpagenko15ff4a52021-03-02 10:09:20 +00001537 oFsm.mutexFlowParams.RLock()
Girish Gowdrae95687a2021-09-08 16:30:58 -07001538 tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID
1539 configuredUniFlow := oFsm.ConfiguredUniFlow
mpagenko3ce9fa02021-07-28 13:26:54 +00001540 // ensure mutexFlowParams not locked before calling some TPProcessing activity (that might already be pending on it)
mpagenko15ff4a52021-03-02 10:09:20 +00001541 oFsm.mutexFlowParams.RUnlock()
Girish Gowdrae95687a2021-09-08 16:30:58 -07001542 errEvto := oFsm.performConfigEvtocdEntries(ctx, configuredUniFlow)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001543 //This is correct passing scenario
1544 if errEvto == nil {
1545 //TODO Possibly insert new state for multicast --> possibly another jira/later time.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001546 for _, gemPort := range oFsm.pUniTechProf.getMulticastGemPorts(ctx, oFsm.pOnuUniPort.UniID, uint8(tpID)) {
mpagenko15ff4a52021-03-02 10:09:20 +00001547 oFsm.mutexFlowParams.RLock()
Girish Gowdrae95687a2021-09-08 16:30:58 -07001548 vlanID := oFsm.actualUniFlowParam.VlanRuleParams.SetVid
dbainbri4d3a0dc2020-12-02 00:33:42 +00001549 logger.Infow(ctx, "Setting multicast MEs for additional flows", log.Fields{"deviceID": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001550 "techProfile": tpID, "gemPort": gemPort,
Girish Gowdrae95687a2021-09-08 16:30:58 -07001551 "vlanID": vlanID, "ConfiguredUniFlow": configuredUniFlow})
mpagenko15ff4a52021-03-02 10:09:20 +00001552 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001553 errCreateAllMulticastME := oFsm.performSettingMulticastME(ctx, tpID, gemPort, vlanID)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001554 if errCreateAllMulticastME != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001555 logger.Errorw(ctx, "Multicast ME create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001556 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001557 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001558 }
1559 }
ozgecanetsia82b91a62021-05-21 18:54:49 +03001560 //If this incremental flow contains a meter, then create TD for related gems.
Girish Gowdrae95687a2021-09-08 16:30:58 -07001561 if oFsm.actualUniFlowParam.Meter != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001562 for _, gemPort := range oFsm.pUniTechProf.getBidirectionalGemPortIDsForTP(ctx, oFsm.pOnuUniPort.UniID, tpID) {
Girish Gowdrae95687a2021-09-08 16:30:58 -07001563 logger.Debugw(ctx, "Creating Traffic Descriptor for gem", log.Fields{"device-id": oFsm.deviceID, "meter": oFsm.actualUniFlowParam.Meter, "gem": gemPort})
1564 errCreateTrafficDescriptor := oFsm.createTrafficDescriptor(ctx, oFsm.actualUniFlowParam.Meter, tpID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001565 oFsm.pOnuUniPort.UniID, gemPort)
ozgecanetsia82b91a62021-05-21 18:54:49 +03001566 if errCreateTrafficDescriptor != nil {
1567 logger.Errorw(ctx, "Create Traffic Descriptor create failed, aborting Ani Config FSM!",
1568 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001569 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsia82b91a62021-05-21 18:54:49 +03001570 }
1571 }
1572 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001573 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvRxConfigEvtocd)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001574 }
1575 }()
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001576}
1577
dbainbri4d3a0dc2020-12-02 00:33:42 +00001578func (oFsm *UniVlanConfigFsm) enterRemoveFlow(ctx context.Context, e *fsm.Event) {
mpagenko551a4d42020-12-08 18:09:20 +00001579 oFsm.mutexFlowParams.RLock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001580 logger.Debugw(ctx, "UniVlanConfigFsm - start removing the top remove-flow", log.Fields{
mpagenkof1d21d12021-06-11 13:14:45 +00001581 "with last cookie": oFsm.uniRemoveFlowsSlice[0].cookie,
1582 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001583
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001584 pConfigVlanStateBaseFsm := oFsm.PAdaptFsm.PFsm
1585 loAllowSpecificOmciConfig := oFsm.pDeviceHandler.IsReadyForOmciConfig()
mpagenko01e726e2020-10-23 09:45:29 +00001586 loVlanEntryClear := uint8(0)
1587 loVlanEntryRmPos := uint8(0x80) //with indication 'invalid' in bit 7
1588 //shallow copy is sufficient as no reference variables are used within struct
1589 loRuleParams := oFsm.uniRemoveFlowsSlice[0].vlanRuleParams
mpagenko551a4d42020-12-08 18:09:20 +00001590 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001591 logger.Debugw(ctx, "UniVlanConfigFsm - remove-flow parameters are", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001592 "match vid": loRuleParams.MatchVid, "match Pcp": loRuleParams.MatchPcp,
1593 "set vid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
1594 "device-id": oFsm.deviceID})
1595
1596 if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
1597 // meaning transparent setup - no specific VTFD setting required
dbainbri4d3a0dc2020-12-02 00:33:42 +00001598 logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD removal required for transparent flow", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001599 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
1600 } else {
1601 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization and 're-copy'
1602 if oFsm.numVlanFilterEntries == 1 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001603 vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(loRuleParams.TpID))
mpagenko01e726e2020-10-23 09:45:29 +00001604 //only one active VLAN entry (hopefully the SetVID we want to remove - should be, but not verified ..)
1605 // so we can just delete the VTFD entry
dbainbri4d3a0dc2020-12-02 00:33:42 +00001606 logger.Debugw(ctx, "UniVlanConfigFsm: VTFD delete (no more vlan filters)",
Mahir Gunyel6781f962021-05-16 23:30:08 -07001607 log.Fields{"current vlan list": oFsm.vlanFilterList, "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenkof1d21d12021-06-11 13:14:45 +00001608 "device-id": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001609 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": loRuleParams.TpID})
mpagenkofc4f56e2020-11-04 17:17:49 +00001610 loVlanEntryClear = 1 //full VlanFilter clear request
1611 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001612 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001613 meInstance, err := oFsm.pOmciCC.SendDeleteVtfd(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1614 oFsm.PAdaptFsm.CommChan, vtfdID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001615 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001616 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001617 logger.Errorw(ctx, "UniVlanFsm delete Vlan Tagging Filter ME result error",
1618 log.Fields{"device-id": oFsm.deviceID, "Error": err})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001619 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001620 return
1621 }
mpagenkofc4f56e2020-11-04 17:17:49 +00001622 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001623 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkofc4f56e2020-11-04 17:17:49 +00001624 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001625 logger.Debugw(ctx, "UniVlanConfigFsm delete VTFD OMCI handling skipped based on device state", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001626 "device-id": oFsm.deviceID, "device-state": oFsm.pDeviceHandler.GetDeviceReasonString()})
mpagenkofc4f56e2020-11-04 17:17:49 +00001627 }
mpagenko01e726e2020-10-23 09:45:29 +00001628 } else {
1629 //many VTFD already should exists - find and remove the one concerned by the actual remove rule
1630 // by updating the VTFD per set command with new valid list
dbainbri4d3a0dc2020-12-02 00:33:42 +00001631 logger.Debugw(ctx, "UniVlanConfigFsm: VTFD removal of requested VLAN from the list on OMCI",
mpagenko01e726e2020-10-23 09:45:29 +00001632 log.Fields{"current vlan list": oFsm.vlanFilterList,
1633 "set-vlan": loRuleParams.SetVid, "device-id": oFsm.deviceID})
1634 for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ {
1635 if loRuleParams.SetVid == uint32(oFsm.vlanFilterList[i]) {
1636 loVlanEntryRmPos = i
1637 break //abort search
1638 }
1639 }
1640 if loVlanEntryRmPos < cVtfdTableSize {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001641 vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(loRuleParams.TpID))
mpagenko01e726e2020-10-23 09:45:29 +00001642 //valid entry was found - to be eclipsed
1643 loVlanEntryClear = 2 //VlanFilter remove request for a specific entry
1644 for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ {
1645 if i < loVlanEntryRmPos {
1646 vtfdFilterList[i] = oFsm.vlanFilterList[i] //copy original
1647 } else if i < (cVtfdTableSize - 1) {
1648 vtfdFilterList[i] = oFsm.vlanFilterList[i+1] //copy successor (including 0 elements)
1649 } else {
1650 vtfdFilterList[i] = 0 //set last byte if needed
1651 }
1652 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001653 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001654 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
Mahir Gunyel6781f962021-05-16 23:30:08 -07001655 "new vlan list": vtfdFilterList, "device-id": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001656 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": loRuleParams.TpID})
mpagenko01e726e2020-10-23 09:45:29 +00001657
mpagenkofc4f56e2020-11-04 17:17:49 +00001658 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001659 // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001660 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001661 meInstance, err := oFsm.pOmciCC.SendDeleteVtfd(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1662 oFsm.PAdaptFsm.CommChan, vtfdID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001663 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001664 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001665 logger.Errorw(ctx, "UniVlanFsm delete Vlan Tagging Filter ME result error",
1666 log.Fields{"device-id": oFsm.deviceID, "Error": err})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001667 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001668 return
1669 }
mpagenkofc4f56e2020-11-04 17:17:49 +00001670 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001671 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkofc4f56e2020-11-04 17:17:49 +00001672 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001673 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD OMCI handling skipped based on device state", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001674 "device-id": oFsm.deviceID, "device-state": oFsm.pDeviceHandler.GetDeviceReasonString()})
mpagenko01e726e2020-10-23 09:45:29 +00001675 }
mpagenko01e726e2020-10-23 09:45:29 +00001676 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001677 logger.Warnw(ctx, "UniVlanConfigFsm: requested VLAN for removal not found in list - ignore and continue (no VTFD set)",
mpagenko01e726e2020-10-23 09:45:29 +00001678 log.Fields{"device-id": oFsm.deviceID})
1679 }
1680 }
1681 if loVlanEntryClear > 0 {
mpagenkofc4f56e2020-11-04 17:17:49 +00001682 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
1683 //waiting on response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001684 err := oFsm.waitforOmciResponse(ctx)
mpagenkofc4f56e2020-11-04 17:17:49 +00001685 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001686 logger.Errorw(ctx, "VTFD delete/reset failed, aborting VlanConfig FSM!",
mpagenkofc4f56e2020-11-04 17:17:49 +00001687 log.Fields{"device-id": oFsm.deviceID})
mpagenko9a304ea2020-12-16 15:54:01 +00001688 // Can't call FSM Event directly, decoupling it
mpagenkofc4f56e2020-11-04 17:17:49 +00001689 go func(a_pBaseFsm *fsm.FSM) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001690 _ = a_pBaseFsm.Event(VlanEvReset)
mpagenkofc4f56e2020-11-04 17:17:49 +00001691 }(pConfigVlanStateBaseFsm)
1692 return
1693 }
mpagenko01e726e2020-10-23 09:45:29 +00001694 }
1695
mpagenko15ff4a52021-03-02 10:09:20 +00001696 oFsm.mutexFlowParams.Lock()
mpagenko01e726e2020-10-23 09:45:29 +00001697 if loVlanEntryClear == 1 {
1698 oFsm.vlanFilterList[0] = 0 //first entry is the only that can contain the previous only-one element
1699 oFsm.numVlanFilterEntries = 0
1700 } else if loVlanEntryClear == 2 {
1701 // new VlanFilterList should be one entry smaller now - copy from last configured entry
1702 // this loop now includes the 0 element on previous last valid entry
1703 for i := uint8(0); i <= oFsm.numVlanFilterEntries; i++ {
1704 oFsm.vlanFilterList[i] = vtfdFilterList[i]
1705 }
1706 oFsm.numVlanFilterEntries--
1707 }
mpagenko15ff4a52021-03-02 10:09:20 +00001708 oFsm.mutexFlowParams.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00001709 }
1710 }
1711
mpagenkofc4f56e2020-11-04 17:17:49 +00001712 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
dbainbri4d3a0dc2020-12-02 00:33:42 +00001713 go oFsm.removeEvtocdEntries(ctx, loRuleParams)
mpagenkofc4f56e2020-11-04 17:17:49 +00001714 } else {
1715 // OMCI processing is not done, expectation is to have the ONU in some basic config state accordingly
dbainbri4d3a0dc2020-12-02 00:33:42 +00001716 logger.Debugw(ctx, "UniVlanConfigFsm remove EVTOCD OMCI handling skipped based on device state", log.Fields{
mpagenkofc4f56e2020-11-04 17:17:49 +00001717 "device-id": oFsm.deviceID})
mpagenko9a304ea2020-12-16 15:54:01 +00001718 // Can't call FSM Event directly, decoupling it
mpagenkofc4f56e2020-11-04 17:17:49 +00001719 go func(a_pBaseFsm *fsm.FSM) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001720 _ = a_pBaseFsm.Event(VlanEvRemFlowDone, loRuleParams.TpID)
mpagenkofc4f56e2020-11-04 17:17:49 +00001721 }(pConfigVlanStateBaseFsm)
1722 }
mpagenkodff5dda2020-08-28 11:52:01 +00001723}
1724
dbainbri4d3a0dc2020-12-02 00:33:42 +00001725func (oFsm *UniVlanConfigFsm) enterVlanCleanupDone(ctx context.Context, e *fsm.Event) {
Girish Gowdra26a40922021-01-29 17:14:34 -08001726 var tpID uint8
1727 // Extract the tpID
1728 if len(e.Args) > 0 {
1729 tpID = e.Args[0].(uint8)
1730 logger.Debugw(ctx, "UniVlanConfigFsm - flow removed for tp id", log.Fields{"device-id": oFsm.deviceID, "tpID": e.Args[0].(uint8)})
1731 } else {
1732 logger.Warnw(ctx, "UniVlanConfigFsm - tp id not available", log.Fields{"device-id": oFsm.deviceID})
1733 }
mpagenko01e726e2020-10-23 09:45:29 +00001734 oFsm.mutexFlowParams.Lock()
mpagenkof1fc3862021-02-16 10:09:52 +00001735 deletedCookie := oFsm.uniRemoveFlowsSlice[0].cookie
mpagenkof1d21d12021-06-11 13:14:45 +00001736
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001737 pConfigVlanStateAFsm := oFsm.PAdaptFsm
mpagenkof582d6a2021-06-18 15:58:10 +00001738 if pConfigVlanStateAFsm == nil {
1739 logger.Errorw(ctx, "invalid Fsm pointer - unresolvable - abort",
1740 log.Fields{"device-id": oFsm.deviceID})
1741 //would have to be fixed from outside somehow
1742 return
1743 }
1744
mpagenkof1d21d12021-06-11 13:14:45 +00001745 // here we need o finally remove the removed data also from uniVlanFlowParamsSlice and possibly have to
1746 // stop the suspension of a add-activity waiting for the end of removal
mpagenkof582d6a2021-06-18 15:58:10 +00001747 //call from 'configured' state of the rule
1748 if err := oFsm.removeFlowFromParamsSlice(ctx, deletedCookie, true); err != nil {
1749 //something quite inconsistent detected, perhaps just try to recover with FSM reset
1750 oFsm.mutexFlowParams.Unlock()
1751 logger.Errorw(ctx, "UniVlanConfigFsm - could not clear database - abort", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001752 go func(a_pAFsm *cmn.AdapterFsm) {
1753 _ = a_pAFsm.PFsm.Event(VlanEvReset)
mpagenkof582d6a2021-06-18 15:58:10 +00001754 }(pConfigVlanStateAFsm)
1755 return
1756 }
mpagenkof1d21d12021-06-11 13:14:45 +00001757 if oFsm.uniRemoveFlowsSlice[0].isSuspendedOnAdd {
1758 removeChannel := oFsm.uniRemoveFlowsSlice[0].removeChannel
1759 oFsm.mutexFlowParams.Unlock()
1760 removeChannel <- true
1761 oFsm.mutexFlowParams.Lock()
1762 }
1763
mpagenkof1fc3862021-02-16 10:09:52 +00001764 logger.Debugw(ctx, "UniVlanConfigFsm - removing the removal data", log.Fields{
1765 "in state": e.FSM.Current(), "device-id": oFsm.deviceID,
1766 "removed cookie": deletedCookie, "waitForDeleteCookie": oFsm.delayNewRuleCookie})
1767
Girish Gowdrae95687a2021-09-08 16:30:58 -07001768 // Store the reference to the flow response channel before this entry in the slice is deleted
1769 flowRespChan := oFsm.uniRemoveFlowsSlice[0].respChan
1770
mpagenko01e726e2020-10-23 09:45:29 +00001771 if len(oFsm.uniRemoveFlowsSlice) <= 1 {
1772 oFsm.uniRemoveFlowsSlice = nil //reset the slice
dbainbri4d3a0dc2020-12-02 00:33:42 +00001773 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - last remove-flow deleted", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001774 "device-id": oFsm.deviceID})
1775 } else {
1776 //cut off the actual flow by slicing out the first element
1777 oFsm.uniRemoveFlowsSlice = append(
1778 oFsm.uniRemoveFlowsSlice[:0],
1779 oFsm.uniRemoveFlowsSlice[1:]...)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001780 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - specific flow deleted from data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001781 "device-id": oFsm.deviceID})
1782 }
1783 oFsm.mutexFlowParams.Unlock()
1784
mpagenkof1fc3862021-02-16 10:09:52 +00001785 oFsm.requestEventOffset = uint8(cDeviceEventOffsetRemoveWithKvStore) //offset for last flow-remove activity (with kvStore request)
mpagenko01e726e2020-10-23 09:45:29 +00001786 //return to the basic config verification state
mpagenkof582d6a2021-06-18 15:58:10 +00001787 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001788 go func(a_pAFsm *cmn.AdapterFsm) {
1789 _ = a_pAFsm.PFsm.Event(VlanEvFlowDataRemoved)
mpagenkof582d6a2021-06-18 15:58:10 +00001790 }(pConfigVlanStateAFsm)
Girish Gowdra26a40922021-01-29 17:14:34 -08001791
mpagenkobb47bc22021-04-20 13:29:09 +00001792 oFsm.mutexFlowParams.Lock()
Girish Gowdra26a40922021-01-29 17:14:34 -08001793 noOfFlowRem := len(oFsm.uniRemoveFlowsSlice)
mpagenkof1fc3862021-02-16 10:09:52 +00001794 if deletedCookie == oFsm.delayNewRuleCookie {
1795 // flush the channel CookieDeleted to ensure it is not lingering from some previous (aborted) activity
1796 select {
1797 case <-oFsm.chCookieDeleted:
1798 logger.Debug(ctx, "flushed CookieDeleted")
1799 default:
1800 }
1801 oFsm.chCookieDeleted <- true // let the waiting AddFlow thread continue
1802 }
mpagenkobb47bc22021-04-20 13:29:09 +00001803 // If all pending flow-removes are completed and TP ID is valid go on processing any pending TP delete
1804 if oFsm.signalOnFlowDelete && noOfFlowRem == 0 && tpID > 0 {
1805 logger.Debugw(ctx, "signal flow removal for pending TP delete", log.Fields{"device-id": oFsm.deviceID, "tpID": tpID})
Girish Gowdra26a40922021-01-29 17:14:34 -08001806 // If we are here then all flows are removed.
mpagenkobb47bc22021-04-20 13:29:09 +00001807 if len(oFsm.flowDeleteChannel) == 0 { //channel not yet in use
1808 oFsm.flowDeleteChannel <- true
1809 oFsm.signalOnFlowDelete = false
1810 }
Girish Gowdra26a40922021-01-29 17:14:34 -08001811 }
mpagenkobb47bc22021-04-20 13:29:09 +00001812 oFsm.mutexFlowParams.Unlock()
Girish Gowdrae95687a2021-09-08 16:30:58 -07001813
1814 // send response on the response channel for the removed flow.
1815 oFsm.PushReponseOnFlowResponseChannel(ctx, flowRespChan, nil)
mpagenkodff5dda2020-08-28 11:52:01 +00001816}
1817
dbainbri4d3a0dc2020-12-02 00:33:42 +00001818func (oFsm *UniVlanConfigFsm) enterResetting(ctx context.Context, e *fsm.Event) {
1819 logger.Debugw(ctx, "UniVlanConfigFsm resetting", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001820
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001821 pConfigVlanStateAFsm := oFsm.PAdaptFsm
mpagenkodff5dda2020-08-28 11:52:01 +00001822 if pConfigVlanStateAFsm != nil {
1823 // abort running message processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001824 fsmAbortMsg := cmn.Message{
1825 Type: cmn.TestMsg,
1826 Data: cmn.TestMessage{
1827 TestMessageVal: cmn.AbortMessageProcessing,
mpagenkodff5dda2020-08-28 11:52:01 +00001828 },
1829 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001830 pConfigVlanStateAFsm.CommChan <- fsmAbortMsg
mpagenkodff5dda2020-08-28 11:52:01 +00001831
mpagenko9a304ea2020-12-16 15:54:01 +00001832 //try to restart the FSM to 'disabled'
1833 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001834 go func(a_pAFsm *cmn.AdapterFsm) {
1835 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
1836 _ = a_pAFsm.PFsm.Event(VlanEvRestart)
mpagenkodff5dda2020-08-28 11:52:01 +00001837 }
1838 }(pConfigVlanStateAFsm)
1839 }
1840}
1841
dbainbri4d3a0dc2020-12-02 00:33:42 +00001842func (oFsm *UniVlanConfigFsm) enterDisabled(ctx context.Context, e *fsm.Event) {
1843 logger.Debugw(ctx, "UniVlanConfigFsm enters disabled state", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001844 oFsm.mutexPLastTxMeInstance.Lock()
mpagenko01e726e2020-10-23 09:45:29 +00001845 oFsm.pLastTxMeInstance = nil
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001846 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkof1d21d12021-06-11 13:14:45 +00001847
1848 oFsm.mutexFlowParams.RLock()
1849 if oFsm.delayNewRuleCookie != 0 {
1850 // looks like the waiting AddFlow is stuck
1851 oFsm.mutexFlowParams.RUnlock()
mpagenkobc4170a2021-08-17 16:42:10 +00001852 oFsm.chCookieDeleted <- false // let the waiting AddFlow thread terminate
mpagenkof1d21d12021-06-11 13:14:45 +00001853 oFsm.mutexFlowParams.RLock()
1854 }
1855 if len(oFsm.uniRemoveFlowsSlice) > 0 {
1856 for _, removeUniFlowParams := range oFsm.uniRemoveFlowsSlice {
1857 if removeUniFlowParams.isSuspendedOnAdd {
1858 removeChannel := removeUniFlowParams.removeChannel
1859 logger.Debugw(ctx, "UniVlanConfigFsm flow clear-up - abort suspended rule-add", log.Fields{
1860 "device-id": oFsm.deviceID, "cookie": removeUniFlowParams.cookie})
1861 oFsm.mutexFlowParams.RUnlock()
1862 removeChannel <- false
1863 oFsm.mutexFlowParams.RLock()
1864 }
Girish Gowdrae95687a2021-09-08 16:30:58 -07001865 // Send response on response channel if the caller is waiting on it.
1866 oFsm.PushReponseOnFlowResponseChannel(ctx, removeUniFlowParams.respChan, fmt.Errorf("internal-error"))
mpagenkof1d21d12021-06-11 13:14:45 +00001867 }
1868 }
1869
mpagenkodff5dda2020-08-28 11:52:01 +00001870 if oFsm.pDeviceHandler != nil {
mpagenko2418ab02020-11-12 12:58:06 +00001871 //TODO: to clarify with improved error treatment for VlanConfigFsm (timeout,reception) errors
1872 // current code removes the complete FSM including all flow/rule configuration done so far
1873 // this might be a bit to much, it would require fully new flow config from rwCore (at least on OnuDown/up)
1874 // maybe a more sophisticated approach is possible without clearing the data
1875 if oFsm.clearPersistency {
1876 //permanently remove possibly stored persistent data
1877 if len(oFsm.uniVlanFlowParamsSlice) > 0 {
Girish Gowdrae95687a2021-09-08 16:30:58 -07001878 for _, vlanRule := range oFsm.uniVlanFlowParamsSlice {
1879 // Send response on response channel if the caller is waiting on it.
1880 oFsm.PushReponseOnFlowResponseChannel(ctx, vlanRule.RespChan, fmt.Errorf("internal-error"))
1881 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001882 var emptySlice = make([]cmn.UniVlanFlowParams, 0)
1883 _ = oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID, &emptySlice, true) //ignore errors
mpagenko2418ab02020-11-12 12:58:06 +00001884 }
1885 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001886 logger.Debugw(ctx, "UniVlanConfigFsm persistency data not cleared", log.Fields{"device-id": oFsm.deviceID})
mpagenko2418ab02020-11-12 12:58:06 +00001887 }
mpagenko9a304ea2020-12-16 15:54:01 +00001888 oFsm.mutexFlowParams.RUnlock()
mpagenko2418ab02020-11-12 12:58:06 +00001889 //request removal of 'reference' in the Handler (completely clear the FSM and its data)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001890 go oFsm.pDeviceHandler.RemoveVlanFilterFsm(ctx, oFsm.pOnuUniPort)
mpagenkof1d21d12021-06-11 13:14:45 +00001891 return
mpagenkodff5dda2020-08-28 11:52:01 +00001892 }
mpagenkof1d21d12021-06-11 13:14:45 +00001893 oFsm.mutexFlowParams.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001894}
1895
dbainbri4d3a0dc2020-12-02 00:33:42 +00001896func (oFsm *UniVlanConfigFsm) processOmciVlanMessages(ctx context.Context) { //ctx context.Context?
1897 logger.Debugw(ctx, "Start UniVlanConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001898loop:
1899 for {
mpagenkodff5dda2020-08-28 11:52:01 +00001900 // case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +00001901 // logger.Info(ctx,"MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001902 // break loop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001903 message, ok := <-oFsm.PAdaptFsm.CommChan
Himani Chawla4d908332020-08-31 12:30:20 +05301904 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001905 logger.Info(ctx, "UniVlanConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301906 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001907 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
Himani Chawla4d908332020-08-31 12:30:20 +05301908 break loop
1909 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001910 logger.Debugw(ctx, "UniVlanConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301911
1912 switch message.Type {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001913 case cmn.TestMsg:
1914 msg, _ := message.Data.(cmn.TestMessage)
1915 if msg.TestMessageVal == cmn.AbortMessageProcessing {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001916 logger.Infow(ctx, "UniVlanConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001917 break loop
1918 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001919 logger.Warnw(ctx, "UniVlanConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001920 case cmn.OMCI:
1921 msg, _ := message.Data.(cmn.OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001922 oFsm.handleOmciVlanConfigMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301923 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +00001924 logger.Warn(ctx, "UniVlanConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID,
Himani Chawla4d908332020-08-31 12:30:20 +05301925 "message.Type": message.Type})
mpagenkodff5dda2020-08-28 11:52:01 +00001926 }
1927 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001928 logger.Infow(ctx, "End UniVlanConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001929}
1930
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001931func (oFsm *UniVlanConfigFsm) handleOmciVlanConfigMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001932 logger.Debugw(ctx, "Rx OMCI UniVlanConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00001933 "msgType": msg.OmciMsg.MessageType})
1934
1935 switch msg.OmciMsg.MessageType {
1936 case omci.CreateResponseType:
mpagenko01e726e2020-10-23 09:45:29 +00001937 { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-(
dbainbri4d3a0dc2020-12-02 00:33:42 +00001938 if err := oFsm.handleOmciCreateResponseMessage(ctx, msg.OmciPacket); err != nil {
1939 logger.Warnw(ctx, "CreateResponse handling aborted", log.Fields{"err": err})
mpagenkodff5dda2020-08-28 11:52:01 +00001940 return
1941 }
mpagenkodff5dda2020-08-28 11:52:01 +00001942 } //CreateResponseType
1943 case omci.SetResponseType:
mpagenko01e726e2020-10-23 09:45:29 +00001944 { //leave that here as direct code as most often used
mpagenkodff5dda2020-08-28 11:52:01 +00001945 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
1946 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001947 logger.Errorw(ctx, "Omci Msg layer could not be detected for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001948 log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001949 return
1950 }
1951 msgObj, msgOk := msgLayer.(*omci.SetResponse)
1952 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001953 logger.Errorw(ctx, "Omci Msg layer could not be assigned for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001954 log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001955 return
1956 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001957 logger.Debugw(ctx, "UniVlanConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenkodff5dda2020-08-28 11:52:01 +00001958 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001959 logger.Errorw(ctx, "UniVlanConfigFsm Omci SetResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00001960 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
mpagenkodff5dda2020-08-28 11:52:01 +00001961 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
1962 return
1963 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001964 oFsm.mutexPLastTxMeInstance.RLock()
1965 if oFsm.pLastTxMeInstance != nil {
1966 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1967 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1968 switch oFsm.pLastTxMeInstance.GetName() {
ozgecanetsia82b91a62021-05-21 18:54:49 +03001969 case "VlanTaggingFilterData", "ExtendedVlanTaggingOperationConfigurationData", "MulticastOperationsProfile", "GemPortNetworkCtp":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001970 { // let the MultiEntity config proceed by stopping the wait function
1971 oFsm.mutexPLastTxMeInstance.RUnlock()
1972 oFsm.omciMIdsResponseReceived <- true
1973 return
1974 }
1975 default:
1976 {
1977 logger.Warnw(ctx, "Unsupported ME name received!",
1978 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1979 }
mpagenkodff5dda2020-08-28 11:52:01 +00001980 }
1981 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001982 } else {
1983 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001984 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001985 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001986 } //SetResponseType
mpagenko01e726e2020-10-23 09:45:29 +00001987 case omci.DeleteResponseType:
1988 { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-(
dbainbri4d3a0dc2020-12-02 00:33:42 +00001989 if err := oFsm.handleOmciDeleteResponseMessage(ctx, msg.OmciPacket); err != nil {
1990 logger.Warnw(ctx, "DeleteResponse handling aborted", log.Fields{"err": err})
mpagenko01e726e2020-10-23 09:45:29 +00001991 return
1992 }
1993 } //DeleteResponseType
mpagenkodff5dda2020-08-28 11:52:01 +00001994 default:
1995 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001996 logger.Errorw(ctx, "Rx OMCI unhandled MsgType",
mpagenko01e726e2020-10-23 09:45:29 +00001997 log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001998 return
1999 }
2000 }
2001}
2002
dbainbri4d3a0dc2020-12-02 00:33:42 +00002003func (oFsm *UniVlanConfigFsm) handleOmciCreateResponseMessage(ctx context.Context, apOmciPacket *gp.Packet) error {
mpagenko01e726e2020-10-23 09:45:29 +00002004 msgLayer := (*apOmciPacket).Layer(omci.LayerTypeCreateResponse)
2005 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002006 logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00002007 log.Fields{"device-id": oFsm.deviceID})
2008 return fmt.Errorf("omci msg layer could not be detected for CreateResponse for device-id %x",
2009 oFsm.deviceID)
2010 }
2011 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
2012 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002013 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00002014 log.Fields{"device-id": oFsm.deviceID})
2015 return fmt.Errorf("omci msg layer could not be assigned for CreateResponse for device-id %x",
2016 oFsm.deviceID)
2017 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00002018 logger.Debugw(ctx, "UniVlanConfigFsm CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002019 if msgObj.Result != me.Success && msgObj.Result != me.InstanceExists {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002020 logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": oFsm.deviceID,
mpagenko01e726e2020-10-23 09:45:29 +00002021 "Error": msgObj.Result})
2022 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
2023 return fmt.Errorf("omci CreateResponse Error for device-id %x",
2024 oFsm.deviceID)
2025 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002026 oFsm.mutexPLastTxMeInstance.RLock()
2027 if oFsm.pLastTxMeInstance != nil {
2028 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
2029 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
2030 // to satisfy StaticCodeAnalysis I had to move the small processing into a separate method :-(
2031 switch oFsm.pLastTxMeInstance.GetName() {
2032 case "VlanTaggingFilterData", "MulticastOperationsProfile",
2033 "MulticastSubscriberConfigInfo", "MacBridgePortConfigurationData",
ozgecanetsia82b91a62021-05-21 18:54:49 +03002034 "ExtendedVlanTaggingOperationConfigurationData", "TrafficDescriptor":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002035 {
2036 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002037 if oFsm.PAdaptFsm.PFsm.Current() == VlanStConfigVtfd {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002038 // Only if CreateResponse is received from first flow entry - let the FSM proceed ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002039 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvRxConfigVtfd)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002040 } else { // let the MultiEntity config proceed by stopping the wait function
2041 oFsm.omciMIdsResponseReceived <- true
2042 }
2043 return nil
2044 }
2045 default:
2046 {
2047 logger.Warnw(ctx, "Unsupported ME name received!",
2048 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00002049 }
2050 }
2051 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002052 } else {
2053 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00002054 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002055 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00002056 return nil
2057}
2058
dbainbri4d3a0dc2020-12-02 00:33:42 +00002059func (oFsm *UniVlanConfigFsm) handleOmciDeleteResponseMessage(ctx context.Context, apOmciPacket *gp.Packet) error {
mpagenko01e726e2020-10-23 09:45:29 +00002060 msgLayer := (*apOmciPacket).Layer(omci.LayerTypeDeleteResponse)
2061 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002062 logger.Errorw(ctx, "UniVlanConfigFsm - Omci Msg layer could not be detected for DeleteResponse",
mpagenko01e726e2020-10-23 09:45:29 +00002063 log.Fields{"device-id": oFsm.deviceID})
2064 return fmt.Errorf("omci msg layer could not be detected for DeleteResponse for device-id %x",
2065 oFsm.deviceID)
2066 }
2067 msgObj, msgOk := msgLayer.(*omci.DeleteResponse)
2068 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002069 logger.Errorw(ctx, "UniVlanConfigFsm - Omci Msg layer could not be assigned for DeleteResponse",
mpagenko01e726e2020-10-23 09:45:29 +00002070 log.Fields{"device-id": oFsm.deviceID})
2071 return fmt.Errorf("omci msg layer could not be assigned for DeleteResponse for device-id %x",
2072 oFsm.deviceID)
2073 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00002074 logger.Debugw(ctx, "UniVlanConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenko01e726e2020-10-23 09:45:29 +00002075 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002076 logger.Errorw(ctx, "UniVlanConfigFsm - Omci DeleteResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00002077 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
2078 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
2079 return fmt.Errorf("omci DeleteResponse Error for device-id %x",
2080 oFsm.deviceID)
2081 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002082 oFsm.mutexPLastTxMeInstance.RLock()
2083 if oFsm.pLastTxMeInstance != nil {
2084 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
2085 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
2086 switch oFsm.pLastTxMeInstance.GetName() {
ozgecanetsia82b91a62021-05-21 18:54:49 +03002087 case "VlanTaggingFilterData", "ExtendedVlanTaggingOperationConfigurationData", "TrafficDescriptor":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002088 { // let the MultiEntity config proceed by stopping the wait function
2089 oFsm.mutexPLastTxMeInstance.RUnlock()
2090 oFsm.omciMIdsResponseReceived <- true
2091 return nil
2092 }
2093 default:
2094 {
2095 logger.Warnw(ctx, "Unsupported ME name received!",
2096 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
2097 }
mpagenko01e726e2020-10-23 09:45:29 +00002098 }
2099 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002100 } else {
2101 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00002102 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002103 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00002104 return nil
2105}
2106
dbainbri4d3a0dc2020-12-02 00:33:42 +00002107func (oFsm *UniVlanConfigFsm) performConfigEvtocdEntries(ctx context.Context, aFlowEntryNo uint8) error {
mpagenkof1d21d12021-06-11 13:14:45 +00002108 oFsm.mutexFlowParams.RLock()
2109 evtocdID := oFsm.evtocdID
2110 oFsm.mutexFlowParams.RUnlock()
2111
Holger Hildebrandt394c5522020-09-11 11:23:01 +00002112 if aFlowEntryNo == 0 {
2113 // EthType set only at first flow element
mpagenkodff5dda2020-08-28 11:52:01 +00002114 // EVTOCD ME is expected to exist at this point already from MIB-Download (with AssociationType/Pointer)
2115 // we need to extend the configuration by EthType definition and, to be sure, downstream 'inverse' mode
dbainbri4d3a0dc2020-12-02 00:33:42 +00002116 logger.Debugw(ctx, "UniVlanConfigFsm Tx Create::EVTOCD", log.Fields{
mpagenkof1d21d12021-06-11 13:14:45 +00002117 "EntitytId": strconv.FormatInt(int64(evtocdID), 16),
mpagenkodff5dda2020-08-28 11:52:01 +00002118 "i/oEthType": strconv.FormatInt(int64(cDefaultTpid), 16),
mpagenko01e726e2020-10-23 09:45:29 +00002119 "device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002120 associationType := 2 // default to UniPPTP
2121 if oFsm.pOnuUniPort.PortType == cmn.UniVEIP {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002122 associationType = 10
2123 }
2124 // Create the EVTOCD ME
mpagenkodff5dda2020-08-28 11:52:01 +00002125 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002126 EntityID: evtocdID,
mpagenkodff5dda2020-08-28 11:52:01 +00002127 Attributes: me.AttributeValueMap{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002128 "AssociationType": uint8(associationType),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002129 "AssociatedMePointer": oFsm.pOnuUniPort.EntityID,
mpagenkodff5dda2020-08-28 11:52:01 +00002130 },
2131 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002132 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002133 meInstance, err := oFsm.pOmciCC.SendCreateEvtocdVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(),
2134 true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002135 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002136 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002137 logger.Errorw(ctx, "CreateEvtocdVar create failed, aborting UniVlanConfigFsm!",
2138 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002139 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002140 return fmt.Errorf("evtocd instance create failed %s, error %s", oFsm.deviceID, err)
2141 }
mpagenkodff5dda2020-08-28 11:52:01 +00002142 //accept also nil as (error) return value for writing to LastTx
2143 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00002144 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002145 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002146
2147 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002148 err = oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00002149 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002150 logger.Errorw(ctx, "Evtocd create failed, aborting VlanConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002151 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002152 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002153 return fmt.Errorf("evtocd create failed %s, error %s", oFsm.deviceID, err)
2154 }
2155
2156 // Set the EVTOCD ME default params
2157 meParams = me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002158 EntityID: evtocdID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002159 Attributes: me.AttributeValueMap{
2160 "InputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base
2161 "OutputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base
2162 "DownstreamMode": uint8(cDefaultDownstreamMode),
2163 },
2164 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002165 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002166 meInstance, err = oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2167 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2168 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002169 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002170 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002171 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2172 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002173 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002174 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
2175 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002176 //accept also nil as (error) return value for writing to LastTx
2177 // - this avoids misinterpretation of new received OMCI messages
2178 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002179 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002180
2181 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00002182 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002183 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002184 logger.Errorw(ctx, "Evtocd set TPID failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002185 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002186 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002187 return fmt.Errorf("evtocd set TPID failed %s, error %s", oFsm.deviceID, err)
mpagenkodff5dda2020-08-28 11:52:01 +00002188 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00002189 } //first flow element
mpagenkodff5dda2020-08-28 11:52:01 +00002190
mpagenko551a4d42020-12-08 18:09:20 +00002191 oFsm.mutexFlowParams.RLock()
Girish Gowdrae95687a2021-09-08 16:30:58 -07002192 if oFsm.actualUniFlowParam.VlanRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
mpagenkodff5dda2020-08-28 11:52:01 +00002193 //transparent transmission required
mpagenko551a4d42020-12-08 18:09:20 +00002194 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00002195 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD single tagged transparent rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00002196 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00002197 sliceEvtocdRule := make([]uint8, 16)
2198 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2199 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2200 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2201 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2202 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2203
2204 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2205 cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule
2206 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
2207 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2208 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2209
2210 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
2211 0<<cTreatTTROffset| // Do not pop any tags
2212 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
2213 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2214 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
2215
2216 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
2217 cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag
2218 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2219 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
2220
2221 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002222 EntityID: evtocdID,
mpagenkodff5dda2020-08-28 11:52:01 +00002223 Attributes: me.AttributeValueMap{
2224 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
2225 },
2226 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002227 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002228 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2229 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2230 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002231 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002232 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002233 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2234 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002235 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002236 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
2237 }
mpagenkodff5dda2020-08-28 11:52:01 +00002238 //accept also nil as (error) return value for writing to LastTx
2239 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00002240 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002241 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002242
2243 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002244 err = oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00002245 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002246 logger.Errorw(ctx, "Evtocd set transparent singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002247 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002248 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002249 return fmt.Errorf("evtocd set transparent singletagged rule failed %s, error %s", oFsm.deviceID, err)
2250
mpagenkodff5dda2020-08-28 11:52:01 +00002251 }
2252 } else {
2253 // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario
2254 if oFsm.acceptIncrementalEvtoOption {
Girish Gowdrae95687a2021-09-08 16:30:58 -07002255 matchPcp := oFsm.actualUniFlowParam.VlanRuleParams.MatchPcp
2256 matchVid := oFsm.actualUniFlowParam.VlanRuleParams.MatchVid
2257 setPcp := oFsm.actualUniFlowParam.VlanRuleParams.SetPcp
2258 setVid := oFsm.actualUniFlowParam.VlanRuleParams.SetVid
mpagenkodff5dda2020-08-28 11:52:01 +00002259 // this defines VID translation scenario: singletagged->singletagged (if not transparent)
dbainbri4d3a0dc2020-12-02 00:33:42 +00002260 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD single tagged translation rule", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002261 "match-pcp": matchPcp, "match-vid": matchVid, "set-pcp": setPcp, "set-vid:": setVid, "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00002262 sliceEvtocdRule := make([]uint8, 16)
2263 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2264 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2265 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2266 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2267 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2268
2269 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
Girish Gowdrae95687a2021-09-08 16:30:58 -07002270 oFsm.actualUniFlowParam.VlanRuleParams.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN
2271 oFsm.actualUniFlowParam.VlanRuleParams.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID
mpagenkodff5dda2020-08-28 11:52:01 +00002272 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2273 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2274
2275 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
Girish Gowdrae95687a2021-09-08 16:30:58 -07002276 oFsm.actualUniFlowParam.VlanRuleParams.TagsToRemove<<cTreatTTROffset| // either 1 or 0
mpagenkodff5dda2020-08-28 11:52:01 +00002277 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
2278 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2279 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
2280
2281 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
Girish Gowdrae95687a2021-09-08 16:30:58 -07002282 oFsm.actualUniFlowParam.VlanRuleParams.SetPcp<<cTreatPrioOffset| // as configured in flow
2283 oFsm.actualUniFlowParam.VlanRuleParams.SetVid<<cTreatVidOffset| //as configured in flow
mpagenkodff5dda2020-08-28 11:52:01 +00002284 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
mpagenko551a4d42020-12-08 18:09:20 +00002285 oFsm.mutexFlowParams.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002286
2287 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002288 EntityID: evtocdID,
mpagenkodff5dda2020-08-28 11:52:01 +00002289 Attributes: me.AttributeValueMap{
2290 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
2291 },
2292 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002293 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002294 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2295 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2296 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002297 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002298 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002299 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2300 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002301 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002302 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
2303 }
mpagenkodff5dda2020-08-28 11:52:01 +00002304 //accept also nil as (error) return value for writing to LastTx
2305 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00002306 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002307 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002308
2309 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002310 err = oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00002311 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002312 logger.Errorw(ctx, "Evtocd set singletagged translation rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002313 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002314 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002315 return fmt.Errorf("evtocd set singletagged translation rule failed %s, error %s", oFsm.deviceID, err)
mpagenkodff5dda2020-08-28 11:52:01 +00002316 }
2317 } else {
2318 //not transparent and not acceptIncrementalEvtoOption untagged/priotagged->singletagged
2319 { // just for local var's
2320 // this defines stacking scenario: untagged->singletagged
dbainbri4d3a0dc2020-12-02 00:33:42 +00002321 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD untagged->singletagged rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00002322 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00002323 sliceEvtocdRule := make([]uint8, 16)
2324 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2325 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2326 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2327 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2328 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2329
2330 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2331 cPrioIgnoreTag<<cFilterPrioOffset| // Not an inner-tag rule
2332 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
2333 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2334 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2335
2336 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
2337 0<<cTreatTTROffset| // Do not pop any tags
2338 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
2339 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2340 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
2341
2342 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
2343 0<<cTreatPrioOffset| // vlan prio set to 0
2344 // (as done in Py code, maybe better option would be setPcp here, which still could be 0?)
Girish Gowdrae95687a2021-09-08 16:30:58 -07002345 oFsm.actualUniFlowParam.VlanRuleParams.SetVid<<cTreatVidOffset| // Outer VID don't care
mpagenkodff5dda2020-08-28 11:52:01 +00002346 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
2347
mpagenko551a4d42020-12-08 18:09:20 +00002348 oFsm.mutexFlowParams.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002349 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002350 EntityID: evtocdID,
mpagenkodff5dda2020-08-28 11:52:01 +00002351 Attributes: me.AttributeValueMap{
2352 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
2353 },
2354 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002355 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002356 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2357 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2358 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002359 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002360 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002361 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2362 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002363 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002364 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
2365 }
mpagenkodff5dda2020-08-28 11:52:01 +00002366 //accept also nil as (error) return value for writing to LastTx
2367 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00002368 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002369 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002370
2371 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002372 err = oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00002373 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002374 logger.Errorw(ctx, "Evtocd set untagged->singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002375 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002376 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002377 return fmt.Errorf("evtocd set untagged->singletagged rule failed %s, error %s", oFsm.deviceID, err)
2378
mpagenkodff5dda2020-08-28 11:52:01 +00002379 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00002380 } // just for local var's
mpagenkodff5dda2020-08-28 11:52:01 +00002381 { // just for local var's
2382 // this defines 'stacking' scenario: priotagged->singletagged
dbainbri4d3a0dc2020-12-02 00:33:42 +00002383 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD priotagged->singletagged rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00002384 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00002385 sliceEvtocdRule := make([]uint8, 16)
2386 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2387 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2388 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2389 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2390 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2391
2392 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2393 cPrioDoNotFilter<<cFilterPrioOffset| // Do not Filter on innerprio
2394 0<<cFilterVidOffset| // filter on inner vid 0 (prioTagged)
2395 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2396 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2397
2398 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
2399 1<<cTreatTTROffset| // pop the prio-tag
2400 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
2401 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2402 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
2403
mpagenko551a4d42020-12-08 18:09:20 +00002404 oFsm.mutexFlowParams.RLock()
mpagenkodff5dda2020-08-28 11:52:01 +00002405 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
2406 cCopyPrioFromInner<<cTreatPrioOffset| // vlan copy from PrioTag
2407 // (as done in Py code, maybe better option would be setPcp here, which still could be PrioCopy?)
Girish Gowdrae95687a2021-09-08 16:30:58 -07002408 oFsm.actualUniFlowParam.VlanRuleParams.SetVid<<cTreatVidOffset| // Outer VID as configured
mpagenkodff5dda2020-08-28 11:52:01 +00002409 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
mpagenko551a4d42020-12-08 18:09:20 +00002410 oFsm.mutexFlowParams.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002411
2412 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002413 EntityID: evtocdID,
mpagenkodff5dda2020-08-28 11:52:01 +00002414 Attributes: me.AttributeValueMap{
2415 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
2416 },
2417 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002418 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002419 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2420 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2421 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002422 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002423 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002424 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2425 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002426 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002427 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
2428 }
mpagenkodff5dda2020-08-28 11:52:01 +00002429 //accept also nil as (error) return value for writing to LastTx
2430 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00002431 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002432 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002433
2434 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002435 err = oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00002436 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002437 logger.Errorw(ctx, "Evtocd set priotagged->singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002438 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002439 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002440 return fmt.Errorf("evtocd set priotagged->singletagged rule failed %s, error %s", oFsm.deviceID, err)
2441
mpagenkodff5dda2020-08-28 11:52:01 +00002442 }
2443 } //just for local var's
2444 }
2445 }
2446
mpagenkofc4f56e2020-11-04 17:17:49 +00002447 // if Config has been done for all EVTOCD entries let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00002448 logger.Debugw(ctx, "EVTOCD set loop finished", log.Fields{"device-id": oFsm.deviceID})
mpagenkof1d21d12021-06-11 13:14:45 +00002449 oFsm.mutexFlowParams.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002450 oFsm.ConfiguredUniFlow++ // one (more) flow configured
mpagenkof1d21d12021-06-11 13:14:45 +00002451 oFsm.mutexFlowParams.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002452 return nil
mpagenkodff5dda2020-08-28 11:52:01 +00002453}
2454
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002455func (oFsm *UniVlanConfigFsm) removeEvtocdEntries(ctx context.Context, aRuleParams cmn.UniVlanRuleParams) {
mpagenkof1d21d12021-06-11 13:14:45 +00002456 oFsm.mutexFlowParams.RLock()
2457 evtocdID := oFsm.evtocdID
2458 oFsm.mutexFlowParams.RUnlock()
2459
mpagenko01e726e2020-10-23 09:45:29 +00002460 // configured Input/Output TPID is not modified again - no influence if no filter is applied
2461 if aRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
2462 //transparent transmission was set
2463 //perhaps the config is not needed for removal,
2464 // but the specific InnerTpid setting is removed in favor of the real default forwarding rule
dbainbri4d3a0dc2020-12-02 00:33:42 +00002465 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD reset to default single tagged rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00002466 "device-id": oFsm.deviceID})
2467 sliceEvtocdRule := make([]uint8, 16)
2468 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2469 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2470 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2471 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2472 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2473
2474 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2475 cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule
2476 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
2477 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2478 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2479
2480 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
2481 0<<cTreatTTROffset| // Do not pop any tags
2482 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
2483 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2484 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
2485
2486 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
2487 cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag
2488 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2489 cDontCareTpid<<cTreatTpidOffset) // copy TPID and DEI
2490
2491 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002492 EntityID: evtocdID,
mpagenko01e726e2020-10-23 09:45:29 +00002493 Attributes: me.AttributeValueMap{
2494 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
2495 },
2496 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002497 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002498 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2499 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2500 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002501 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002502 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002503 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2504 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002505 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002506 return
2507 }
mpagenko01e726e2020-10-23 09:45:29 +00002508 //accept also nil as (error) return value for writing to LastTx
2509 // - this avoids misinterpretation of new received OMCI messages
2510 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002511 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00002512
2513 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002514 err = oFsm.waitforOmciResponse(ctx)
mpagenko01e726e2020-10-23 09:45:29 +00002515 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002516 logger.Errorw(ctx, "Evtocd reset singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002517 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002518 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
mpagenko01e726e2020-10-23 09:45:29 +00002519 return
2520 }
2521 } else {
2522 // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario
mpagenkof1d21d12021-06-11 13:14:45 +00002523 oFsm.mutexFlowParams.RLock()
mpagenko01e726e2020-10-23 09:45:29 +00002524 if oFsm.acceptIncrementalEvtoOption {
mpagenkof1d21d12021-06-11 13:14:45 +00002525 oFsm.mutexFlowParams.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00002526 // this defines VID translation scenario: singletagged->singletagged (if not transparent)
dbainbri4d3a0dc2020-12-02 00:33:42 +00002527 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD clear single tagged translation rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00002528 "device-id": oFsm.deviceID, "match-vlan": aRuleParams.MatchVid})
2529 sliceEvtocdRule := make([]uint8, 16)
2530 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2531 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2532 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2533 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2534 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2535
2536 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2537 aRuleParams.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN
2538 aRuleParams.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID
2539 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2540 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2541
2542 // delete indication for the indicated Filter
2543 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], 0xFFFFFFFF)
2544 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], 0xFFFFFFFF)
2545
2546 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002547 EntityID: evtocdID,
mpagenko01e726e2020-10-23 09:45:29 +00002548 Attributes: me.AttributeValueMap{
2549 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
2550 },
2551 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002552 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002553 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2554 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2555 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002556 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002557 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002558 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2559 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002560 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002561 return
2562 }
mpagenko01e726e2020-10-23 09:45:29 +00002563 //accept also nil as (error) return value for writing to LastTx
2564 // - this avoids misinterpretation of new received OMCI messages
2565 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002566 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00002567
2568 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002569 err = oFsm.waitforOmciResponse(ctx)
mpagenko01e726e2020-10-23 09:45:29 +00002570 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002571 logger.Errorw(ctx, "Evtocd clear singletagged translation rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002572 log.Fields{"device-id": oFsm.deviceID, "match-vlan": aRuleParams.MatchVid})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002573 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
mpagenko01e726e2020-10-23 09:45:29 +00002574 return
2575 }
2576 } else {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002577 // VOL-3685
2578 // NOTE: With ALPHA ONUs it was seen that just resetting a particular entry in the EVTOCD table
2579 // and re-configuring a new entry would not work. The old entry is removed and new entry is created
2580 // indeed, but the traffic landing upstream would carry old vlan sometimes.
2581 // This is only a WORKAROUND which basically deletes the entire EVTOCD ME and re-creates it again
2582 // later when the flow is being re-installed.
2583 // Of course this is applicable to case only where single service (or single tcont) is in use and
2584 // there is only one service vlan (oFsm.acceptIncrementalEvtoOption is false in this case).
2585 // Interstingly this problem has not been observed in multi-tcont (or multi-service) scenario (in
2586 // which case the oFsm.acceptIncrementalEvtoOption is set to true).
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002587 if oFsm.ConfiguredUniFlow == 1 && !oFsm.acceptIncrementalEvtoOption {
mpagenkof1d21d12021-06-11 13:14:45 +00002588 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00002589 logger.Debugw(ctx, "UniVlanConfigFsm Tx Remove::EVTOCD", log.Fields{"device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002590 // When there are no more EVTOCD vlan configurations on the ONU and acceptIncrementalEvtoOption
2591 // is not enabled, delete the EVTOCD ME.
mpagenko01e726e2020-10-23 09:45:29 +00002592 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002593 EntityID: evtocdID,
mpagenko01e726e2020-10-23 09:45:29 +00002594 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002595 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002596 meInstance, err := oFsm.pOmciCC.SendDeleteEvtocd(log.WithSpanFromContext(context.TODO(), ctx),
2597 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2598 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002599 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002600 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002601 logger.Errorw(ctx, "DeleteEvtocdVar delete failed, aborting UniVlanConfigFsm!",
2602 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002603 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002604 return
2605 }
mpagenko01e726e2020-10-23 09:45:29 +00002606 //accept also nil as (error) return value for writing to LastTx
2607 // - this avoids misinterpretation of new received OMCI messages
2608 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002609 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00002610
2611 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002612 err = oFsm.waitforOmciResponse(ctx)
mpagenko01e726e2020-10-23 09:45:29 +00002613 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002614 logger.Errorw(ctx, "Evtocd delete rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002615 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002616 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
mpagenko01e726e2020-10-23 09:45:29 +00002617 return
2618 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002619 } else {
2620 // NOTE : We should ideally never ether this section when oFsm.acceptIncrementalEvtoOption is set to false
2621 // This is true for only ATT/DT workflow
dbainbri4d3a0dc2020-12-02 00:33:42 +00002622 logger.Debugw(ctx, "UniVlanConfigFsm: Remove EVTOCD set operation",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002623 log.Fields{"configured-flow": oFsm.ConfiguredUniFlow, "incremental-evto": oFsm.acceptIncrementalEvtoOption})
mpagenkof1d21d12021-06-11 13:14:45 +00002624 oFsm.mutexFlowParams.RUnlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002625 //not transparent and not acceptIncrementalEvtoOption: untagged/priotagged->singletagged
2626 { // just for local var's
2627 // this defines stacking scenario: untagged->singletagged
2628 //TODO!! in theory there could be different rules running in setting different PCP/VID'S
2629 // for untagged/priotagged, last rule wins (and remains the only one), maybe that should be
2630 // checked already at flow-add (and rejected) - to be observed if such is possible in Voltha
2631 // delete now assumes there is only one such rule!
dbainbri4d3a0dc2020-12-02 00:33:42 +00002632 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD reset untagged rule to default", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002633 "device-id": oFsm.deviceID})
2634 sliceEvtocdRule := make([]uint8, 16)
2635 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2636 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2637 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2638 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2639 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
mpagenko01e726e2020-10-23 09:45:29 +00002640
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002641 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2642 cPrioIgnoreTag<<cFilterPrioOffset| // Not an inner-tag rule
2643 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
2644 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2645 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
mpagenko01e726e2020-10-23 09:45:29 +00002646
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002647 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
2648 0<<cTreatTTROffset| // Do not pop any tags
2649 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
2650 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2651 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
mpagenko01e726e2020-10-23 09:45:29 +00002652
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002653 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
2654 cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag
2655 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2656 cDontCareTpid<<cTreatTpidOffset) // copy TPID and DEI
mpagenko01e726e2020-10-23 09:45:29 +00002657
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002658 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002659 EntityID: evtocdID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002660 Attributes: me.AttributeValueMap{
2661 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
2662 },
2663 }
Girish Gowdra754ffb12021-06-30 16:30:12 -07002664 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002665 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(context.TODO(),
2666 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2667 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002668 if err != nil {
Girish Gowdra754ffb12021-06-30 16:30:12 -07002669 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002670 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2671 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002672 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002673 return
2674 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002675 //accept also nil as (error) return value for writing to LastTx
2676 // - this avoids misinterpretation of new received OMCI messages
2677 oFsm.pLastTxMeInstance = meInstance
Girish Gowdra754ffb12021-06-30 16:30:12 -07002678 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002679
2680 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002681 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002682 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002683 logger.Errorw(ctx, "Evtocd reset untagged rule to default failed, aborting VlanConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002684 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002685 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002686 return
2687 }
2688 } // just for local var's
2689 { // just for local var's
2690 // this defines 'stacking' scenario: priotagged->singletagged
dbainbri4d3a0dc2020-12-02 00:33:42 +00002691 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD delete priotagged rule", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002692 "device-id": oFsm.deviceID})
2693 sliceEvtocdRule := make([]uint8, 16)
2694 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2695 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2696 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2697 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2698 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2699
2700 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2701 cPrioDoNotFilter<<cFilterPrioOffset| // Do not Filter on innerprio
2702 0<<cFilterVidOffset| // filter on inner vid 0 (prioTagged)
2703 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2704 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2705
2706 // delete indication for the indicated Filter
2707 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], 0xFFFFFFFF)
2708 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], 0xFFFFFFFF)
2709
2710 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002711 EntityID: evtocdID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002712 Attributes: me.AttributeValueMap{
2713 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
2714 },
2715 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002716 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002717 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2718 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2719 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002720 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002721 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002722 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2723 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002724 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002725 return
2726 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002727 //accept also nil as (error) return value for writing to LastTx
2728 // - this avoids misinterpretation of new received OMCI messages
2729 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002730 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002731
2732 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002733 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002734 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002735 logger.Errorw(ctx, "Evtocd delete priotagged rule failed, aborting VlanConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002736 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002737 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002738 return
2739 }
mpagenko01e726e2020-10-23 09:45:29 +00002740 }
2741 } //just for local var's
2742 }
2743 }
mpagenkofc4f56e2020-11-04 17:17:49 +00002744 // if Config has been done for all EVTOCD entries let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00002745 logger.Debugw(ctx, "EVTOCD filter remove loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002746 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvRemFlowDone, aRuleParams.TpID)
mpagenko01e726e2020-10-23 09:45:29 +00002747}
2748
dbainbri4d3a0dc2020-12-02 00:33:42 +00002749func (oFsm *UniVlanConfigFsm) waitforOmciResponse(ctx context.Context) error {
mpagenko7d6bb022021-03-11 15:07:55 +00002750 oFsm.mutexIsAwaitingResponse.Lock()
mpagenkocf48e452021-04-23 09:23:00 +00002751 if oFsm.isCanceled {
2752 // FSM already canceled before entering wait
2753 logger.Debugw(ctx, "UniVlanConfigFsm wait-for-multi-entity-response aborted (on enter)", log.Fields{"for device-id": oFsm.deviceID})
2754 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002755 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenkocf48e452021-04-23 09:23:00 +00002756 }
mpagenko7d6bb022021-03-11 15:07:55 +00002757 oFsm.isAwaitingResponse = true
2758 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002759 select {
Himani Chawla26e555c2020-08-31 12:30:20 +05302760 // maybe be also some outside cancel (but no context modeled for the moment ...)
mpagenkodff5dda2020-08-28 11:52:01 +00002761 // case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +00002762 // logger.Infow(ctx,"LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +00002763 case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //AS FOR THE OTHER OMCI FSM's
dbainbri4d3a0dc2020-12-02 00:33:42 +00002764 logger.Warnw(ctx, "UniVlanConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00002765 oFsm.mutexIsAwaitingResponse.Lock()
2766 oFsm.isAwaitingResponse = false
2767 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00002768 return fmt.Errorf("uniVlanConfigFsm multi entity timeout %s", oFsm.deviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00002769 case success := <-oFsm.omciMIdsResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +05302770 if success {
mpagenkocf48e452021-04-23 09:23:00 +00002771 logger.Debugw(ctx, "UniVlanConfigFsm multi entity response received", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00002772 oFsm.mutexIsAwaitingResponse.Lock()
2773 oFsm.isAwaitingResponse = false
2774 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002775 return nil
2776 }
mpagenko7d6bb022021-03-11 15:07:55 +00002777 // waiting was aborted (probably on external request)
mpagenkocf48e452021-04-23 09:23:00 +00002778 logger.Debugw(ctx, "UniVlanConfigFsm wait-for-multi-entity-response aborted", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00002779 oFsm.mutexIsAwaitingResponse.Lock()
2780 oFsm.isAwaitingResponse = false
2781 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002782 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenkodff5dda2020-08-28 11:52:01 +00002783 }
2784}
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002785
mpagenko551a4d42020-12-08 18:09:20 +00002786func (oFsm *UniVlanConfigFsm) performSettingMulticastME(ctx context.Context, tpID uint8, multicastGemPortID uint16, vlanID uint32) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002787 logger.Debugw(ctx, "Setting Multicast MEs", log.Fields{"device-id": oFsm.deviceID, "tpID": tpID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002788 "multicastGemPortID": multicastGemPortID, "vlanID": vlanID})
dbainbri4d3a0dc2020-12-02 00:33:42 +00002789 errCreateMOP := oFsm.performCreatingMulticastOperationProfile(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002790 if errCreateMOP != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002791 logger.Errorw(ctx, "MulticastOperationProfile create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002792 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002793 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002794 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, errCreateMOP)
2795 }
2796
dbainbri4d3a0dc2020-12-02 00:33:42 +00002797 errSettingMOP := oFsm.performSettingMulticastOperationProfile(ctx, multicastGemPortID, vlanID)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002798 if errSettingMOP != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002799 logger.Errorw(ctx, "MulticastOperationProfile setting failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002800 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002801 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002802 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, errSettingMOP)
2803 }
2804
dbainbri4d3a0dc2020-12-02 00:33:42 +00002805 errCreateMSCI := oFsm.performCreatingMulticastSubscriberConfigInfo(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002806 if errCreateMSCI != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002807 logger.Errorw(ctx, "MulticastOperationProfile setting failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002808 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002809 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002810 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, errCreateMSCI)
2811 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002812 macBpCdEID, errMacBpCdEID := cmn.GenerateMcastANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo))
Mahir Gunyel6781f962021-05-16 23:30:08 -07002813 if errMacBpCdEID != nil {
2814 logger.Errorw(ctx, "MulticastMacBridgePortConfigData entity id generation failed, aborting AniConfig FSM!",
2815 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002816 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
Mahir Gunyel6781f962021-05-16 23:30:08 -07002817 return fmt.Errorf("generateMcastANISideMBPCDEID responseError %s, error %s", oFsm.deviceID, errMacBpCdEID)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002818
Mahir Gunyel6781f962021-05-16 23:30:08 -07002819 }
2820 logger.Debugw(ctx, "UniVlanConfigFsm set macBpCdEID for mcast", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002821 "EntitytId": strconv.FormatInt(int64(macBpCdEID), 16), "macBpNo": oFsm.pOnuUniPort.MacBpNo,
2822 "in state": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002823 meParams := me.ParamData{
Mahir Gunyel6781f962021-05-16 23:30:08 -07002824 EntityID: macBpCdEID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002825 Attributes: me.AttributeValueMap{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002826 "BridgeIdPointer": cmn.MacBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.MacBpNo),
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002827 "PortNum": 0xf0, //fixed unique ANI side indication
2828 "TpType": 6, //MCGemIWTP
2829 "TpPointer": multicastGemPortID,
2830 },
2831 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002832 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002833 meInstance, err := oFsm.pOmciCC.SendCreateMBPConfigDataVar(context.TODO(),
2834 oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002835 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002836 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002837 logger.Errorw(ctx, "MBPConfigDataVar create failed, aborting AniConfig FSM!",
2838 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002839 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002840 return fmt.Errorf("creatingMulticastSubscriberConfigInfo createError #{oFsm.deviceID}, error #{err}")
2841 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002842 //accept also nil as (error) return value for writing to LastTx
2843 // - this avoids misinterpretation of new received OMCI messages
2844 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002845 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002846 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002847 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002848 logger.Errorw(ctx, "CreateMBPConfigData failed, aborting AniConfig FSM!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002849 log.Fields{"device-id": oFsm.deviceID, "MBPConfigDataID": cmn.MacBridgeServiceProfileEID})
2850 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002851 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, err)
2852 }
2853
2854 // ==> Start creating VTFD for mcast vlan
2855
2856 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
2857 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
Mahir Gunyel6781f962021-05-16 23:30:08 -07002858 mcastVtfdID := macBpCdEID
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002859
dbainbri4d3a0dc2020-12-02 00:33:42 +00002860 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD for mcast", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002861 "EntitytId": strconv.FormatInt(int64(mcastVtfdID), 16), "mcastVlanID": vlanID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002862 "in state": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002863 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
2864
2865 // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME
2866 // VTFD has to be created afresh with a new entity ID that has the same entity ID as the MBPCD ME for every
2867 // new vlan associated with a different TP.
2868 vtfdFilterList[0] = uint16(vlanID)
2869
2870 meParams = me.ParamData{
2871 EntityID: mcastVtfdID,
2872 Attributes: me.AttributeValueMap{
2873 "VlanFilterList": vtfdFilterList,
2874 "ForwardOperation": uint8(0x10), //VID investigation
2875 "NumberOfEntries": oFsm.numVlanFilterEntries,
2876 },
2877 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002878 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002879 meInstance, err = oFsm.pOmciCC.SendCreateVtfdVar(context.TODO(),
2880 oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002881 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002882 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002883 logger.Errorw(ctx, "CreateVtfdVar create failed, aborting UniVlanConfigFsm!",
2884 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002885 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002886 return fmt.Errorf("createMcastVlanFilterData creationError %s, error %s", oFsm.deviceID, err)
2887 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002888 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002889 oFsm.mutexPLastTxMeInstance.Unlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00002890 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002891 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002892 logger.Errorw(ctx, "CreateMcastVlanFilterData failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002893 log.Fields{"device-id": oFsm.deviceID, "mcastVtfdID": mcastVtfdID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002894 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002895 return fmt.Errorf("createMcastVlanFilterData responseError %s, error %s", oFsm.deviceID, err)
2896 }
2897
2898 return nil
2899}
2900
dbainbri4d3a0dc2020-12-02 00:33:42 +00002901func (oFsm *UniVlanConfigFsm) performCreatingMulticastSubscriberConfigInfo(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002902 instID, err := cmn.GenerateUNISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002903 if err != nil {
Mahir Gunyel6781f962021-05-16 23:30:08 -07002904 logger.Errorw(ctx, "error generrating me instance id",
2905 log.Fields{"device-id": oFsm.deviceID, "error": err})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002906 return err
2907 }
Mahir Gunyel6781f962021-05-16 23:30:08 -07002908 logger.Debugw(ctx, "UniVlanConfigFsm create MulticastSubscriberConfigInfo",
2909 log.Fields{"device-id": oFsm.deviceID, "EntityId": instID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002910 meParams := me.ParamData{
2911 EntityID: instID,
2912 Attributes: me.AttributeValueMap{
2913 "MeType": 0,
2914 //Direct reference to the Operation profile
2915 //TODO ANI side used on UNI side, not the clearest option.
ozgecanetsia5c88b762021-03-23 10:27:15 +03002916 "MulticastOperationsProfilePointer": instID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002917 },
2918 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002919 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002920 meInstance, err := oFsm.pOmciCC.SendCreateMulticastSubConfigInfoVar(context.TODO(),
2921 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2922 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002923 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002924 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002925 logger.Errorw(ctx, "CreateMulticastSubConfigInfoVar create failed, aborting UniVlanConfigFSM!",
2926 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002927 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002928 return fmt.Errorf("creatingMulticastSubscriberConfigInfo interface creationError %s, error %s",
2929 oFsm.deviceID, err)
2930 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002931 //accept also nil as (error) return value for writing to LastTx
2932 // - this avoids misinterpretation of new received OMCI messages
2933 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002934 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002935 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00002936 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002937 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002938 logger.Errorw(ctx, "CreateMulticastSubConfigInfo create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002939 log.Fields{"device-id": oFsm.deviceID, "MulticastSubConfigInfo": instID})
2940 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s", oFsm.deviceID)
2941 }
2942 return nil
2943}
2944
dbainbri4d3a0dc2020-12-02 00:33:42 +00002945func (oFsm *UniVlanConfigFsm) performCreatingMulticastOperationProfile(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002946 instID, err := cmn.GenerateUNISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo))
ozgecanetsia5c88b762021-03-23 10:27:15 +03002947 if err != nil {
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03002948 logger.Errorw(ctx, "error generating me instance id",
2949 log.Fields{"device-id": oFsm.deviceID, "error": err})
ozgecanetsia5c88b762021-03-23 10:27:15 +03002950 return err
2951 }
Mahir Gunyel6781f962021-05-16 23:30:08 -07002952 logger.Debugw(ctx, "UniVlanConfigFsm create MulticastOperationProfile",
2953 log.Fields{"device-id": oFsm.deviceID, "EntityId": instID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002954 meParams := me.ParamData{
2955 EntityID: instID,
2956 Attributes: me.AttributeValueMap{
2957 "IgmpVersion": 2,
2958 "IgmpFunction": 0,
2959 //0 means false
2960 "ImmediateLeave": 0,
2961 "Robustness": 2,
2962 "QuerierIp": 0,
2963 "QueryInterval": 125,
2964 "QuerierMaxResponseTime": 100,
2965 "LastMemberResponseTime": 10,
2966 //0 means false
2967 "UnauthorizedJoinBehaviour": 0,
2968 },
2969 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002970 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002971 meInstance, err := oFsm.pOmciCC.SendCreateMulticastOperationProfileVar(context.TODO(),
2972 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2973 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002974 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002975 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002976 logger.Errorw(ctx, "CreateMulticastOperationProfileVar create failed, aborting UniVlanConfigFsm!",
2977 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002978 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002979 return fmt.Errorf("createMulticastOperationProfileVar responseError %s, error %s", oFsm.deviceID, err)
2980 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002981 //accept also nil as (error) return value for writing to LastTx
2982 // - this avoids misinterpretation of new received OMCI messages
2983 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002984 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002985 //verify response
ozgecanetsia5c88b762021-03-23 10:27:15 +03002986 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002987 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002988 logger.Errorw(ctx, "CreateMulticastOperationProfile create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002989 log.Fields{"device-id": oFsm.deviceID, "MulticastOperationProfileID": instID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03002990 return fmt.Errorf("createMulticastOperationProfile responseError %s, error %s", oFsm.deviceID, err)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002991 }
2992 return nil
2993}
2994
dbainbri4d3a0dc2020-12-02 00:33:42 +00002995func (oFsm *UniVlanConfigFsm) performSettingMulticastOperationProfile(ctx context.Context, multicastGemPortID uint16, vlanID uint32) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002996 instID, err := cmn.GenerateUNISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo))
ozgecanetsia5c88b762021-03-23 10:27:15 +03002997 if err != nil {
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03002998 logger.Errorw(ctx, "error generating me instance id",
2999 log.Fields{"device-id": oFsm.deviceID, "error": err})
ozgecanetsia5c88b762021-03-23 10:27:15 +03003000 return err
3001 }
Mahir Gunyel6781f962021-05-16 23:30:08 -07003002 logger.Debugw(ctx, "UniVlanConfigFsm set MulticastOperationProfile",
3003 log.Fields{"device-id": oFsm.deviceID, "EntityId": instID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003004 //TODO check that this is correct
3005 // Table control
3006 //setCtrl = 1
3007 //rowPartId = 0
3008 //test = 0
3009 //rowKey = 0
3010 tableCtrlStr := "0100000000000000"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003011 tableCtrl := cmn.AsByteSlice(tableCtrlStr)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003012 dynamicAccessCL := make([]uint8, 24)
3013 copy(dynamicAccessCL, tableCtrl)
3014 //Multicast GemPortId
3015 binary.BigEndian.PutUint16(dynamicAccessCL[2:], multicastGemPortID)
3016 // python version waits for installation of flows, see line 723 onward of
3017 // brcm_openomci_onu_handler.py
3018 binary.BigEndian.PutUint16(dynamicAccessCL[4:], uint16(vlanID))
3019 //Source IP all to 0
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003020 binary.BigEndian.PutUint32(dynamicAccessCL[6:], cmn.IPToInt32(net.IPv4(0, 0, 0, 0)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003021 //TODO start and end are hardcoded, get from TP
3022 // Destination IP address start of range
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003023 binary.BigEndian.PutUint32(dynamicAccessCL[10:], cmn.IPToInt32(net.IPv4(225, 0, 0, 0)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003024 // Destination IP address end of range
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003025 binary.BigEndian.PutUint32(dynamicAccessCL[14:], cmn.IPToInt32(net.IPv4(239, 255, 255, 255)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003026 //imputed group bandwidth
3027 binary.BigEndian.PutUint16(dynamicAccessCL[18:], 0)
3028
3029 meParams := me.ParamData{
3030 EntityID: instID,
3031 Attributes: me.AttributeValueMap{
3032 "DynamicAccessControlListTable": dynamicAccessCL,
3033 },
3034 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003035 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003036 meInstance, err := oFsm.pOmciCC.SendSetMulticastOperationProfileVar(context.TODO(),
3037 oFsm.pDeviceHandler.GetOmciTimeout(), true,
3038 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03003039 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003040 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03003041 logger.Errorw(ctx, "SetMulticastOperationProfileVar set failed, aborting UniVlanConfigFsm!",
3042 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003043 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03003044 return fmt.Errorf("setMulticastOperationProfile responseError %s, error %s", oFsm.deviceID, err)
3045 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003046 //accept also nil as (error) return value for writing to LastTx
3047 // - this avoids misinterpretation of new received OMCI messages
3048 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003049 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003050 //verify response
ozgecanetsia5c88b762021-03-23 10:27:15 +03003051 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003052 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003053 logger.Errorw(ctx, "CreateMulticastOperationProfile create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003054 log.Fields{"device-id": oFsm.deviceID, "MulticastOperationProfileID": instID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03003055 return fmt.Errorf("createMulticastOperationProfile responseError %s, error %s", oFsm.deviceID, err)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003056 }
3057 return nil
3058}
Girish Gowdra26a40922021-01-29 17:14:34 -08003059
ozgecanetsia82b91a62021-05-21 18:54:49 +03003060func (oFsm *UniVlanConfigFsm) createTrafficDescriptor(ctx context.Context, aMeter *voltha.OfpMeterConfig,
3061 tpID uint8, uniID uint8, gemPortID uint16) error {
3062 logger.Infow(ctx, "Starting create traffic descriptor", log.Fields{"device-id": oFsm.deviceID, "uniID": uniID, "tpID": tpID})
3063 // uniTPKey generate id to Traffic Descriptor ME. We need to create two of them. They should be unique. Because of that
3064 // I created unique TD ID by flow direction.
3065 // TODO! Traffic descriptor ME ID will check
3066 trafficDescriptorID := gemPortID
3067 if aMeter == nil {
3068 return fmt.Errorf("meter not found %s", oFsm.deviceID)
3069 }
3070 trafficShapingInfo, err := meters.GetTrafficShapingInfo(ctx, aMeter)
3071 if err != nil {
3072 logger.Errorw(ctx, "Traffic Shaping Info get failed", log.Fields{"device-id": oFsm.deviceID})
3073 return err
3074 }
3075 cir := trafficShapingInfo.Cir + trafficShapingInfo.Gir
3076 cbs := trafficShapingInfo.Cbs
3077 pir := trafficShapingInfo.Pir
3078 pbs := trafficShapingInfo.Pbs
3079
3080 logger.Infow(ctx, "cir-pir-cbs-pbs", log.Fields{"device-id": oFsm.deviceID, "cir": cir, "pir": pir, "cbs": cbs, "pbs": pbs})
3081 meParams := me.ParamData{
3082 EntityID: trafficDescriptorID,
3083 Attributes: me.AttributeValueMap{
3084 "Cir": cir,
3085 "Pir": pir,
3086 "Cbs": cbs,
3087 "Pbs": pbs,
3088 "ColourMode": 1,
3089 "IngressColourMarking": 3,
3090 "EgressColourMarking": 3,
3091 "MeterType": 1,
3092 },
3093 }
Girish Gowdra754ffb12021-06-30 16:30:12 -07003094 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003095 meInstance, errCreateTD := oFsm.pOmciCC.SendCreateTDVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(),
3096 true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsia82b91a62021-05-21 18:54:49 +03003097 if errCreateTD != nil {
Girish Gowdra754ffb12021-06-30 16:30:12 -07003098 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia82b91a62021-05-21 18:54:49 +03003099 logger.Errorw(ctx, "Traffic Descriptor create failed", log.Fields{"device-id": oFsm.deviceID})
3100 return err
3101 }
3102 oFsm.pLastTxMeInstance = meInstance
Girish Gowdra754ffb12021-06-30 16:30:12 -07003103 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia82b91a62021-05-21 18:54:49 +03003104 err = oFsm.waitforOmciResponse(ctx)
3105 if err != nil {
3106 logger.Errorw(ctx, "Traffic Descriptor create failed, aborting VlanConfig FSM!", log.Fields{"device-id": oFsm.deviceID})
3107 return err
3108 }
3109
Girish Gowdra09e5f212021-09-30 16:28:36 -07003110 // Note: in the below request the gemport entity id is same as the gemport id and the traffic descriptor entity id is also same as gemport id
3111 err = oFsm.setTrafficDescriptorToGemPortNWCTP(ctx, gemPortID, gemPortID)
ozgecanetsia82b91a62021-05-21 18:54:49 +03003112 if err != nil {
3113 logger.Errorw(ctx, "Traffic Descriptor set failed to Gem Port Network CTP, aborting VlanConfig FSM!", log.Fields{"device-id": oFsm.deviceID})
3114 return err
3115 }
3116 logger.Infow(ctx, "Set TD Info to GemPortNWCTP successfully", log.Fields{"device-id": oFsm.deviceID, "gem-port-id": gemPortID, "td-id": trafficDescriptorID})
3117
3118 return nil
3119}
3120
Girish Gowdra09e5f212021-09-30 16:28:36 -07003121func (oFsm *UniVlanConfigFsm) setTrafficDescriptorToGemPortNWCTP(ctx context.Context, gemPortEntityID uint16, trafficDescriptorEntityID uint16) error {
3122 logger.Debugw(ctx, "Starting Set Traffic Descriptor to GemPortNWCTP",
3123 log.Fields{"device-id": oFsm.deviceID, "gem-port-entity-id": gemPortEntityID, "traffic-descriptor-entity-id": trafficDescriptorEntityID})
ozgecanetsia82b91a62021-05-21 18:54:49 +03003124 meParams := me.ParamData{
Girish Gowdra09e5f212021-09-30 16:28:36 -07003125 EntityID: gemPortEntityID,
ozgecanetsia82b91a62021-05-21 18:54:49 +03003126 Attributes: me.AttributeValueMap{
Girish Gowdra09e5f212021-09-30 16:28:36 -07003127 "TrafficDescriptorProfilePointerForUpstream": trafficDescriptorEntityID,
ozgecanetsia82b91a62021-05-21 18:54:49 +03003128 },
3129 }
Girish Gowdra754ffb12021-06-30 16:30:12 -07003130 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003131 meInstance, err := oFsm.pOmciCC.SendSetGemNCTPVar(log.WithSpanFromContext(context.TODO(), ctx),
3132 oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsia82b91a62021-05-21 18:54:49 +03003133 if err != nil {
Girish Gowdra754ffb12021-06-30 16:30:12 -07003134 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia82b91a62021-05-21 18:54:49 +03003135 logger.Errorw(ctx, "GemNCTP set failed", log.Fields{"device-id": oFsm.deviceID})
3136 return err
3137 }
3138 oFsm.pLastTxMeInstance = meInstance
Girish Gowdra754ffb12021-06-30 16:30:12 -07003139 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia82b91a62021-05-21 18:54:49 +03003140 err = oFsm.waitforOmciResponse(ctx)
3141 if err != nil {
3142 logger.Errorw(ctx, "Upstream Traffic Descriptor set failed, aborting VlanConfig FSM!", log.Fields{"device-id": oFsm.deviceID})
3143 return err
3144 }
3145 return nil
3146}
3147
Girish Gowdra26a40922021-01-29 17:14:34 -08003148// IsFlowRemovePending returns true if there are pending flows to remove, else false.
mpagenkobb47bc22021-04-20 13:29:09 +00003149func (oFsm *UniVlanConfigFsm) IsFlowRemovePending(aFlowDeleteChannel chan<- bool) bool {
3150 oFsm.mutexFlowParams.Lock()
3151 defer oFsm.mutexFlowParams.Unlock()
3152 if len(oFsm.uniRemoveFlowsSlice) > 0 {
3153 //flow removal is still ongoing/pending
3154 oFsm.signalOnFlowDelete = true
3155 oFsm.flowDeleteChannel = aFlowDeleteChannel
3156 return true
3157 }
3158 return false
Girish Gowdra26a40922021-01-29 17:14:34 -08003159}
Holger Hildebrandt968eb8f2021-09-17 07:41:12 +00003160
3161func (oFsm *UniVlanConfigFsm) reconcileVlanFilterList(ctx context.Context, aSetVid uint16) {
3162 // VOL-4342 - reconcile vlanFilterList[] for possible later flow removal
3163 if aSetVid == uint16(of.OfpVlanId_OFPVID_PRESENT) {
3164 logger.Debugw(ctx, "reconciling - transparent setup: no VTFD config was required",
3165 log.Fields{"device-id": oFsm.deviceID})
3166 } else {
3167 oFsm.vlanFilterList[oFsm.numVlanFilterEntries] = aSetVid
3168 logger.Debugw(ctx, "reconciling - Vid of VTFD stored in list", log.Fields{
3169 "index": oFsm.numVlanFilterEntries,
3170 "vid": strconv.FormatInt(int64(oFsm.vlanFilterList[oFsm.numVlanFilterEntries]), 16),
3171 "device-id": oFsm.deviceID})
3172 oFsm.numVlanFilterEntries++
3173 }
3174}
Girish Gowdrae95687a2021-09-08 16:30:58 -07003175
3176// PushReponseOnFlowResponseChannel pushes response on the response channel if available
3177func (oFsm *UniVlanConfigFsm) PushReponseOnFlowResponseChannel(ctx context.Context, respChan *chan error, err error) {
3178 if respChan != nil {
3179 // Do it in a non blocking fashion, so that in case the flow handler routine has shutdown for any reason, we do not block here
3180 select {
3181 case *respChan <- err:
3182 logger.Debugw(ctx, "submitted-response-for-flow", log.Fields{"device-id": oFsm.deviceID, "err": err})
3183 default:
3184 }
3185 }
3186}