blob: 394602b9d704f66d5252e54b87900219a6eeb8c2 [file] [log] [blame]
mpagenkodff5dda2020-08-28 11:52:01 +00001/*
Joey Armstronge8c091f2023-01-17 16:56:26 -05002 * Copyright 2020-2023 Open Networking Foundation (ONF) and the ONF Contributors
mpagenkodff5dda2020-08-28 11:52:01 +00003 *
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"
ozgecanetsia82b91a62021-05-21 18:54:49 +030031
mpagenko01e726e2020-10-23 09:45:29 +000032 gp "github.com/google/gopacket"
mpagenkodff5dda2020-08-28 11:52:01 +000033 "github.com/looplab/fsm"
mpagenko836a1fd2021-11-01 16:12:42 +000034 "github.com/opencord/omci-lib-go/v2"
35 me "github.com/opencord/omci-lib-go/v2/generated"
khenaidoo7d3c5582021-08-11 18:09:44 -040036 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000037 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
38 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb"
khenaidoo7d3c5582021-08-11 18:09:44 -040039 of "github.com/opencord/voltha-protos/v5/go/openflow_13"
mpagenkodff5dda2020-08-28 11:52:01 +000040)
41
42const (
43 // internal predefined values
44 cDefaultDownstreamMode = 0
45 cDefaultTpid = 0x8100
mpagenko01e726e2020-10-23 09:45:29 +000046 cVtfdTableSize = 12 //as per G.988
47 cMaxAllowedFlows = cVtfdTableSize //which might be under discussion, for the moment connected to limit of VLAN's within VTFD
mpagenkodff5dda2020-08-28 11:52:01 +000048)
49
50const (
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000051 // internal offsets for requestEvent according to definition in onu_device_entry::cmn.OnuDeviceEvent
mpagenkof1fc3862021-02-16 10:09:52 +000052 cDeviceEventOffsetAddWithKvStore = 0 //OmciVlanFilterAddDone - OmciVlanFilterAddDone cannot use because of lint
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000053 cDeviceEventOffsetAddNoKvStore = cmn.OmciVlanFilterAddDoneNoKvStore - cmn.OmciVlanFilterAddDone
54 cDeviceEventOffsetRemoveWithKvStore = cmn.OmciVlanFilterRemDone - cmn.OmciVlanFilterAddDone
55 cDeviceEventOffsetRemoveNoKvStore = cmn.OmciVlanFilterRemDoneNoKvStore - cmn.OmciVlanFilterAddDone
mpagenkof1fc3862021-02-16 10:09:52 +000056)
57
58const (
mpagenkodff5dda2020-08-28 11:52:01 +000059 // bit mask offsets for EVTOCD VlanTaggingOperationTable related to 32 bits (4 bytes)
60 cFilterPrioOffset = 28
61 cFilterVidOffset = 15
62 cFilterTpidOffset = 12
63 cFilterEtherTypeOffset = 0
64 cTreatTTROffset = 30
65 cTreatPrioOffset = 16
66 cTreatVidOffset = 3
67 cTreatTpidOffset = 0
68)
69const (
70 // byte offsets for EVTOCD VlanTaggingOperationTable related to overall 16 byte size with slice byte 0 as first Byte (MSB)
71 cFilterOuterOffset = 0
72 cFilterInnerOffset = 4
73 cTreatOuterOffset = 8
74 cTreatInnerOffset = 12
75)
76const (
77 // basic values used within EVTOCD VlanTaggingOperationTable in respect to their bitfields
78 cPrioIgnoreTag uint32 = 15
79 cPrioDefaultFilter uint32 = 14
80 cPrioDoNotFilter uint32 = 8
81 cDoNotFilterVid uint32 = 4096
82 cDoNotFilterTPID uint32 = 0
83 cDoNotFilterEtherType uint32 = 0
84 cDoNotAddPrio uint32 = 15
85 cCopyPrioFromInner uint32 = 8
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +053086 cCopyPrioFromOuter uint32 = 9
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
mpagenkocf48e452021-04-23 09:23:00 +0000160 isCanceled bool
mpagenko7d6bb022021-03-11 15:07:55 +0000161 isAwaitingResponse bool
162 mutexIsAwaitingResponse sync.RWMutex
mpagenko551a4d42020-12-08 18:09:20 +0000163 mutexFlowParams sync.RWMutex
mpagenkobb47bc22021-04-20 13:29:09 +0000164 chCookieDeleted chan bool //channel to indicate that a specific cookie (related to the active rule) was deleted
Girish Gowdrae95687a2021-09-08 16:30:58 -0700165 actualUniFlowParam cmn.UniVlanFlowParams
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000166 uniVlanFlowParamsSlice []cmn.UniVlanFlowParams
mpagenko01e726e2020-10-23 09:45:29 +0000167 uniRemoveFlowsSlice []uniRemoveVlanFlowParams
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000168 NumUniFlows uint8 // expected number of flows should be less than 12
169 ConfiguredUniFlow uint8
mpagenko01e726e2020-10-23 09:45:29 +0000170 numRemoveFlows uint8
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000171 numVlanFilterEntries uint8
mpagenko01e726e2020-10-23 09:45:29 +0000172 vlanFilterList [cVtfdTableSize]uint16
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000173 evtocdID uint16
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000174 mutexPLastTxMeInstance sync.RWMutex
mpagenko01e726e2020-10-23 09:45:29 +0000175 pLastTxMeInstance *me.ManagedEntity
mpagenkofc4f56e2020-11-04 17:17:49 +0000176 requestEventOffset uint8
mpagenko551a4d42020-12-08 18:09:20 +0000177 TpIDWaitingFor uint8
mpagenkobb47bc22021-04-20 13:29:09 +0000178 signalOnFlowDelete bool
179 flowDeleteChannel chan<- bool
mpagenkof1fc3862021-02-16 10:09:52 +0000180 //cookie value that indicates that a rule to add is delayed by waiting for deletion of some other existing rule with the same cookie
181 delayNewRuleCookie uint64
Andrea Campanellaf66ac6e2021-05-24 17:09:20 +0200182 // Used to indicate if the FSM is for a reconciling flow and if it's the last flow to be reconciled
183 // thus notification needs to be sent on chan.
184 lastFlowToReconcile bool
mpagenkodff5dda2020-08-28 11:52:01 +0000185}
186
mpagenko01e726e2020-10-23 09:45:29 +0000187//NewUniVlanConfigFsm is the 'constructor' for the state machine to config the PON ANI ports
188// of ONU UNI ports via OMCI
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000189func NewUniVlanConfigFsm(ctx context.Context, apDeviceHandler cmn.IdeviceHandler, apOnuDeviceEntry cmn.IonuDeviceEntry, apDevOmciCC *cmn.OmciCC, apUniPort *cmn.OnuUniPort,
190 apUniTechProf *OnuUniTechProf, apOnuDB *devdb.OnuDeviceDB, aTechProfileID uint8,
191 aRequestEvent cmn.OnuDeviceEvent, aName string, aCommChannel chan cmn.Message, aAcceptIncrementalEvto bool,
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +0530192 aCookieSlice []uint64, aMatchVlan uint16, aMatchPcp uint8, aSetVlan uint16, aSetPcp uint8, innerCvlan uint16, lastFlowToRec bool, aMeter *of.OfpMeterConfig, respChan *chan error) *UniVlanConfigFsm {
mpagenkodff5dda2020-08-28 11:52:01 +0000193 instFsm := &UniVlanConfigFsm{
194 pDeviceHandler: apDeviceHandler,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000195 pOnuDeviceEntry: apOnuDeviceEntry,
196 deviceID: apDeviceHandler.GetDeviceID(),
mpagenkodff5dda2020-08-28 11:52:01 +0000197 pOmciCC: apDevOmciCC,
198 pOnuUniPort: apUniPort,
199 pUniTechProf: apUniTechProf,
200 pOnuDB: apOnuDB,
mpagenkodff5dda2020-08-28 11:52:01 +0000201 requestEvent: aRequestEvent,
202 acceptIncrementalEvtoOption: aAcceptIncrementalEvto,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000203 NumUniFlows: 0,
204 ConfiguredUniFlow: 0,
mpagenko01e726e2020-10-23 09:45:29 +0000205 numRemoveFlows: 0,
Andrea Campanellaf66ac6e2021-05-24 17:09:20 +0200206 lastFlowToReconcile: lastFlowToRec,
mpagenkodff5dda2020-08-28 11:52:01 +0000207 }
208
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000209 instFsm.PAdaptFsm = cmn.NewAdapterFsm(aName, instFsm.deviceID, aCommChannel)
210 if instFsm.PAdaptFsm == nil {
211 logger.Errorw(ctx, "UniVlanConfigFsm's cmn.AdapterFsm could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000212 "device-id": instFsm.deviceID})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700213 // Push response on the response channel
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000214 instFsm.pushReponseOnFlowResponseChannel(ctx, respChan, fmt.Errorf("adapter-fsm-could-not-be-instantiated"))
mpagenkodff5dda2020-08-28 11:52:01 +0000215 return nil
216 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000217 instFsm.PAdaptFsm.PFsm = fsm.NewFSM(
218 VlanStDisabled,
mpagenkodff5dda2020-08-28 11:52:01 +0000219 fsm.Events{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000220 {Name: VlanEvStart, Src: []string{VlanStDisabled}, Dst: VlanStPreparing},
221 {Name: VlanEvPrepareDone, Src: []string{VlanStPreparing}, Dst: VlanStStarting},
222 {Name: VlanEvWaitTechProf, Src: []string{VlanStStarting}, Dst: VlanStWaitingTechProf},
223 {Name: VlanEvCancelOutstandingConfig, Src: []string{VlanStWaitingTechProf}, Dst: VlanStConfigDone},
224 {Name: VlanEvContinueConfig, Src: []string{VlanStWaitingTechProf}, Dst: VlanStConfigVtfd},
225 {Name: VlanEvStartConfig, Src: []string{VlanStStarting}, Dst: VlanStConfigVtfd},
226 {Name: VlanEvRxConfigVtfd, Src: []string{VlanStConfigVtfd}, Dst: VlanStConfigEvtocd},
227 {Name: VlanEvRxConfigEvtocd, Src: []string{VlanStConfigEvtocd, VlanStConfigIncrFlow},
228 Dst: VlanStConfigDone},
229 {Name: VlanEvRenew, Src: []string{VlanStConfigDone}, Dst: VlanStStarting},
230 {Name: VlanEvWaitTPIncr, Src: []string{VlanStConfigDone}, Dst: VlanStIncrFlowWaitTP},
231 {Name: VlanEvIncrFlowConfig, Src: []string{VlanStConfigDone, VlanStIncrFlowWaitTP},
232 Dst: VlanStConfigIncrFlow},
233 {Name: VlanEvRemFlowConfig, Src: []string{VlanStConfigDone}, Dst: VlanStRemoveFlow},
234 {Name: VlanEvRemFlowDone, Src: []string{VlanStRemoveFlow}, Dst: VlanStCleanupDone},
235 {Name: VlanEvFlowDataRemoved, Src: []string{VlanStCleanupDone}, Dst: VlanStConfigDone},
mpagenkodff5dda2020-08-28 11:52:01 +0000236 /*
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000237 {Name: VlanEvTimeoutSimple, Src: []string{
238 VlanStCreatingDot1PMapper, VlanStCreatingMBPCD, VlanStSettingTconts, VlanStSettingDot1PMapper}, Dst: VlanStStarting},
239 {Name: VlanEvTimeoutMids, Src: []string{
240 VlanStCreatingGemNCTPs, VlanStCreatingGemIWs, VlanStSettingPQs}, Dst: VlanStStarting},
mpagenkodff5dda2020-08-28 11:52:01 +0000241 */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000242 // exceptional treatment for all states except VlanStResetting
243 {Name: VlanEvReset, Src: []string{VlanStStarting, VlanStWaitingTechProf,
244 VlanStConfigVtfd, VlanStConfigEvtocd, VlanStConfigDone, VlanStConfigIncrFlow,
245 VlanStRemoveFlow, VlanStCleanupDone},
246 Dst: VlanStResetting},
mpagenkodff5dda2020-08-28 11:52:01 +0000247 // the only way to get to resource-cleared disabled state again is via "resseting"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000248 {Name: VlanEvRestart, Src: []string{VlanStResetting}, Dst: VlanStDisabled},
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000249 // transitions for reconcile handling according to VOL-3834
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000250 {Name: VlanEvSkipOmciConfig, Src: []string{VlanStPreparing}, Dst: VlanStConfigDone},
251 {Name: VlanEvSkipOmciConfig, Src: []string{VlanStConfigDone}, Dst: VlanStConfigIncrFlow},
252 {Name: VlanEvSkipIncFlowConfig, Src: []string{VlanStConfigIncrFlow}, Dst: VlanStConfigDone},
mpagenkodff5dda2020-08-28 11:52:01 +0000253 },
mpagenkodff5dda2020-08-28 11:52:01 +0000254 fsm.Callbacks{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000255 "enter_state": func(e *fsm.Event) { instFsm.PAdaptFsm.LogFsmStateChange(ctx, e) },
256 "enter_" + VlanStPreparing: func(e *fsm.Event) { instFsm.enterPreparing(ctx, e) },
257 "enter_" + VlanStStarting: func(e *fsm.Event) { instFsm.enterConfigStarting(ctx, e) },
258 "enter_" + VlanStConfigVtfd: func(e *fsm.Event) { instFsm.enterConfigVtfd(ctx, e) },
259 "enter_" + VlanStConfigEvtocd: func(e *fsm.Event) { instFsm.enterConfigEvtocd(ctx, e) },
260 "enter_" + VlanStConfigDone: func(e *fsm.Event) { instFsm.enterVlanConfigDone(ctx, e) },
261 "enter_" + VlanStConfigIncrFlow: func(e *fsm.Event) { instFsm.enterConfigIncrFlow(ctx, e) },
262 "enter_" + VlanStRemoveFlow: func(e *fsm.Event) { instFsm.enterRemoveFlow(ctx, e) },
263 "enter_" + VlanStCleanupDone: func(e *fsm.Event) { instFsm.enterVlanCleanupDone(ctx, e) },
264 "enter_" + VlanStResetting: func(e *fsm.Event) { instFsm.enterResetting(ctx, e) },
265 "enter_" + VlanStDisabled: func(e *fsm.Event) { instFsm.enterDisabled(ctx, e) },
mpagenkodff5dda2020-08-28 11:52:01 +0000266 },
267 )
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000268 if instFsm.PAdaptFsm.PFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000269 logger.Errorw(ctx, "UniVlanConfigFsm's Base FSM could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000270 "device-id": instFsm.deviceID})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700271 // Push response on the response channel
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000272 instFsm.pushReponseOnFlowResponseChannel(ctx, respChan, fmt.Errorf("adapter-base-fsm-could-not-be-instantiated"))
mpagenkodff5dda2020-08-28 11:52:01 +0000273 return nil
274 }
275
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +0530276 _ = instFsm.initUniFlowParams(ctx, aTechProfileID, aCookieSlice, aMatchVlan, aMatchPcp, aSetVlan, aSetPcp, innerCvlan, aMeter, respChan)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000277 logger.Debugw(ctx, "UniVlanConfigFsm created", log.Fields{"device-id": instFsm.deviceID,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000278 "accIncrEvto": instFsm.acceptIncrementalEvtoOption})
mpagenkodff5dda2020-08-28 11:52:01 +0000279 return instFsm
280}
281
mpagenko01e726e2020-10-23 09:45:29 +0000282//initUniFlowParams is a simplified form of SetUniFlowParams() used for first flow parameters configuration
mpagenko551a4d42020-12-08 18:09:20 +0000283func (oFsm *UniVlanConfigFsm) initUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64,
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +0530284 aMatchVlan uint16, aMatchPcp uint8, aSetVlan uint16, aSetPcp uint8, innerCvlan uint16, aMeter *of.OfpMeterConfig, respChan *chan error) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000285 loRuleParams := cmn.UniVlanRuleParams{
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +0530286 TpID: aTpID,
287 MatchVid: uint32(aMatchVlan),
288 MatchPcp: uint32(aMatchPcp),
289 SetVid: uint32(aSetVlan),
290 SetPcp: uint32(aSetPcp),
291 InnerCvlan: innerCvlan,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000292 }
293 // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters
Abhilash Laxmeshwarc7c29d82022-03-03 18:38:45 +0530294 loRuleParams.TagsToRemove = 1 //one tag to remove as default setting
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000295
mpagenko01e726e2020-10-23 09:45:29 +0000296 if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000297 //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 +0000298 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000299 //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther)
300 } else {
301 if !oFsm.acceptIncrementalEvtoOption {
302 //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 +0000303 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000304 }
305 }
306
mpagenko01e726e2020-10-23 09:45:29 +0000307 if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000308 // no prio/vid filtering requested
mpagenko01e726e2020-10-23 09:45:29 +0000309 loRuleParams.TagsToRemove = 0 //no tag pop action
310 loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering
311 if loRuleParams.SetPcp == cCopyPrioFromInner {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000312 //in case of no filtering and configured PrioCopy ensure default prio setting to 0
313 // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged
314 // might collide with NoMatchVid/CopyPrio(/setVid) setting
315 // this was some precondition setting taken over from py adapter ..
mpagenko01e726e2020-10-23 09:45:29 +0000316 loRuleParams.SetPcp = 0
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000317 }
318 }
mpagenko01e726e2020-10-23 09:45:29 +0000319
Girish Gowdrae95687a2021-09-08 16:30:58 -0700320 loFlowParams := cmn.UniVlanFlowParams{VlanRuleParams: loRuleParams, RespChan: respChan}
mpagenko01e726e2020-10-23 09:45:29 +0000321 loFlowParams.CookieSlice = make([]uint64, 0)
322 loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...)
ozgecanetsia82b91a62021-05-21 18:54:49 +0300323 if aMeter != nil {
324 loFlowParams.Meter = aMeter
325 }
mpagenko01e726e2020-10-23 09:45:29 +0000326
327 //no mutex protection is required for initial access and adding the first flow is always possible
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000328 oFsm.uniVlanFlowParamsSlice = make([]cmn.UniVlanFlowParams, 0)
mpagenko01e726e2020-10-23 09:45:29 +0000329 oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000330 logger.Debugw(ctx, "first UniVlanConfigFsm flow added", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000331 "Cookies": oFsm.uniVlanFlowParamsSlice[0].CookieSlice,
332 "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16),
333 "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
334 "SetPcp": loRuleParams.SetPcp,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000335 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
Holger Hildebrandt968eb8f2021-09-17 07:41:12 +0000336
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000337 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandt968eb8f2021-09-17 07:41:12 +0000338 oFsm.reconcileVlanFilterList(ctx, uint16(loRuleParams.SetVid))
339 }
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000340 //cmp also usage in EVTOCDE create in omci_cc
341 oFsm.evtocdID = cmn.MacBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.MacBpNo)
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) {
Holger Hildebrandt12609a12022-03-25 13:23:25 +0000357 logger.Debugw(ctx, "CancelProcessing entered", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000358 if oFsm == nil {
359 logger.Error(ctx, "no valid UniVlanConfigFsm!")
360 return
361 }
mpagenko7d6bb022021-03-11 15:07:55 +0000362 //mutex protection is required for possible concurrent access to FSM members
mpagenkocf48e452021-04-23 09:23:00 +0000363 oFsm.mutexIsAwaitingResponse.Lock()
364 oFsm.isCanceled = true
mpagenko7d6bb022021-03-11 15:07:55 +0000365 if oFsm.isAwaitingResponse {
mpagenkocf48e452021-04-23 09:23:00 +0000366 //attention: for an unbuffered channel the sender is blocked until the value is received (processed)!
367 // accordingly the mutex must be released before sending to channel here (mutex acquired in receiver)
368 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko7d6bb022021-03-11 15:07:55 +0000369 //use channel to indicate that the response waiting shall be aborted
370 oFsm.omciMIdsResponseReceived <- false
mpagenkocf48e452021-04-23 09:23:00 +0000371 } else {
372 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko7d6bb022021-03-11 15:07:55 +0000373 }
mpagenkocf48e452021-04-23 09:23:00 +0000374
mpagenko7d6bb022021-03-11 15:07:55 +0000375 // 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 +0000376 PAdaptFsm := oFsm.PAdaptFsm
377 if PAdaptFsm != nil {
378 if fsmErr := PAdaptFsm.PFsm.Event(VlanEvReset); fsmErr != nil {
mpagenkocf48e452021-04-23 09:23:00 +0000379 logger.Errorw(ctx, "reset-event failed in UniVlanConfigFsm!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000380 log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000381 }
mpagenko7d6bb022021-03-11 15:07:55 +0000382 }
383}
384
mpagenko551a4d42020-12-08 18:09:20 +0000385//GetWaitingTpID returns the TpId that the FSM might be waiting for continuation (0 if none)
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000386func (oFsm *UniVlanConfigFsm) GetWaitingTpID(ctx context.Context) uint8 {
387 if oFsm == nil {
388 logger.Error(ctx, "no valid UniVlanConfigFsm!")
389 return 0
390 }
mpagenko551a4d42020-12-08 18:09:20 +0000391 //mutex protection is required for possible concurrent access to FSM members
392 oFsm.mutexFlowParams.RLock()
393 defer oFsm.mutexFlowParams.RUnlock()
394 return oFsm.TpIDWaitingFor
395}
396
mpagenko01e726e2020-10-23 09:45:29 +0000397//SetUniFlowParams verifies on existence of flow parameters to be configured,
398// optionally udates the cookie list or appends a new flow if there is space
399// if possible the FSM is trigggerd to start with the processing
mpagenko551a4d42020-12-08 18:09:20 +0000400// ignore complexity by now
401// nolint: gocyclo
402func (oFsm *UniVlanConfigFsm) SetUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64,
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +0530403 aMatchVlan uint16, aMatchPcp uint8, aSetVlan uint16, aSetPcp uint8, aInnerCvlan uint16, lastFlowToReconcile bool, aMeter *of.OfpMeterConfig, respChan *chan error) error {
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000404 if oFsm == nil {
405 logger.Error(ctx, "no valid UniVlanConfigFsm!")
406 return fmt.Errorf("no-valid-UniVlanConfigFsm")
407 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000408 loRuleParams := cmn.UniVlanRuleParams{
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +0530409 TpID: aTpID,
410 MatchVid: uint32(aMatchVlan),
411 MatchPcp: uint32(aMatchPcp),
412 SetVid: uint32(aSetVlan),
413 SetPcp: uint32(aSetPcp),
414 InnerCvlan: aInnerCvlan,
mpagenko01e726e2020-10-23 09:45:29 +0000415 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700416 var err error
mpagenko01e726e2020-10-23 09:45:29 +0000417 // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +0530418 loRuleParams.TagsToRemove = 1 //one tag to remove as default setting
mpagenko01e726e2020-10-23 09:45:29 +0000419 if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
420 //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries
421 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
422 //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther)
423 } else {
424 if !oFsm.acceptIncrementalEvtoOption {
425 //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries
426 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
427 }
428 }
429
430 if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
431 // no prio/vid filtering requested
432 loRuleParams.TagsToRemove = 0 //no tag pop action
433 loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering
434 if loRuleParams.SetPcp == cCopyPrioFromInner {
435 //in case of no filtering and configured PrioCopy ensure default prio setting to 0
436 // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged
437 // might collide with NoMatchVid/CopyPrio(/setVid) setting
438 // this was some precondition setting taken over from py adapter ..
439 loRuleParams.SetPcp = 0
440 }
441 }
442
mpagenkof1d21d12021-06-11 13:14:45 +0000443 //check if there is some ongoing delete-request running for this flow. If so, block here until this is finished.
444 // might be accordingly rwCore processing runs into timeout in specific situations - needs to be observed ...
445 // this is to protect uniVlanFlowParams from adding new or re-writing the same cookie to the rule currently under deletion
446 oFsm.mutexFlowParams.RLock()
447 if len(oFsm.uniRemoveFlowsSlice) > 0 {
448 for flow, removeUniFlowParams := range oFsm.uniRemoveFlowsSlice {
449 if removeUniFlowParams.vlanRuleParams == loRuleParams {
450 // the flow to add is the same as the one already in progress of deleting
451 logger.Infow(ctx, "UniVlanConfigFsm flow setting - suspending rule-add due to ongoing removal", log.Fields{
mpagenkof582d6a2021-06-18 15:58:10 +0000452 "device-id": oFsm.deviceID, "cookie": removeUniFlowParams.cookie, "remove-index": flow})
453 if flow >= len(oFsm.uniRemoveFlowsSlice) {
454 logger.Errorw(ctx, "abort UniVlanConfigFsm flow add - inconsistent RemoveFlowsSlice", log.Fields{
455 "device-id": oFsm.deviceID, "slice length": len(oFsm.uniRemoveFlowsSlice)})
456 oFsm.mutexFlowParams.RUnlock()
Girish Gowdrae95687a2021-09-08 16:30:58 -0700457 err = fmt.Errorf("abort UniVlanConfigFsm flow add - inconsistent RemoveFlowsSlice %s", oFsm.deviceID)
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000458 oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700459 return err
460
mpagenkof582d6a2021-06-18 15:58:10 +0000461 }
mpagenkof1d21d12021-06-11 13:14:45 +0000462 pRemoveParams := &oFsm.uniRemoveFlowsSlice[flow] //wants to modify the uniRemoveFlowsSlice element directly!
463 oFsm.mutexFlowParams.RUnlock()
464 if err := oFsm.suspendAddRule(ctx, pRemoveParams); err != nil {
465 logger.Errorw(ctx, "UniVlanConfigFsm suspension on add aborted - abort complete add-request", log.Fields{
466 "device-id": oFsm.deviceID, "cookie": removeUniFlowParams.cookie})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700467 err = fmt.Errorf("abort UniVlanConfigFsm suspension on add %s", oFsm.deviceID)
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000468 oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700469 return err
mpagenkof1d21d12021-06-11 13:14:45 +0000470 }
471 oFsm.mutexFlowParams.RLock()
mpagenkof582d6a2021-06-18 15:58:10 +0000472 break //this specific rule should only exist once per uniRemoveFlowsSlice
mpagenkof1d21d12021-06-11 13:14:45 +0000473 }
474 }
475 }
476 oFsm.mutexFlowParams.RUnlock()
477
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000478 flowEntryMatch := false
mpagenko01e726e2020-10-23 09:45:29 +0000479 flowCookieModify := false
mpagenkof1fc3862021-02-16 10:09:52 +0000480 requestAppendRule := false
Andrea Campanellaf66ac6e2021-05-24 17:09:20 +0200481 oFsm.lastFlowToReconcile = lastFlowToReconcile
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000482 //mutex protection is required for possible concurrent access to FSM members
483 oFsm.mutexFlowParams.Lock()
mpagenko01e726e2020-10-23 09:45:29 +0000484 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
485 //TODO: Verify if using e.g. hashes for the structures here for comparison may generate
486 // countable run time optimization (perhaps with including the hash in kvStore storage?)
487 if storedUniFlowParams.VlanRuleParams == loRuleParams {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000488 flowEntryMatch = true
dbainbri4d3a0dc2020-12-02 00:33:42 +0000489 logger.Debugw(ctx, "UniVlanConfigFsm flow setting - rule already exists", log.Fields{
ozgecanetsia82b91a62021-05-21 18:54:49 +0300490 "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16),
491 "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
492 "SetPcp": loRuleParams.SetPcp,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000493 "device-id": oFsm.deviceID, " uni-id": oFsm.pOnuUniPort.UniID})
mpagenko01e726e2020-10-23 09:45:29 +0000494 var cookieMatch bool
495 for _, newCookie := range aCookieSlice { // for all cookies available in the arguments
496 cookieMatch = false
497 for _, cookie := range storedUniFlowParams.CookieSlice {
498 if cookie == newCookie {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000499 logger.Debugw(ctx, "UniVlanConfigFsm flow setting - and cookie already exists", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000500 "device-id": oFsm.deviceID, "cookie": cookie})
501 cookieMatch = true
502 break //found new cookie - no further search for this requested cookie
503 }
504 }
505 if !cookieMatch {
mpagenkof1fc3862021-02-16 10:09:52 +0000506 delayedCookie := oFsm.delayNewRuleForCookie(ctx, aCookieSlice)
507 if delayedCookie != 0 {
508 //a delay for adding the cookie to this rule is requested
509 // take care of the mutex which is already locked here, need to unlock/lock accordingly to prevent deadlock in suspension
510 oFsm.mutexFlowParams.Unlock()
mpagenkobc4170a2021-08-17 16:42:10 +0000511 if deleteSuccess := oFsm.suspendNewRule(ctx); !deleteSuccess {
512 logger.Errorw(ctx, "UniVlanConfigFsm suspended add-cookie-to-rule aborted", log.Fields{
513 "device-id": oFsm.deviceID, "cookie": delayedCookie})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700514 err = fmt.Errorf(" UniVlanConfigFsm suspended add-cookie-to-rule aborted %s", oFsm.deviceID)
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000515 oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700516 return err
mpagenkobc4170a2021-08-17 16:42:10 +0000517 }
mpagenkobc4170a2021-08-17 16:42:10 +0000518 flowCookieModify, requestAppendRule = oFsm.reviseFlowConstellation(ctx, delayedCookie, loRuleParams)
mpagenkod6c05522021-08-23 15:59:06 +0000519 oFsm.mutexFlowParams.Lock()
mpagenkof1fc3862021-02-16 10:09:52 +0000520 } else {
521 logger.Debugw(ctx, "UniVlanConfigFsm flow setting -adding new cookie", log.Fields{
522 "device-id": oFsm.deviceID, "cookie": newCookie})
523 //as range works with copies of the slice we have to write to the original slice!!
524 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(oFsm.uniVlanFlowParamsSlice[flow].CookieSlice,
525 newCookie)
526 flowCookieModify = true
527 }
mpagenko01e726e2020-10-23 09:45:29 +0000528 }
529 } //for all new cookies
530 break // found rule - no further rule search
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000531 }
532 }
mpagenkof1fc3862021-02-16 10:09:52 +0000533 oFsm.mutexFlowParams.Unlock()
534
535 if !flowEntryMatch { //it is (was) a new rule
mpagenkobc4170a2021-08-17 16:42:10 +0000536 delayedCookie, deleteSuccess := oFsm.suspendIfRequiredNewRule(ctx, aCookieSlice)
537 if !deleteSuccess {
538 logger.Errorw(ctx, "UniVlanConfigFsm suspended add-new-rule aborted", log.Fields{
539 "device-id": oFsm.deviceID, "cookie": delayedCookie})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700540 err = fmt.Errorf(" UniVlanConfigFsm suspended add-new-rule aborted %s", oFsm.deviceID)
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000541 oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700542 return err
mpagenkobc4170a2021-08-17 16:42:10 +0000543 }
mpagenkof1fc3862021-02-16 10:09:52 +0000544 requestAppendRule = true //default assumption here is that rule is to be appended
545 flowCookieModify = true //and that the the flow data base is to be updated
546 if delayedCookie != 0 { //it was suspended
547 flowCookieModify, requestAppendRule = oFsm.reviseFlowConstellation(ctx, delayedCookie, loRuleParams)
548 }
549 }
550 kvStoreWrite := false //default setting is to not write to kvStore immediately - will be done on FSM execution finally
551 if requestAppendRule {
552 oFsm.mutexFlowParams.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000553 if oFsm.NumUniFlows < cMaxAllowedFlows {
Girish Gowdrae95687a2021-09-08 16:30:58 -0700554 loFlowParams := cmn.UniVlanFlowParams{VlanRuleParams: loRuleParams, RespChan: respChan}
mpagenko01e726e2020-10-23 09:45:29 +0000555 loFlowParams.CookieSlice = make([]uint64, 0)
556 loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...)
ozgecanetsia82b91a62021-05-21 18:54:49 +0300557 if aMeter != nil {
558 loFlowParams.Meter = aMeter
559 }
mpagenko01e726e2020-10-23 09:45:29 +0000560 oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000561 logger.Debugw(ctx, "UniVlanConfigFsm flow add", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000562 "Cookies": oFsm.uniVlanFlowParamsSlice[oFsm.NumUniFlows].CookieSlice,
mpagenko01e726e2020-10-23 09:45:29 +0000563 "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16),
564 "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000565 "SetPcp": loRuleParams.SetPcp, "numberofFlows": oFsm.NumUniFlows + 1,
566 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko01e726e2020-10-23 09:45:29 +0000567
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000568 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandt968eb8f2021-09-17 07:41:12 +0000569 oFsm.reconcileVlanFilterList(ctx, uint16(loRuleParams.SetVid))
570 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000571 oFsm.NumUniFlows++
572 pConfigVlanStateBaseFsm := oFsm.PAdaptFsm.PFsm
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000573
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000574 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000575 logger.Debugw(ctx, "reconciling - skip omci-config of additional vlan rule",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000576 log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID})
mpagenkobb47bc22021-04-20 13:29:09 +0000577 //attention: take care to release the mutexFlowParams when calling the FSM directly -
578 // synchronous FSM 'event/state' functions may rely on this mutex
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000579 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000580 if pConfigVlanStateBaseFsm.Is(VlanStConfigDone) {
581 if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvSkipOmciConfig); fsmErr != nil {
mpagenkobb47bc22021-04-20 13:29:09 +0000582 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000583 log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700584 err = fsmErr
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000585 oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700586 return err
mpagenkobb47bc22021-04-20 13:29:09 +0000587 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000588 }
589 return nil
590 }
mpagenko01e726e2020-10-23 09:45:29 +0000591 // note: theoretical it would be possible to clear the same rule from the remove slice
592 // (for entries that have not yet been started with removal)
593 // but that is getting quite complicated - maybe a future optimization in case it should prove reasonable
594 // 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 +0000595
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000596 if pConfigVlanStateBaseFsm.Is(VlanStConfigDone) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000597 //have to re-trigger the FSM to proceed with outstanding incremental flow configuration
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000598 if oFsm.ConfiguredUniFlow == 0 {
mpagenko551a4d42020-12-08 18:09:20 +0000599 // this is a restart with a complete new flow, we can re-use the initial flow config control
600 // including the check, if the related techProfile is (still) available (probably also removed in between)
mpagenkobb47bc22021-04-20 13:29:09 +0000601 //attention: take care to release the mutexFlowParams when calling the FSM directly -
602 // synchronous FSM 'event/state' functions may rely on this mutex
603 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000604 if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvRenew); fsmErr != nil {
mpagenkobb47bc22021-04-20 13:29:09 +0000605 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
606 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
607 }
mpagenko551a4d42020-12-08 18:09:20 +0000608 } else {
609 //some further flows are to be configured
mpagenko9a304ea2020-12-16 15:54:01 +0000610 //store the actual rule that shall be worked upon in the following transient states
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000611 if len(oFsm.uniVlanFlowParamsSlice) < int(oFsm.ConfiguredUniFlow) {
mpagenkof1d21d12021-06-11 13:14:45 +0000612 //check introduced after having observed some panic here
613 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm - inconsistent counter",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000614 log.Fields{"ConfiguredUniFlow": oFsm.ConfiguredUniFlow,
mpagenkof1d21d12021-06-11 13:14:45 +0000615 "sliceLen": len(oFsm.uniVlanFlowParamsSlice), "device-id": oFsm.deviceID})
616 oFsm.mutexFlowParams.Unlock()
Girish Gowdrae95687a2021-09-08 16:30:58 -0700617 err = fmt.Errorf("abort UniVlanConfigFsm on add due to internal counter mismatch %s", oFsm.deviceID)
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000618 oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700619 return err
mpagenkof1d21d12021-06-11 13:14:45 +0000620 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700621
622 oFsm.actualUniFlowParam = oFsm.uniVlanFlowParamsSlice[oFsm.ConfiguredUniFlow]
mpagenko551a4d42020-12-08 18:09:20 +0000623 //tpId of the next rule to be configured
Girish Gowdrae95687a2021-09-08 16:30:58 -0700624 tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID
mpagenko551a4d42020-12-08 18:09:20 +0000625 oFsm.TpIDWaitingFor = tpID
Girish Gowdrae95687a2021-09-08 16:30:58 -0700626 loSetVlan := oFsm.actualUniFlowParam.VlanRuleParams.SetVid
mpagenkobb47bc22021-04-20 13:29:09 +0000627 //attention: take care to release the mutexFlowParams when calling the FSM directly -
628 // synchronous FSM 'event/state' functions may rely on this mutex
mpagenko45cc6a32021-07-23 10:06:57 +0000629 // but it must be released already before calling getTechProfileDone() as it may already be locked
630 // by the techProfile processing call to VlanFsm.IsFlowRemovePending() (see VOL-4207)
mpagenkobb47bc22021-04-20 13:29:09 +0000631 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000632 loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.UniID, tpID)
mpagenko45cc6a32021-07-23 10:06:57 +0000633 logger.Debugw(ctx, "UniVlanConfigFsm - incremental config request (on setConfig)", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000634 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko45cc6a32021-07-23 10:06:57 +0000635 "set-Vlan": loSetVlan, "tp-id": tpID, "ProfDone": loTechProfDone})
636
mpagenkobb47bc22021-04-20 13:29:09 +0000637 var fsmErr error
638 if loTechProfDone {
639 // let the vlan processing continue with next rule
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000640 fsmErr = pConfigVlanStateBaseFsm.Event(VlanEvIncrFlowConfig)
mpagenkobb47bc22021-04-20 13:29:09 +0000641 } else {
642 // set to waiting for Techprofile
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000643 fsmErr = pConfigVlanStateBaseFsm.Event(VlanEvWaitTPIncr)
mpagenkobb47bc22021-04-20 13:29:09 +0000644 }
645 if fsmErr != nil {
646 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
647 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000648 oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, fsmErr)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700649 return fsmErr
mpagenkobb47bc22021-04-20 13:29:09 +0000650 }
mpagenko551a4d42020-12-08 18:09:20 +0000651 }
mpagenkobb47bc22021-04-20 13:29:09 +0000652 } else {
653 // if not in the appropriate state a new entry will be automatically considered later
654 // when the configDone state is reached
655 oFsm.mutexFlowParams.Unlock()
656 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000657 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000658 logger.Errorw(ctx, "UniVlanConfigFsm flow limit exceeded", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000659 "device-id": oFsm.deviceID, "flow-number": oFsm.NumUniFlows})
mpagenko15ff4a52021-03-02 10:09:20 +0000660 oFsm.mutexFlowParams.Unlock()
Girish Gowdrae95687a2021-09-08 16:30:58 -0700661 err = fmt.Errorf(" UniVlanConfigFsm flow limit exceeded %s", oFsm.deviceID)
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000662 oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700663 return err
mpagenko01e726e2020-10-23 09:45:29 +0000664 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000665 } else {
666 // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately
mpagenkof1fc3862021-02-16 10:09:52 +0000667 kvStoreWrite = true // ensure actual data write to kvStore immediately (no FSM activity)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700668 // push response on response channel as there is nothing to be done for this flow
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000669 oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, nil)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700670
mpagenko15ff4a52021-03-02 10:09:20 +0000671 oFsm.mutexFlowParams.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000672 if oFsm.NumUniFlows == oFsm.ConfiguredUniFlow {
mpagenkofc4f56e2020-11-04 17:17:49 +0000673 //all requested rules really have been configured
674 // state transition notification is checked in deviceHandler
mpagenko15ff4a52021-03-02 10:09:20 +0000675 oFsm.mutexFlowParams.RUnlock()
mpagenkofc4f56e2020-11-04 17:17:49 +0000676 if oFsm.pDeviceHandler != nil {
677 //also the related TechProfile was already configured
dbainbri4d3a0dc2020-12-02 00:33:42 +0000678 logger.Debugw(ctx, "UniVlanConfigFsm rule already set - send immediate add-success event for reason update", log.Fields{
mpagenkofc4f56e2020-11-04 17:17:49 +0000679 "device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000680 // success indication without the need to write to kvStore (done already below with updated data from StorePersUniFlowConfig())
681 go oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetAddNoKvStore))
mpagenkofc4f56e2020-11-04 17:17:49 +0000682 }
683 } else {
684 // avoid device reason update as the rule config connected to this flow may still be in progress
685 // and the device reason should only be updated on success of rule config
dbainbri4d3a0dc2020-12-02 00:33:42 +0000686 logger.Debugw(ctx, "UniVlanConfigFsm rule already set but configuration ongoing, suppress early add-success event for reason update",
mpagenkofc4f56e2020-11-04 17:17:49 +0000687 log.Fields{"device-id": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000688 "NumberofRules": oFsm.NumUniFlows, "Configured rules": oFsm.ConfiguredUniFlow})
mpagenko15ff4a52021-03-02 10:09:20 +0000689 oFsm.mutexFlowParams.RUnlock()
mpagenkofc4f56e2020-11-04 17:17:49 +0000690 }
691 }
mpagenko01e726e2020-10-23 09:45:29 +0000692
mpagenkof1fc3862021-02-16 10:09:52 +0000693 if flowCookieModify { // some change was done to the flow entries
mpagenko01e726e2020-10-23 09:45:29 +0000694 //permanently store flow config for reconcile case
mpagenko15ff4a52021-03-02 10:09:20 +0000695 oFsm.mutexFlowParams.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000696 if err := oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID,
mpagenkof1fc3862021-02-16 10:09:52 +0000697 &oFsm.uniVlanFlowParamsSlice, kvStoreWrite); err != nil {
mpagenko15ff4a52021-03-02 10:09:20 +0000698 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000699 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +0000700 return err
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000701 }
mpagenko15ff4a52021-03-02 10:09:20 +0000702 oFsm.mutexFlowParams.RUnlock()
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000703 }
704 return nil
705}
706
mpagenkof1d21d12021-06-11 13:14:45 +0000707func (oFsm *UniVlanConfigFsm) suspendAddRule(ctx context.Context, apRemoveFlowParams *uniRemoveVlanFlowParams) error {
708 oFsm.mutexFlowParams.Lock()
709 deleteChannel := apRemoveFlowParams.removeChannel
710 apRemoveFlowParams.isSuspendedOnAdd = true
711 oFsm.mutexFlowParams.Unlock()
712
713 // isSuspendedOnAdd is not reset here-after as the assumption is, that after
714 select {
715 case success := <-deleteChannel:
716 //no need to reset isSuspendedOnAdd as in this case the removeElement will be deleted completely
717 if success {
718 logger.Infow(ctx, "resume adding this rule after having completed deletion", log.Fields{
719 "device-id": oFsm.deviceID})
720 return nil
721 }
722 return fmt.Errorf("suspend aborted, also aborting add-activity: %s", oFsm.deviceID)
723 case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second):
724 oFsm.mutexFlowParams.Lock()
725 if apRemoveFlowParams != nil {
726 apRemoveFlowParams.isSuspendedOnAdd = false
727 }
728 oFsm.mutexFlowParams.Unlock()
mpagenkof582d6a2021-06-18 15:58:10 +0000729 logger.Errorw(ctx, "timeout waiting for deletion of rule, also aborting add-activity", log.Fields{
mpagenkof1d21d12021-06-11 13:14:45 +0000730 "device-id": oFsm.deviceID})
mpagenkof582d6a2021-06-18 15:58:10 +0000731 return fmt.Errorf("suspend aborted on timeout, also aborting add-activity: %s", oFsm.deviceID)
mpagenkof1d21d12021-06-11 13:14:45 +0000732 }
mpagenkof1d21d12021-06-11 13:14:45 +0000733}
734
mpagenkof1fc3862021-02-16 10:09:52 +0000735// VOL-3828 flow config sequence workaround ########### start ##########
736func (oFsm *UniVlanConfigFsm) delayNewRuleForCookie(ctx context.Context, aCookieSlice []uint64) uint64 {
737 //assumes mutexFlowParams.Lock() protection from caller!
738 if oFsm.delayNewRuleCookie == 0 && len(aCookieSlice) == 1 {
739 // if not already waiting, limitation for this workaround is to just have one overlapping cookie/rule
mpagenkof1d21d12021-06-11 13:14:45 +0000740 // suspend check is done only if there is only one cookie in the request
mpagenkof1fc3862021-02-16 10:09:52 +0000741 // background: more elements only expected in reconcile use case, where no conflicting sequence is to be expected
742 newCookie := aCookieSlice[0]
743 for _, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
744 for _, cookie := range storedUniFlowParams.CookieSlice {
745 if cookie == newCookie {
746 logger.Debugw(ctx, "UniVlanConfigFsm flow setting - new cookie still exists for some rule", log.Fields{
747 "device-id": oFsm.deviceID, "cookie": cookie, "exists with SetVlan": storedUniFlowParams.VlanRuleParams.SetVid})
748 oFsm.delayNewRuleCookie = newCookie
749 return newCookie //found new cookie in some existing rule
750 }
751 } // for all stored cookies of the actual inspected rule
752 } //for all rules
753 }
754 return 0 //no delay requested
755}
mpagenkobc4170a2021-08-17 16:42:10 +0000756func (oFsm *UniVlanConfigFsm) suspendNewRule(ctx context.Context) bool {
mpagenkof1fc3862021-02-16 10:09:52 +0000757 oFsm.mutexFlowParams.RLock()
758 logger.Infow(ctx, "Need to suspend adding this rule as long as the cookie is still connected to some other rule", log.Fields{
759 "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie})
760 oFsm.mutexFlowParams.RUnlock()
mpagenkobc4170a2021-08-17 16:42:10 +0000761 cookieDeleted := true //default assumption also for timeout (just try to continue as if removed)
mpagenkof1fc3862021-02-16 10:09:52 +0000762 select {
mpagenkobc4170a2021-08-17 16:42:10 +0000763 case cookieDeleted = <-oFsm.chCookieDeleted:
764 logger.Infow(ctx, "resume adding this rule after having deleted cookie in some other rule or abort", log.Fields{
765 "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie, "deleted": cookieDeleted})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000766 case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second):
mpagenkof1fc3862021-02-16 10:09:52 +0000767 logger.Errorw(ctx, "timeout waiting for deletion of cookie in some other rule, just try to continue", log.Fields{
768 "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie})
769 }
770 oFsm.mutexFlowParams.Lock()
771 oFsm.delayNewRuleCookie = 0
772 oFsm.mutexFlowParams.Unlock()
mpagenkobc4170a2021-08-17 16:42:10 +0000773 return cookieDeleted
mpagenkof1fc3862021-02-16 10:09:52 +0000774}
mpagenkobc4170a2021-08-17 16:42:10 +0000775func (oFsm *UniVlanConfigFsm) suspendIfRequiredNewRule(ctx context.Context, aCookieSlice []uint64) (uint64, bool) {
mpagenkof1fc3862021-02-16 10:09:52 +0000776 oFsm.mutexFlowParams.Lock()
777 delayedCookie := oFsm.delayNewRuleForCookie(ctx, aCookieSlice)
778 oFsm.mutexFlowParams.Unlock()
779
mpagenkobc4170a2021-08-17 16:42:10 +0000780 deleteSuccess := true
mpagenkof1fc3862021-02-16 10:09:52 +0000781 if delayedCookie != 0 {
mpagenkobc4170a2021-08-17 16:42:10 +0000782 deleteSuccess = oFsm.suspendNewRule(ctx)
mpagenkof1fc3862021-02-16 10:09:52 +0000783 }
mpagenkobc4170a2021-08-17 16:42:10 +0000784 return delayedCookie, deleteSuccess
mpagenkof1fc3862021-02-16 10:09:52 +0000785}
786
787//returns flowModified, RuleAppendRequest
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000788func (oFsm *UniVlanConfigFsm) reviseFlowConstellation(ctx context.Context, aCookie uint64, aUniVlanRuleParams cmn.UniVlanRuleParams) (bool, bool) {
mpagenkof1fc3862021-02-16 10:09:52 +0000789 flowEntryMatch := false
790 oFsm.mutexFlowParams.Lock()
791 defer oFsm.mutexFlowParams.Unlock()
792 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
793 if storedUniFlowParams.VlanRuleParams == aUniVlanRuleParams {
794 flowEntryMatch = true
795 logger.Debugw(ctx, "UniVlanConfigFsm flow revise - rule already exists", log.Fields{
796 "device-id": oFsm.deviceID})
797 cookieMatch := false
798 for _, cookie := range storedUniFlowParams.CookieSlice {
799 if cookie == aCookie {
800 logger.Debugw(ctx, "UniVlanConfigFsm flow revise - and cookie already exists", log.Fields{
801 "device-id": oFsm.deviceID, "cookie": cookie})
802 cookieMatch = true
803 break //found new cookie - no further search for this requested cookie
804 }
805 }
806 if !cookieMatch {
807 logger.Debugw(ctx, "UniVlanConfigFsm flow revise -adding new cookie", log.Fields{
808 "device-id": oFsm.deviceID, "cookie": aCookie})
809 //as range works with copies of the slice we have to write to the original slice!!
810 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(oFsm.uniVlanFlowParamsSlice[flow].CookieSlice,
811 aCookie)
812 return true, false //flowModified, NoRuleAppend
813 }
814 break // found rule - no further rule search
815 }
816 }
817 if !flowEntryMatch { //it is a new rule
818 return true, true //flowModified, RuleAppend
819 }
820 return false, false //flowNotModified, NoRuleAppend
821}
822
823// VOL-3828 flow config sequence workaround ########### end ##########
824
mpagenko01e726e2020-10-23 09:45:29 +0000825//RemoveUniFlowParams verifies on existence of flow cookie,
826// if found removes cookie from flow cookie list and if this is empty
827// initiates removal of the flow related configuration from the ONU (via OMCI)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700828func (oFsm *UniVlanConfigFsm) RemoveUniFlowParams(ctx context.Context, aCookie uint64, respChan *chan error) error {
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000829 if oFsm == nil {
830 logger.Error(ctx, "no valid UniVlanConfigFsm!")
831 return fmt.Errorf("no-valid-UniVlanConfigFsm")
832 }
mpagenkof1fc3862021-02-16 10:09:52 +0000833 var deletedCookie uint64
mpagenko01e726e2020-10-23 09:45:29 +0000834 flowCookieMatch := false
835 //mutex protection is required for possible concurrent access to FSM members
836 oFsm.mutexFlowParams.Lock()
837 defer oFsm.mutexFlowParams.Unlock()
mpagenkof1fc3862021-02-16 10:09:52 +0000838remove_loop:
mpagenko01e726e2020-10-23 09:45:29 +0000839 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
840 for i, cookie := range storedUniFlowParams.CookieSlice {
841 if cookie == aCookie {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000842 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - cookie found", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000843 "device-id": oFsm.deviceID, "cookie": cookie})
mpagenkof1fc3862021-02-16 10:09:52 +0000844 deletedCookie = aCookie
mpagenko01e726e2020-10-23 09:45:29 +0000845 //remove the cookie from the cookie slice and verify it is getting empty
846 if len(storedUniFlowParams.CookieSlice) == 1 {
mpagenkof582d6a2021-06-18 15:58:10 +0000847 // had to shift content to function due to sca complexity
Girish Gowdrae95687a2021-09-08 16:30:58 -0700848 flowCookieMatch = oFsm.removeRuleComplete(ctx, storedUniFlowParams, aCookie, respChan)
mpagenkodee02a62021-07-21 10:56:10 +0000849 //persistencyData write is now part of removeRuleComplete() (on success)
mpagenko01e726e2020-10-23 09:45:29 +0000850 } else {
mpagenkof582d6a2021-06-18 15:58:10 +0000851 flowCookieMatch = true
mpagenko01e726e2020-10-23 09:45:29 +0000852 //cut off the requested cookie by slicing out this element
853 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(
854 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[:i],
855 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[i+1:]...)
mpagenkofc4f56e2020-11-04 17:17:49 +0000856 // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately
857 // state transition notification is checked in deviceHandler
858 if oFsm.pDeviceHandler != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000859 // success indication without the need to write to kvStore (done already below with updated data from StorePersUniFlowConfig())
860 go oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetRemoveNoKvStore))
mpagenkofc4f56e2020-11-04 17:17:49 +0000861 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000862 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - rule persists with still valid cookies", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000863 "device-id": oFsm.deviceID, "cookies": oFsm.uniVlanFlowParamsSlice[flow].CookieSlice})
mpagenkof1fc3862021-02-16 10:09:52 +0000864 if deletedCookie == oFsm.delayNewRuleCookie {
865 //the delayedNewCookie is the one that is currently deleted, but the rule still exist with other cookies
866 //as long as there are further cookies for this rule indicate there is still some cookie to be deleted
867 //simply use the first one
868 oFsm.delayNewRuleCookie = oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[0]
869 logger.Debugw(ctx, "UniVlanConfigFsm remaining cookie awaited for deletion before new rule add", log.Fields{
870 "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie})
871 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700872 // Push response on the response channel
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000873 oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, nil)
mpagenkodee02a62021-07-21 10:56:10 +0000874 //permanently store the modified flow config for reconcile case and immediately write to KvStore
875 if oFsm.pDeviceHandler != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000876 if err := oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID,
mpagenkodee02a62021-07-21 10:56:10 +0000877 &oFsm.uniVlanFlowParamsSlice, true); err != nil {
878 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
879 return err
880 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000881 }
mpagenko01e726e2020-10-23 09:45:29 +0000882 }
mpagenkof1fc3862021-02-16 10:09:52 +0000883 break remove_loop //found the cookie - no further search for this requested cookie
mpagenko01e726e2020-10-23 09:45:29 +0000884 }
885 }
mpagenko01e726e2020-10-23 09:45:29 +0000886 } //search all flows
887 if !flowCookieMatch { //some cookie remove-request for a cookie that does not exist in the FSM data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000888 logger.Warnw(ctx, "UniVlanConfigFsm flow removal - remove-cookie not found", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000889 "device-id": oFsm.deviceID, "remove-cookie": aCookie})
890 // but accept the request with success as no such cookie (flow) does exist
mpagenkofc4f56e2020-11-04 17:17:49 +0000891 // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately
892 // state transition notification is checked in deviceHandler
893 if oFsm.pDeviceHandler != nil {
mpagenkof1fc3862021-02-16 10:09:52 +0000894 // success indication without the need to write to kvStore (no change)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000895 go oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetRemoveNoKvStore))
mpagenkofc4f56e2020-11-04 17:17:49 +0000896 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700897 // Push response on the response channel
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000898 oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, nil)
mpagenko01e726e2020-10-23 09:45:29 +0000899 return nil
900 } //unknown cookie
901
902 return nil
903}
904
mpagenkof582d6a2021-06-18 15:58:10 +0000905// removeRuleComplete initiates the complete removal of a VLAN rule (from single cookie element)
mpagenkodee02a62021-07-21 10:56:10 +0000906// requires mutexFlowParams to be locked at call
mpagenkof582d6a2021-06-18 15:58:10 +0000907func (oFsm *UniVlanConfigFsm) removeRuleComplete(ctx context.Context,
Girish Gowdrae95687a2021-09-08 16:30:58 -0700908 aUniFlowParams cmn.UniVlanFlowParams, aCookie uint64, respChan *chan error) bool {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000909 pConfigVlanStateBaseFsm := oFsm.PAdaptFsm.PFsm
mpagenkof582d6a2021-06-18 15:58:10 +0000910 var cancelPendingConfig bool = false
911 var loRemoveParams uniRemoveVlanFlowParams = uniRemoveVlanFlowParams{}
912 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - full flow removal", log.Fields{
913 "device-id": oFsm.deviceID})
914 //rwCore flow recovery may be the reason for this delete, in which case the flowToBeDeleted may be the same
915 // as the one still waiting in the FSM as toAdd but waiting for TechProfileConfig
916 // so we have to check if we have to abort the outstanding AddRequest and regard the current DelRequest as done
917 // 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 +0000918 if pConfigVlanStateBaseFsm.Is(VlanStWaitingTechProf) {
mpagenkof582d6a2021-06-18 15:58:10 +0000919 logger.Debugw(ctx, "UniVlanConfigFsm was waiting for TechProf config with add-request, just aborting the outstanding add",
920 log.Fields{"device-id": oFsm.deviceID})
921 cancelPendingConfig = true
922 } else {
923 //create a new element for the removeVlanFlow slice
924 loRemoveParams = uniRemoveVlanFlowParams{
925 vlanRuleParams: aUniFlowParams.VlanRuleParams,
926 cookie: aCookie,
Girish Gowdrae95687a2021-09-08 16:30:58 -0700927 respChan: respChan,
mpagenkof582d6a2021-06-18 15:58:10 +0000928 }
929 loRemoveParams.removeChannel = make(chan bool)
930 oFsm.uniRemoveFlowsSlice = append(oFsm.uniRemoveFlowsSlice, loRemoveParams)
931 }
932
933 usedTpID := aUniFlowParams.VlanRuleParams.TpID
934 if len(oFsm.uniVlanFlowParamsSlice) <= 1 {
935 //at this point it is evident that no flow anymore will refer to a still possibly active Techprofile
936 //request that this profile gets deleted before a new flow add is allowed (except for some aborted add)
937 if !cancelPendingConfig {
mpagenko3ce9fa02021-07-28 13:26:54 +0000938 // ensure mutexFlowParams not locked before calling some TPProcessing activity (that might already be pending on it)
939 oFsm.mutexFlowParams.Unlock()
mpagenkof582d6a2021-06-18 15:58:10 +0000940 logger.Debugw(ctx, "UniVlanConfigFsm flow removal requested - set TechProfile to-delete", log.Fields{
941 "device-id": oFsm.deviceID})
942 if oFsm.pUniTechProf != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000943 oFsm.pUniTechProf.SetProfileToDelete(oFsm.pOnuUniPort.UniID, usedTpID, true)
mpagenkof582d6a2021-06-18 15:58:10 +0000944 }
mpagenko3ce9fa02021-07-28 13:26:54 +0000945 oFsm.mutexFlowParams.Lock()
mpagenkof582d6a2021-06-18 15:58:10 +0000946 }
947 } else {
948 if !cancelPendingConfig {
949 oFsm.updateTechProfileToDelete(ctx, usedTpID)
950 }
951 }
952 //trigger the FSM to remove the relevant rule
953 if cancelPendingConfig {
954 //as the uniFlow parameters are already stored (for add) but no explicit removal is done anymore
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000955 // the paramSlice has to be updated with rule-removal, which also then updates NumUniFlows
mpagenkof582d6a2021-06-18 15:58:10 +0000956 //call from 'non-configured' state of the rules
957 if err := oFsm.removeFlowFromParamsSlice(ctx, aCookie, false); err != nil {
958 //something quite inconsistent detected, perhaps just try to recover with FSM reset
959 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000960 if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvReset); fsmErr != nil {
mpagenkof582d6a2021-06-18 15:58:10 +0000961 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
962 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
963 }
964 return false //data base update could not be done, return like cookie not found
965 }
966
967 oFsm.requestEventOffset = uint8(cDeviceEventOffsetRemoveWithKvStore) //offset for last flow-remove activity (with kvStore request)
968 //attention: take care to release and re-take the mutexFlowParams when calling the FSM directly -
969 // synchronous FSM 'event/state' functions may rely on this mutex
970 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000971 if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvCancelOutstandingConfig); fsmErr != nil {
mpagenkof582d6a2021-06-18 15:58:10 +0000972 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
973 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
974 }
975 oFsm.mutexFlowParams.Lock()
976 return true
977 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000978 if pConfigVlanStateBaseFsm.Is(VlanStConfigDone) {
mpagenkof582d6a2021-06-18 15:58:10 +0000979 logger.Debugw(ctx, "UniVlanConfigFsm rule removal request", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000980 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenkof582d6a2021-06-18 15:58:10 +0000981 "tp-id": loRemoveParams.vlanRuleParams.TpID,
982 "set-Vlan": loRemoveParams.vlanRuleParams.SetVid})
983 //have to re-trigger the FSM to proceed with outstanding incremental flow configuration
984 //attention: take care to release and re-take the mutexFlowParams when calling the FSM directly -
985 // synchronous FSM 'event/state' functions may rely on this mutex
986 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000987 if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvRemFlowConfig); fsmErr != nil {
mpagenkof582d6a2021-06-18 15:58:10 +0000988 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
989 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
990 }
991 oFsm.mutexFlowParams.Lock()
992 } // if not in the appropriate state a new entry will be automatically considered later
993 // when the configDone state is reached
994 return true
995}
996
mpagenkof1d21d12021-06-11 13:14:45 +0000997//removeFlowFromParamsSlice removes a flow from stored uniVlanFlowParamsSlice based on the cookie
998// it assumes that adding cookies for this flow (including the actual one to delete) was prevented
999// from the start of the deletion request to avoid to much interference
1000// so when called, there can only be one cookie active for this flow
1001// requires mutexFlowParams to be locked at call
mpagenkof582d6a2021-06-18 15:58:10 +00001002func (oFsm *UniVlanConfigFsm) removeFlowFromParamsSlice(ctx context.Context, aCookie uint64, aWasConfigured bool) error {
mpagenkof1d21d12021-06-11 13:14:45 +00001003 logger.Debugw(ctx, "UniVlanConfigFsm flow removal from ParamsSlice", log.Fields{
1004 "device-id": oFsm.deviceID, "cookie": aCookie})
mpagenkof582d6a2021-06-18 15:58:10 +00001005 cookieFound := false
mpagenkof1d21d12021-06-11 13:14:45 +00001006removeFromSlice_loop:
1007 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
mpagenkof582d6a2021-06-18 15:58:10 +00001008 // if UniFlowParams exists, cookieSlice should always have at least one element
1009 cookieSliceLen := len(storedUniFlowParams.CookieSlice)
1010 if cookieSliceLen == 1 {
1011 if storedUniFlowParams.CookieSlice[0] == aCookie {
1012 cookieFound = true
mpagenkof1d21d12021-06-11 13:14:45 +00001013 }
mpagenkof582d6a2021-06-18 15:58:10 +00001014 } else if cookieSliceLen == 0 {
1015 errStr := "UniVlanConfigFsm unexpected cookie slice length 0 - removal in uniVlanFlowParamsSlice aborted"
1016 logger.Errorw(ctx, errStr, log.Fields{"device-id": oFsm.deviceID})
1017 return errors.New(errStr)
1018 } else {
1019 errStr := "UniVlanConfigFsm flow removal unexpected cookie slice length, but rule removal continued"
1020 logger.Errorw(ctx, errStr, log.Fields{
1021 "cookieSliceLen": len(oFsm.uniVlanFlowParamsSlice), "device-id": oFsm.deviceID})
1022 for _, cookie := range storedUniFlowParams.CookieSlice {
1023 if cookie == aCookie {
1024 cookieFound = true
1025 break
1026 }
1027 }
1028 }
1029 if cookieFound {
mpagenkof1d21d12021-06-11 13:14:45 +00001030 logger.Debugw(ctx, "UniVlanConfigFsm flow removal from ParamsSlice - cookie found", log.Fields{
1031 "device-id": oFsm.deviceID, "cookie": aCookie})
1032 //remove the actual element from the addVlanFlow slice
1033 // oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = nil //automatically done by garbage collector
1034 if len(oFsm.uniVlanFlowParamsSlice) <= 1 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001035 oFsm.NumUniFlows = 0 //no more flows
1036 oFsm.ConfiguredUniFlow = 0 //no more flows configured
mpagenkof1d21d12021-06-11 13:14:45 +00001037 oFsm.uniVlanFlowParamsSlice = nil //reset the slice
1038 //at this point it is evident that no flow anymore refers to a still possibly active Techprofile
1039 //request that this profile gets deleted before a new flow add is allowed
1040 logger.Debugw(ctx, "UniVlanConfigFsm flow removal from ParamsSlice - no more flows", log.Fields{
1041 "device-id": oFsm.deviceID})
1042 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001043 oFsm.NumUniFlows--
1044 if aWasConfigured && oFsm.ConfiguredUniFlow > 0 {
1045 oFsm.ConfiguredUniFlow--
mpagenkof1d21d12021-06-11 13:14:45 +00001046 }
Girish Gowdrae95687a2021-09-08 16:30:58 -07001047 if !aWasConfigured {
1048 // We did not actually process this flow but was removed before that.
1049 // Indicate success response for the flow to caller who is blocking on a response
Holger Hildebrandtc192bc42021-10-28 14:38:31 +00001050 oFsm.pushReponseOnFlowResponseChannel(ctx, storedUniFlowParams.RespChan, nil)
Girish Gowdrae95687a2021-09-08 16:30:58 -07001051 }
1052
mpagenkof1d21d12021-06-11 13:14:45 +00001053 //cut off the requested flow by slicing out this element
1054 oFsm.uniVlanFlowParamsSlice = append(
1055 oFsm.uniVlanFlowParamsSlice[:flow], oFsm.uniVlanFlowParamsSlice[flow+1:]...)
1056 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - specific flow removed from data", log.Fields{
1057 "device-id": oFsm.deviceID})
1058 }
1059 break removeFromSlice_loop //found the cookie - no further search for this requested cookie
1060 }
1061 } //search all flows
mpagenkof582d6a2021-06-18 15:58:10 +00001062 if !cookieFound {
1063 errStr := "UniVlanConfigFsm cookie for removal not found, internal counter not updated"
1064 logger.Errorw(ctx, errStr, log.Fields{"device-id": oFsm.deviceID})
1065 return errors.New(errStr)
1066 }
mpagenkodee02a62021-07-21 10:56:10 +00001067 //if the cookie was found and removed from uniVlanFlowParamsSlice above now write the modified persistency data
1068 // KVStore update will be done after reaching the requested FSM end state (not immediately here)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001069 if err := oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID,
mpagenkodee02a62021-07-21 10:56:10 +00001070 &oFsm.uniVlanFlowParamsSlice, false); err != nil {
1071 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
1072 return err
1073 }
mpagenkof582d6a2021-06-18 15:58:10 +00001074 return nil
mpagenkof1d21d12021-06-11 13:14:45 +00001075}
1076
1077// requires mutexFlowParams to be locked at call
mpagenkof1fc3862021-02-16 10:09:52 +00001078func (oFsm *UniVlanConfigFsm) updateTechProfileToDelete(ctx context.Context, usedTpID uint8) {
1079 //here we have to check, if there are still other flows referencing to the actual ProfileId
1080 // before we can request that this profile gets deleted before a new flow add is allowed
1081 tpIDInOtherFlows := false
1082 for _, tpUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
1083 if tpUniFlowParams.VlanRuleParams.TpID == usedTpID {
1084 tpIDInOtherFlows = true
1085 break // search loop can be left
1086 }
1087 }
1088 if tpIDInOtherFlows {
1089 logger.Debugw(ctx, "UniVlanConfigFsm tp-id used in deleted flow is still used in other flows", log.Fields{
1090 "device-id": oFsm.deviceID, "tp-id": usedTpID})
1091 } else {
mpagenkof1d21d12021-06-11 13:14:45 +00001092 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 +00001093 "device-id": oFsm.deviceID, "tp-id": usedTpID})
mpagenko3ce9fa02021-07-28 13:26:54 +00001094 // ensure mutexFlowParams not locked before calling some TPProcessing activity (that might already be pending on it)
1095 oFsm.mutexFlowParams.Unlock()
mpagenkof1d21d12021-06-11 13:14:45 +00001096 if oFsm.pUniTechProf != nil {
1097 //request that this profile gets deleted before a new flow add is allowed
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001098 oFsm.pUniTechProf.SetProfileToDelete(oFsm.pOnuUniPort.UniID, usedTpID, true)
mpagenkof1d21d12021-06-11 13:14:45 +00001099 }
mpagenko3ce9fa02021-07-28 13:26:54 +00001100 oFsm.mutexFlowParams.Lock()
mpagenkof1fc3862021-02-16 10:09:52 +00001101 }
1102}
1103
mpagenkof1d21d12021-06-11 13:14:45 +00001104func (oFsm *UniVlanConfigFsm) enterPreparing(ctx context.Context, e *fsm.Event) {
1105 logger.Debugw(ctx, "UniVlanConfigFsm preparing", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001106
1107 // this FSM is not intended for re-start, needs always new creation for a new run
mpagenko01e726e2020-10-23 09:45:29 +00001108 // (self-destroying - compare enterDisabled())
mpagenkodff5dda2020-08-28 11:52:01 +00001109 oFsm.omciMIdsResponseReceived = make(chan bool)
mpagenkof1fc3862021-02-16 10:09:52 +00001110 oFsm.chCookieDeleted = make(chan bool)
mpagenkodff5dda2020-08-28 11:52:01 +00001111 // start go routine for processing of LockState messages
dbainbri4d3a0dc2020-12-02 00:33:42 +00001112 go oFsm.processOmciVlanMessages(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00001113 //let the state machine run forward from here directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001114 pConfigVlanStateAFsm := oFsm.PAdaptFsm
mpagenkodff5dda2020-08-28 11:52:01 +00001115 if pConfigVlanStateAFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001116 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001117 logger.Debugw(ctx, "reconciling - skip omci-config of vlan rule",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001118 log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID})
mpagenkof1d21d12021-06-11 13:14:45 +00001119 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001120 go func(a_pAFsm *cmn.AdapterFsm) {
1121 _ = a_pAFsm.PFsm.Event(VlanEvSkipOmciConfig)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001122 }(pConfigVlanStateAFsm)
1123 return
1124 }
mpagenkof1d21d12021-06-11 13:14:45 +00001125 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001126 go func(a_pAFsm *cmn.AdapterFsm) {
1127 _ = a_pAFsm.PFsm.Event(VlanEvPrepareDone)
mpagenkof1d21d12021-06-11 13:14:45 +00001128 }(pConfigVlanStateAFsm)
1129 return
1130 }
1131 logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{
1132 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
1133 //should never happen, else: recovery would be needed from outside the FSM
1134}
1135
1136func (oFsm *UniVlanConfigFsm) enterConfigStarting(ctx context.Context, e *fsm.Event) {
1137 logger.Debugw(ctx, "UniVlanConfigFsm start vlan configuration", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001138 pConfigVlanStateAFsm := oFsm.PAdaptFsm
mpagenkof1d21d12021-06-11 13:14:45 +00001139 if pConfigVlanStateAFsm != nil {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001140 oFsm.mutexFlowParams.Lock()
mpagenko9a304ea2020-12-16 15:54:01 +00001141 //possibly the entry is not valid anymore based on intermediate delete requests
1142 //just a basic protection ...
1143 if len(oFsm.uniVlanFlowParamsSlice) == 0 {
1144 oFsm.mutexFlowParams.Unlock()
1145 logger.Debugw(ctx, "UniVlanConfigFsm start: no rule entry anymore available", log.Fields{
1146 "device-id": oFsm.deviceID})
1147 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001148 go func(a_pAFsm *cmn.AdapterFsm) {
1149 _ = a_pAFsm.PFsm.Event(VlanEvReset)
mpagenko9a304ea2020-12-16 15:54:01 +00001150 }(pConfigVlanStateAFsm)
1151 return
1152 }
mpagenko9a304ea2020-12-16 15:54:01 +00001153 //access to uniVlanFlowParamsSlice is done on first element only here per definition
1154 //store the actual rule that shall be worked upon in the following transient states
Girish Gowdrae95687a2021-09-08 16:30:58 -07001155 oFsm.actualUniFlowParam = oFsm.uniVlanFlowParamsSlice[0]
1156 tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID
mpagenko9a304ea2020-12-16 15:54:01 +00001157 oFsm.TpIDWaitingFor = tpID
Girish Gowdrae95687a2021-09-08 16:30:58 -07001158 loSetVlan := oFsm.actualUniFlowParam.VlanRuleParams.SetVid
mpagenko45cc6a32021-07-23 10:06:57 +00001159 //attention: take care to release the mutexFlowParams when calling the FSM directly -
1160 // synchronous FSM 'event/state' functions may rely on this mutex
1161 // but it must be released already before calling getTechProfileDone() as it may already be locked
1162 // by the techProfile processing call to VlanFsm.IsFlowRemovePending() (see VOL-4207)
Girish Gowdra24dd1132021-07-06 15:25:40 -07001163 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001164 loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.UniID, uint8(tpID))
mpagenko9a304ea2020-12-16 15:54:01 +00001165 logger.Debugw(ctx, "UniVlanConfigFsm - start with first rule", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001166 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko45cc6a32021-07-23 10:06:57 +00001167 "set-Vlan": loSetVlan, "tp-id": tpID, "ProfDone": loTechProfDone})
Girish Gowdra24dd1132021-07-06 15:25:40 -07001168
mpagenko9a304ea2020-12-16 15:54:01 +00001169 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001170 go func(aPAFsm *cmn.AdapterFsm, aTechProfDone bool) {
1171 if aPAFsm != nil && aPAFsm.PFsm != nil {
mpagenko551a4d42020-12-08 18:09:20 +00001172 if aTechProfDone {
mpagenkodff5dda2020-08-28 11:52:01 +00001173 // let the vlan processing begin
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001174 _ = aPAFsm.PFsm.Event(VlanEvStartConfig)
mpagenkodff5dda2020-08-28 11:52:01 +00001175 } else {
1176 // set to waiting for Techprofile
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001177 _ = aPAFsm.PFsm.Event(VlanEvWaitTechProf)
mpagenkodff5dda2020-08-28 11:52:01 +00001178 }
1179 }
mpagenko551a4d42020-12-08 18:09:20 +00001180 }(pConfigVlanStateAFsm, loTechProfDone)
1181 } else {
1182 logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{
1183 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
1184 //should never happen, else: recovery would be needed from outside the FSM
1185 return
mpagenkodff5dda2020-08-28 11:52:01 +00001186 }
1187}
1188
dbainbri4d3a0dc2020-12-02 00:33:42 +00001189func (oFsm *UniVlanConfigFsm) enterConfigVtfd(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001190 //mutex protection is required for possible concurrent access to FSM members
1191 oFsm.mutexFlowParams.Lock()
mpagenko551a4d42020-12-08 18:09:20 +00001192 oFsm.TpIDWaitingFor = 0 //reset indication to avoid misinterpretation
Girish Gowdrae95687a2021-09-08 16:30:58 -07001193 if oFsm.actualUniFlowParam.VlanRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
mpagenkodff5dda2020-08-28 11:52:01 +00001194 // meaning transparent setup - no specific VTFD setting required
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001195 oFsm.mutexFlowParams.Unlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001196 logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD config required", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001197 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001198 // let the FSM proceed ... (from within this state all internal pointers may be expected to be correct)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001199 pConfigVlanStateAFsm := oFsm.PAdaptFsm
mpagenko9a304ea2020-12-16 15:54:01 +00001200 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001201 go func(a_pAFsm *cmn.AdapterFsm) {
1202 _ = a_pAFsm.PFsm.Event(VlanEvRxConfigVtfd)
mpagenkodff5dda2020-08-28 11:52:01 +00001203 }(pConfigVlanStateAFsm)
1204 } else {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001205 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
1206 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
Girish Gowdrae95687a2021-09-08 16:30:58 -07001207 vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.actualUniFlowParam.VlanRuleParams.TpID))
dbainbri4d3a0dc2020-12-02 00:33:42 +00001208 logger.Debugw(ctx, "UniVlanConfigFsm create VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001209 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
Mahir Gunyel6781f962021-05-16 23:30:08 -07001210 "in state": e.FSM.Current(), "device-id": oFsm.deviceID,
Girish Gowdrae95687a2021-09-08 16:30:58 -07001211 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": oFsm.actualUniFlowParam.VlanRuleParams.TpID})
mpagenko01e726e2020-10-23 09:45:29 +00001212 // setVid is assumed to be masked already by the caller to 12 bit
Girish Gowdrae95687a2021-09-08 16:30:58 -07001213 oFsm.vlanFilterList[0] = uint16(oFsm.actualUniFlowParam.VlanRuleParams.SetVid)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001214 oFsm.mutexFlowParams.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00001215 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001216 vtfdFilterList[0] = oFsm.vlanFilterList[0]
1217 oFsm.numVlanFilterEntries = 1
mpagenkodff5dda2020-08-28 11:52:01 +00001218 meParams := me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001219 EntityID: vtfdID,
mpagenkodff5dda2020-08-28 11:52:01 +00001220 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001221 me.VlanTaggingFilterData_VlanFilterList: vtfdFilterList, //omci lib wants a slice for serialization
1222 me.VlanTaggingFilterData_ForwardOperation: uint8(0x10), //VID investigation
1223 me.VlanTaggingFilterData_NumberOfEntries: oFsm.numVlanFilterEntries,
mpagenkodff5dda2020-08-28 11:52:01 +00001224 },
1225 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001226 logger.Debugw(ctx, "UniVlanConfigFsm sendcreate VTFD", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001227 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001228 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001229 meInstance, err := oFsm.pOmciCC.SendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1230 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001231 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001232 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001233 logger.Errorw(ctx, "VTFD create failed, aborting UniVlanConfig FSM!",
1234 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001235 pConfigVlanStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001236 if pConfigVlanStateAFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001237 go func(a_pAFsm *cmn.AdapterFsm) {
1238 _ = a_pAFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001239 }(pConfigVlanStateAFsm)
1240 }
1241 return
1242 }
mpagenkodff5dda2020-08-28 11:52:01 +00001243 //accept also nil as (error) return value for writing to LastTx
1244 // - this avoids misinterpretation of new received OMCI messages
1245 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1246 // send shall return (dual format) error code that can be used here for immediate error treatment
1247 // (relevant to all used sendXX() methods in this (and other) FSM's)
mpagenko01e726e2020-10-23 09:45:29 +00001248 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001249 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001250 }
1251}
1252
dbainbri4d3a0dc2020-12-02 00:33:42 +00001253func (oFsm *UniVlanConfigFsm) enterConfigEvtocd(ctx context.Context, e *fsm.Event) {
1254 logger.Debugw(ctx, "UniVlanConfigFsm - start config EVTOCD loop", log.Fields{
mpagenkof1d21d12021-06-11 13:14:45 +00001255 "device-id": oFsm.deviceID})
mpagenkof1fc3862021-02-16 10:09:52 +00001256 oFsm.requestEventOffset = uint8(cDeviceEventOffsetAddWithKvStore) //0 offset for last flow-add activity
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001257 go func() {
mpagenko9a304ea2020-12-16 15:54:01 +00001258 //using the first element in the slice because it's the first flow per definition here
1259 errEvto := oFsm.performConfigEvtocdEntries(ctx, 0)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001260 //This is correct passing scenario
1261 if errEvto == nil {
mpagenkof1d21d12021-06-11 13:14:45 +00001262 oFsm.mutexFlowParams.RLock()
Girish Gowdrae95687a2021-09-08 16:30:58 -07001263 tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID
1264 vlanID := oFsm.actualUniFlowParam.VlanRuleParams.SetVid
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001265 configuredUniFlows := oFsm.ConfiguredUniFlow
mpagenko3ce9fa02021-07-28 13:26:54 +00001266 // ensure mutexFlowParams not locked before calling some TPProcessing activity (that might already be pending on it)
1267 oFsm.mutexFlowParams.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001268 for _, gemPort := range oFsm.pUniTechProf.getMulticastGemPorts(ctx, oFsm.pOnuUniPort.UniID, uint8(tpID)) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001269 logger.Infow(ctx, "Setting multicast MEs, with first flow", log.Fields{"deviceID": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001270 "techProfile": tpID, "gemPort": gemPort, "vlanID": vlanID, "ConfiguredUniFlow": configuredUniFlows})
dbainbri4d3a0dc2020-12-02 00:33:42 +00001271 errCreateAllMulticastME := oFsm.performSettingMulticastME(ctx, tpID, gemPort,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001272 vlanID)
1273 if errCreateAllMulticastME != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001274 logger.Errorw(ctx, "Multicast ME create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001275 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001276 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001277 }
1278 }
ozgecanetsia82b91a62021-05-21 18:54:49 +03001279 //If this first flow contains a meter, then create TD for related gems.
Girish Gowdrae95687a2021-09-08 16:30:58 -07001280 if oFsm.actualUniFlowParam.Meter != nil {
1281 logger.Debugw(ctx, "Creating Traffic Descriptor", log.Fields{"device-id": oFsm.deviceID, "meter": oFsm.actualUniFlowParam.Meter})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001282 for _, gemPort := range oFsm.pUniTechProf.getBidirectionalGemPortIDsForTP(ctx, oFsm.pOnuUniPort.UniID, tpID) {
Girish Gowdrae95687a2021-09-08 16:30:58 -07001283 logger.Debugw(ctx, "Creating Traffic Descriptor for gem", log.Fields{"device-id": oFsm.deviceID, "meter": oFsm.actualUniFlowParam.Meter, "gem": gemPort})
1284 errCreateTrafficDescriptor := oFsm.createTrafficDescriptor(ctx, oFsm.actualUniFlowParam.Meter, tpID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001285 oFsm.pOnuUniPort.UniID, gemPort)
ozgecanetsia82b91a62021-05-21 18:54:49 +03001286 if errCreateTrafficDescriptor != nil {
1287 logger.Errorw(ctx, "Create Traffic Descriptor create failed, aborting Ani Config FSM!",
1288 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001289 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsia82b91a62021-05-21 18:54:49 +03001290 }
1291 }
1292 }
1293
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001294 //TODO Possibly insert new state for multicast --> possibly another jira/later time.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001295 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvRxConfigEvtocd)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001296 }
1297 }()
mpagenkodff5dda2020-08-28 11:52:01 +00001298}
1299
dbainbri4d3a0dc2020-12-02 00:33:42 +00001300func (oFsm *UniVlanConfigFsm) enterVlanConfigDone(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001301
mpagenkof1d21d12021-06-11 13:14:45 +00001302 oFsm.mutexFlowParams.Lock()
mpagenko9a304ea2020-12-16 15:54:01 +00001303
mpagenkof1fc3862021-02-16 10:09:52 +00001304 logger.Infow(ctx, "UniVlanConfigFsm config done - checking on more flows", log.Fields{
mpagenkof1d21d12021-06-11 13:14:45 +00001305 "device-id": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001306 "overall-uni-rules": oFsm.NumUniFlows, "configured-uni-rules": oFsm.ConfiguredUniFlow})
mpagenko101ac942021-11-16 15:01:29 +00001307 if len(oFsm.uniVlanFlowParamsSlice) > 0 && !oFsm.pDeviceHandler.IsReconciling() {
Holger Hildebrandtc192bc42021-10-28 14:38:31 +00001308 oFsm.pushReponseOnFlowResponseChannel(ctx, oFsm.actualUniFlowParam.RespChan, nil)
Girish Gowdrae95687a2021-09-08 16:30:58 -07001309 }
1310
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001311 pConfigVlanStateAFsm := oFsm.PAdaptFsm
mpagenko551a4d42020-12-08 18:09:20 +00001312 if pConfigVlanStateAFsm == nil {
mpagenkof1d21d12021-06-11 13:14:45 +00001313 oFsm.mutexFlowParams.Unlock()
mpagenko551a4d42020-12-08 18:09:20 +00001314 logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{
1315 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
1316 //should never happen, else: recovery would be needed from outside the FSM
1317 return
1318 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001319 pConfigVlanStateBaseFsm := pConfigVlanStateAFsm.PFsm
mpagenko01e726e2020-10-23 09:45:29 +00001320 if len(oFsm.uniRemoveFlowsSlice) > 0 {
1321 //some further flows are to be removed, removal always starts with the first element
mpagenko9a304ea2020-12-16 15:54:01 +00001322 logger.Debugw(ctx, "UniVlanConfigFsm rule removal from ConfigDone", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001323 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko9a304ea2020-12-16 15:54:01 +00001324 "tp-id": oFsm.uniRemoveFlowsSlice[0].vlanRuleParams.TpID,
1325 "set-Vlan": oFsm.uniRemoveFlowsSlice[0].vlanRuleParams.SetVid})
mpagenkof1d21d12021-06-11 13:14:45 +00001326 oFsm.mutexFlowParams.Unlock()
mpagenko9a304ea2020-12-16 15:54:01 +00001327 // Can't call FSM Event directly, decoupling it
mpagenko01e726e2020-10-23 09:45:29 +00001328 go func(a_pBaseFsm *fsm.FSM) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001329 _ = a_pBaseFsm.Event(VlanEvRemFlowConfig)
mpagenko01e726e2020-10-23 09:45:29 +00001330 }(pConfigVlanStateBaseFsm)
1331 return
1332 }
Holger Hildebrandt7741f272022-01-18 08:17:39 +00001333 if oFsm.lastFlowToReconcile {
1334 //note: lastFlowToReconcile does not mean that this block may run only once within reconcilement here,
1335 // due to asynchronous event processing from SetUniFlowParams() it may be executed multiple times
1336 logger.Debugw(ctx, "reconciling - flow processing finished", log.Fields{
1337 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
1338 oFsm.pDeviceHandler.SendChUniVlanConfigFinished(uint16(oFsm.pOnuUniPort.UniID))
1339 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001340 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
1341 oFsm.ConfiguredUniFlow = oFsm.NumUniFlows
Holger Hildebrandt1b8f4ad2021-03-25 15:53:51 +00001342 logger.Debugw(ctx, "reconciling - skip enterVlanConfigDone processing",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001343 log.Fields{"NumUniFlows": oFsm.NumUniFlows, "ConfiguredUniFlow": oFsm.ConfiguredUniFlow, "device-id": oFsm.deviceID})
mpagenkof1d21d12021-06-11 13:14:45 +00001344 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt1b8f4ad2021-03-25 15:53:51 +00001345 return
1346 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001347 if oFsm.NumUniFlows > oFsm.ConfiguredUniFlow {
1348 if oFsm.ConfiguredUniFlow == 0 {
mpagenkof1d21d12021-06-11 13:14:45 +00001349 oFsm.mutexFlowParams.Unlock()
mpagenko551a4d42020-12-08 18:09:20 +00001350 // this is a restart with a complete new flow, we can re-use the initial flow config control
1351 // including the check, if the related techProfile is (still) available (probably also removed in between)
mpagenko9a304ea2020-12-16 15:54:01 +00001352 // Can't call FSM Event directly, decoupling it
mpagenko551a4d42020-12-08 18:09:20 +00001353 go func(a_pBaseFsm *fsm.FSM) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001354 _ = a_pBaseFsm.Event(VlanEvRenew)
mpagenko551a4d42020-12-08 18:09:20 +00001355 }(pConfigVlanStateBaseFsm)
1356 return
1357 }
1358
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001359 //some further flows are to be configured
mpagenko9a304ea2020-12-16 15:54:01 +00001360 //store the actual rule that shall be worked upon in the following transient states
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001361 if len(oFsm.uniVlanFlowParamsSlice) < int(oFsm.ConfiguredUniFlow) {
mpagenkof1d21d12021-06-11 13:14:45 +00001362 //check introduced after having observed some panic in this processing
1363 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm in ConfigDone - inconsistent counter",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001364 log.Fields{"ConfiguredUniFlow": oFsm.ConfiguredUniFlow,
mpagenkof1d21d12021-06-11 13:14:45 +00001365 "sliceLen": len(oFsm.uniVlanFlowParamsSlice), "device-id": oFsm.deviceID})
1366 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001367 go func(a_pAFsm *cmn.AdapterFsm) {
1368 _ = a_pAFsm.PFsm.Event(VlanEvReset)
mpagenkof1d21d12021-06-11 13:14:45 +00001369 }(pConfigVlanStateAFsm)
1370 return
1371 }
Girish Gowdrae95687a2021-09-08 16:30:58 -07001372 oFsm.actualUniFlowParam = oFsm.uniVlanFlowParamsSlice[oFsm.ConfiguredUniFlow]
mpagenko551a4d42020-12-08 18:09:20 +00001373 //tpId of the next rule to be configured
Girish Gowdrae95687a2021-09-08 16:30:58 -07001374 tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID
mpagenko551a4d42020-12-08 18:09:20 +00001375 oFsm.TpIDWaitingFor = tpID
Girish Gowdrae95687a2021-09-08 16:30:58 -07001376 loSetVlan := oFsm.actualUniFlowParam.VlanRuleParams.SetVid
mpagenko45cc6a32021-07-23 10:06:57 +00001377 //attention: take care to release the mutexFlowParams when calling the FSM directly -
1378 // synchronous FSM 'event/state' functions may rely on this mutex
1379 // but it must be released already before calling getTechProfileDone() as it may already be locked
1380 // by the techProfile processing call to VlanFsm.IsFlowRemovePending() (see VOL-4207)
1381 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001382 loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.UniID, tpID)
mpagenko9a304ea2020-12-16 15:54:01 +00001383 logger.Debugw(ctx, "UniVlanConfigFsm - incremental config request", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001384 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko45cc6a32021-07-23 10:06:57 +00001385 "set-Vlan": loSetVlan, "tp-id": tpID, "ProfDone": loTechProfDone})
1386
mpagenko9a304ea2020-12-16 15:54:01 +00001387 // Can't call FSM Event directly, decoupling it
mpagenko551a4d42020-12-08 18:09:20 +00001388 go func(aPBaseFsm *fsm.FSM, aTechProfDone bool) {
1389 if aTechProfDone {
1390 // let the vlan processing continue with next rule
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001391 _ = aPBaseFsm.Event(VlanEvIncrFlowConfig)
mpagenko551a4d42020-12-08 18:09:20 +00001392 } else {
1393 // set to waiting for Techprofile
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001394 _ = aPBaseFsm.Event(VlanEvWaitTPIncr)
mpagenko551a4d42020-12-08 18:09:20 +00001395 }
1396 }(pConfigVlanStateBaseFsm, loTechProfDone)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001397 return
1398 }
mpagenkof1d21d12021-06-11 13:14:45 +00001399 oFsm.mutexFlowParams.Unlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001400 logger.Debugw(ctx, "UniVlanConfigFsm - VLAN config done: send dh event notification", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001401 "device-id": oFsm.deviceID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001402 // it might appear that some flows are requested also after 'flowPushed' event has been generated ...
1403 // state transition notification is checked in deviceHandler
mpagenko551a4d42020-12-08 18:09:20 +00001404 // note: 'flowPushed' event is only generated if all 'pending' rules are configured
mpagenkodff5dda2020-08-28 11:52:01 +00001405 if oFsm.pDeviceHandler != nil {
mpagenkofc4f56e2020-11-04 17:17:49 +00001406 //making use of the add->remove successor enum assumption/definition
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001407 go oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent(uint8(oFsm.requestEvent)+oFsm.requestEventOffset))
mpagenkodff5dda2020-08-28 11:52:01 +00001408 }
1409}
1410
dbainbri4d3a0dc2020-12-02 00:33:42 +00001411func (oFsm *UniVlanConfigFsm) enterConfigIncrFlow(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001412
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001413 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001414 logger.Debugw(ctx, "reconciling - skip further processing for incremental flow",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001415 log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001416 go func(a_pBaseFsm *fsm.FSM) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001417 _ = a_pBaseFsm.Event(VlanEvSkipIncFlowConfig)
1418 }(oFsm.PAdaptFsm.PFsm)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001419 return
1420 }
mpagenko15ff4a52021-03-02 10:09:20 +00001421 oFsm.mutexFlowParams.Lock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001422 logger.Debugw(ctx, "UniVlanConfigFsm - start config further incremental flow", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001423 "recent flow-number": oFsm.ConfiguredUniFlow,
mpagenkof1d21d12021-06-11 13:14:45 +00001424 "device-id": oFsm.deviceID})
mpagenko551a4d42020-12-08 18:09:20 +00001425 oFsm.TpIDWaitingFor = 0 //reset indication to avoid misinterpretation
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001426
Girish Gowdrae95687a2021-09-08 16:30:58 -07001427 if oFsm.actualUniFlowParam.VlanRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001428 // meaning transparent setup - no specific VTFD setting required
dbainbri4d3a0dc2020-12-02 00:33:42 +00001429 logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD config required", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001430 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001431 } else {
mpagenkocf48e452021-04-23 09:23:00 +00001432 //TODO!!!: it was not really intended to keep this enter* FSM method waiting on OMCI response (preventing other state transitions)
1433 // so it would be conceptually better to wait for the response in background like for the other multi-entity processing
1434 // but as the OMCI sequence must be ensured, a separate new state would be required - perhaps later
1435 // 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 +00001436 if oFsm.numVlanFilterEntries == 0 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001437 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
1438 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
Girish Gowdrae95687a2021-09-08 16:30:58 -07001439 vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.actualUniFlowParam.VlanRuleParams.TpID))
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001440 //no VTFD yet created
dbainbri4d3a0dc2020-12-02 00:33:42 +00001441 logger.Debugw(ctx, "UniVlanConfigFsm create VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001442 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenkof1d21d12021-06-11 13:14:45 +00001443 "device-id": oFsm.deviceID,
Girish Gowdrae95687a2021-09-08 16:30:58 -07001444 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": oFsm.actualUniFlowParam.VlanRuleParams.TpID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001445 // 'SetVid' below is assumed to be masked already by the caller to 12 bit
Girish Gowdrae95687a2021-09-08 16:30:58 -07001446 oFsm.vlanFilterList[0] = uint16(oFsm.actualUniFlowParam.VlanRuleParams.SetVid)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001447
mpagenko01e726e2020-10-23 09:45:29 +00001448 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001449 vtfdFilterList[0] = oFsm.vlanFilterList[0]
1450 oFsm.numVlanFilterEntries = 1
1451 meParams := me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001452 EntityID: vtfdID,
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001453 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001454 me.VlanTaggingFilterData_VlanFilterList: vtfdFilterList,
1455 me.VlanTaggingFilterData_ForwardOperation: uint8(0x10), //VID investigation
1456 me.VlanTaggingFilterData_NumberOfEntries: oFsm.numVlanFilterEntries,
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001457 },
1458 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001459 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001460 meInstance, err := oFsm.pOmciCC.SendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1461 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001462 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001463 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkof1d21d12021-06-11 13:14:45 +00001464 oFsm.mutexFlowParams.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001465 logger.Errorw(ctx, "VTFD create failed, aborting UniVlanConfig FSM!",
1466 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001467 pConfigVlanStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001468 if pConfigVlanStateAFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001469 go func(a_pAFsm *cmn.AdapterFsm) {
1470 _ = a_pAFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001471 }(pConfigVlanStateAFsm)
1472 }
1473 return
1474 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001475 //accept also nil as (error) return value for writing to LastTx
1476 // - this avoids misinterpretation of new received OMCI messages
1477 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1478 // send shall return (dual format) error code that can be used here for immediate error treatment
1479 // (relevant to all used sendXX() methods in this (and other) FSM's)
mpagenko01e726e2020-10-23 09:45:29 +00001480 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001481 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001482 } else {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001483 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
1484 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
Girish Gowdrae95687a2021-09-08 16:30:58 -07001485 vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.actualUniFlowParam.VlanRuleParams.TpID))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001486
dbainbri4d3a0dc2020-12-02 00:33:42 +00001487 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001488 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenkof1d21d12021-06-11 13:14:45 +00001489 "device-id": oFsm.deviceID,
Girish Gowdrae95687a2021-09-08 16:30:58 -07001490 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": oFsm.actualUniFlowParam.VlanRuleParams.TpID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001491 // setVid is assumed to be masked already by the caller to 12 bit
1492 oFsm.vlanFilterList[oFsm.numVlanFilterEntries] =
Girish Gowdrae95687a2021-09-08 16:30:58 -07001493 uint16(oFsm.actualUniFlowParam.VlanRuleParams.SetVid)
mpagenko01e726e2020-10-23 09:45:29 +00001494 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001495
1496 // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME
1497 // VTFD has to be created afresh with a new entity ID that has the same entity ID as the MBPCD ME for every
1498 // new vlan associated with a different TP.
Girish Gowdrae95687a2021-09-08 16:30:58 -07001499 vtfdFilterList[0] = uint16(oFsm.actualUniFlowParam.VlanRuleParams.SetVid)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001500
1501 oFsm.numVlanFilterEntries++
1502 meParams := me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001503 EntityID: vtfdID,
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001504 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001505 me.VlanTaggingFilterData_VlanFilterList: vtfdFilterList,
1506 me.VlanTaggingFilterData_ForwardOperation: uint8(0x10), //VID investigation
1507 me.VlanTaggingFilterData_NumberOfEntries: oFsm.numVlanFilterEntries,
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001508 },
1509 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001510 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001511 meInstance, err := oFsm.pOmciCC.SendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1512 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001513 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001514 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkof1d21d12021-06-11 13:14:45 +00001515 oFsm.mutexFlowParams.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001516 logger.Errorw(ctx, "UniVlanFsm create Vlan Tagging Filter ME result error",
1517 log.Fields{"device-id": oFsm.deviceID, "Error": err})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001518 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001519 return
1520 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001521 //accept also nil as (error) return value for writing to LastTx
1522 // - this avoids misinterpretation of new received OMCI messages
1523 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1524 // send shall return (dual format) error code that can be used here for immediate error treatment
1525 // (relevant to all used sendXX() methods in this (and other) FSM's)
mpagenko01e726e2020-10-23 09:45:29 +00001526 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001527 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001528 }
1529 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001530 err := oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001531 if err != nil {
mpagenkof1d21d12021-06-11 13:14:45 +00001532 oFsm.mutexFlowParams.Unlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001533 logger.Errorw(ctx, "VTFD create/set failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001534 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001535 pConfigVlanStateBaseFsm := oFsm.PAdaptFsm.PFsm
mpagenko9a304ea2020-12-16 15:54:01 +00001536 // Can't call FSM Event directly, decoupling it
mpagenkofc4f56e2020-11-04 17:17:49 +00001537 go func(a_pBaseFsm *fsm.FSM) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001538 _ = a_pBaseFsm.Event(VlanEvReset)
mpagenkofc4f56e2020-11-04 17:17:49 +00001539 }(pConfigVlanStateBaseFsm)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001540 return
1541 }
1542 }
mpagenkof1d21d12021-06-11 13:14:45 +00001543
mpagenkof1fc3862021-02-16 10:09:52 +00001544 oFsm.requestEventOffset = uint8(cDeviceEventOffsetAddWithKvStore) //0 offset for last flow-add activity
mpagenko15ff4a52021-03-02 10:09:20 +00001545 oFsm.mutexFlowParams.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001546 go func() {
mpagenko15ff4a52021-03-02 10:09:20 +00001547 oFsm.mutexFlowParams.RLock()
Girish Gowdrae95687a2021-09-08 16:30:58 -07001548 tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID
1549 configuredUniFlow := oFsm.ConfiguredUniFlow
mpagenko3ce9fa02021-07-28 13:26:54 +00001550 // ensure mutexFlowParams not locked before calling some TPProcessing activity (that might already be pending on it)
mpagenko15ff4a52021-03-02 10:09:20 +00001551 oFsm.mutexFlowParams.RUnlock()
Girish Gowdrae95687a2021-09-08 16:30:58 -07001552 errEvto := oFsm.performConfigEvtocdEntries(ctx, configuredUniFlow)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001553 //This is correct passing scenario
1554 if errEvto == nil {
1555 //TODO Possibly insert new state for multicast --> possibly another jira/later time.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001556 for _, gemPort := range oFsm.pUniTechProf.getMulticastGemPorts(ctx, oFsm.pOnuUniPort.UniID, uint8(tpID)) {
mpagenko15ff4a52021-03-02 10:09:20 +00001557 oFsm.mutexFlowParams.RLock()
Girish Gowdrae95687a2021-09-08 16:30:58 -07001558 vlanID := oFsm.actualUniFlowParam.VlanRuleParams.SetVid
dbainbri4d3a0dc2020-12-02 00:33:42 +00001559 logger.Infow(ctx, "Setting multicast MEs for additional flows", log.Fields{"deviceID": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001560 "techProfile": tpID, "gemPort": gemPort,
Girish Gowdrae95687a2021-09-08 16:30:58 -07001561 "vlanID": vlanID, "ConfiguredUniFlow": configuredUniFlow})
mpagenko15ff4a52021-03-02 10:09:20 +00001562 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001563 errCreateAllMulticastME := oFsm.performSettingMulticastME(ctx, tpID, gemPort, vlanID)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001564 if errCreateAllMulticastME != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001565 logger.Errorw(ctx, "Multicast ME create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001566 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001567 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001568 }
1569 }
ozgecanetsia82b91a62021-05-21 18:54:49 +03001570 //If this incremental flow contains a meter, then create TD for related gems.
Girish Gowdrae95687a2021-09-08 16:30:58 -07001571 if oFsm.actualUniFlowParam.Meter != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001572 for _, gemPort := range oFsm.pUniTechProf.getBidirectionalGemPortIDsForTP(ctx, oFsm.pOnuUniPort.UniID, tpID) {
Girish Gowdrae95687a2021-09-08 16:30:58 -07001573 logger.Debugw(ctx, "Creating Traffic Descriptor for gem", log.Fields{"device-id": oFsm.deviceID, "meter": oFsm.actualUniFlowParam.Meter, "gem": gemPort})
1574 errCreateTrafficDescriptor := oFsm.createTrafficDescriptor(ctx, oFsm.actualUniFlowParam.Meter, tpID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001575 oFsm.pOnuUniPort.UniID, gemPort)
ozgecanetsia82b91a62021-05-21 18:54:49 +03001576 if errCreateTrafficDescriptor != nil {
1577 logger.Errorw(ctx, "Create Traffic Descriptor create failed, aborting Ani Config FSM!",
1578 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001579 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsia82b91a62021-05-21 18:54:49 +03001580 }
1581 }
1582 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001583 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvRxConfigEvtocd)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001584 }
1585 }()
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001586}
1587
dbainbri4d3a0dc2020-12-02 00:33:42 +00001588func (oFsm *UniVlanConfigFsm) enterRemoveFlow(ctx context.Context, e *fsm.Event) {
mpagenko551a4d42020-12-08 18:09:20 +00001589 oFsm.mutexFlowParams.RLock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001590 logger.Debugw(ctx, "UniVlanConfigFsm - start removing the top remove-flow", log.Fields{
mpagenkof1d21d12021-06-11 13:14:45 +00001591 "with last cookie": oFsm.uniRemoveFlowsSlice[0].cookie,
1592 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001593
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001594 pConfigVlanStateBaseFsm := oFsm.PAdaptFsm.PFsm
1595 loAllowSpecificOmciConfig := oFsm.pDeviceHandler.IsReadyForOmciConfig()
mpagenko01e726e2020-10-23 09:45:29 +00001596 loVlanEntryClear := uint8(0)
1597 loVlanEntryRmPos := uint8(0x80) //with indication 'invalid' in bit 7
1598 //shallow copy is sufficient as no reference variables are used within struct
1599 loRuleParams := oFsm.uniRemoveFlowsSlice[0].vlanRuleParams
mpagenko551a4d42020-12-08 18:09:20 +00001600 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001601 logger.Debugw(ctx, "UniVlanConfigFsm - remove-flow parameters are", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001602 "match vid": loRuleParams.MatchVid, "match Pcp": loRuleParams.MatchPcp,
1603 "set vid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
1604 "device-id": oFsm.deviceID})
1605
1606 if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
1607 // meaning transparent setup - no specific VTFD setting required
dbainbri4d3a0dc2020-12-02 00:33:42 +00001608 logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD removal required for transparent flow", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001609 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
1610 } else {
1611 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization and 're-copy'
1612 if oFsm.numVlanFilterEntries == 1 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001613 vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(loRuleParams.TpID))
mpagenko01e726e2020-10-23 09:45:29 +00001614 //only one active VLAN entry (hopefully the SetVID we want to remove - should be, but not verified ..)
1615 // so we can just delete the VTFD entry
dbainbri4d3a0dc2020-12-02 00:33:42 +00001616 logger.Debugw(ctx, "UniVlanConfigFsm: VTFD delete (no more vlan filters)",
Mahir Gunyel6781f962021-05-16 23:30:08 -07001617 log.Fields{"current vlan list": oFsm.vlanFilterList, "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenkof1d21d12021-06-11 13:14:45 +00001618 "device-id": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001619 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": loRuleParams.TpID})
mpagenkofc4f56e2020-11-04 17:17:49 +00001620 loVlanEntryClear = 1 //full VlanFilter clear request
1621 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001622 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001623 meInstance, err := oFsm.pOmciCC.SendDeleteVtfd(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1624 oFsm.PAdaptFsm.CommChan, vtfdID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001625 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001626 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001627 logger.Errorw(ctx, "UniVlanFsm delete Vlan Tagging Filter ME result error",
1628 log.Fields{"device-id": oFsm.deviceID, "Error": err})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001629 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001630 return
1631 }
mpagenkofc4f56e2020-11-04 17:17:49 +00001632 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001633 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkofc4f56e2020-11-04 17:17:49 +00001634 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001635 logger.Debugw(ctx, "UniVlanConfigFsm delete VTFD OMCI handling skipped based on device state", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001636 "device-id": oFsm.deviceID, "device-state": oFsm.pDeviceHandler.GetDeviceReasonString()})
mpagenkofc4f56e2020-11-04 17:17:49 +00001637 }
mpagenko01e726e2020-10-23 09:45:29 +00001638 } else {
1639 //many VTFD already should exists - find and remove the one concerned by the actual remove rule
1640 // by updating the VTFD per set command with new valid list
dbainbri4d3a0dc2020-12-02 00:33:42 +00001641 logger.Debugw(ctx, "UniVlanConfigFsm: VTFD removal of requested VLAN from the list on OMCI",
mpagenko01e726e2020-10-23 09:45:29 +00001642 log.Fields{"current vlan list": oFsm.vlanFilterList,
1643 "set-vlan": loRuleParams.SetVid, "device-id": oFsm.deviceID})
1644 for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ {
1645 if loRuleParams.SetVid == uint32(oFsm.vlanFilterList[i]) {
1646 loVlanEntryRmPos = i
1647 break //abort search
1648 }
1649 }
1650 if loVlanEntryRmPos < cVtfdTableSize {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001651 vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(loRuleParams.TpID))
mpagenko01e726e2020-10-23 09:45:29 +00001652 //valid entry was found - to be eclipsed
1653 loVlanEntryClear = 2 //VlanFilter remove request for a specific entry
1654 for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ {
1655 if i < loVlanEntryRmPos {
1656 vtfdFilterList[i] = oFsm.vlanFilterList[i] //copy original
1657 } else if i < (cVtfdTableSize - 1) {
1658 vtfdFilterList[i] = oFsm.vlanFilterList[i+1] //copy successor (including 0 elements)
1659 } else {
1660 vtfdFilterList[i] = 0 //set last byte if needed
1661 }
1662 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001663 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001664 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
Mahir Gunyel6781f962021-05-16 23:30:08 -07001665 "new vlan list": vtfdFilterList, "device-id": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001666 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": loRuleParams.TpID})
mpagenko01e726e2020-10-23 09:45:29 +00001667
mpagenkofc4f56e2020-11-04 17:17:49 +00001668 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001669 // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001670 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001671 meInstance, err := oFsm.pOmciCC.SendDeleteVtfd(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1672 oFsm.PAdaptFsm.CommChan, vtfdID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001673 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001674 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001675 logger.Errorw(ctx, "UniVlanFsm delete Vlan Tagging Filter ME result error",
1676 log.Fields{"device-id": oFsm.deviceID, "Error": err})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001677 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001678 return
1679 }
mpagenkofc4f56e2020-11-04 17:17:49 +00001680 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001681 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkofc4f56e2020-11-04 17:17:49 +00001682 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001683 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD OMCI handling skipped based on device state", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001684 "device-id": oFsm.deviceID, "device-state": oFsm.pDeviceHandler.GetDeviceReasonString()})
mpagenko01e726e2020-10-23 09:45:29 +00001685 }
mpagenko01e726e2020-10-23 09:45:29 +00001686 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001687 logger.Warnw(ctx, "UniVlanConfigFsm: requested VLAN for removal not found in list - ignore and continue (no VTFD set)",
mpagenko01e726e2020-10-23 09:45:29 +00001688 log.Fields{"device-id": oFsm.deviceID})
1689 }
1690 }
1691 if loVlanEntryClear > 0 {
mpagenkofc4f56e2020-11-04 17:17:49 +00001692 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
1693 //waiting on response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001694 err := oFsm.waitforOmciResponse(ctx)
mpagenkofc4f56e2020-11-04 17:17:49 +00001695 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001696 logger.Errorw(ctx, "VTFD delete/reset failed, aborting VlanConfig FSM!",
mpagenkofc4f56e2020-11-04 17:17:49 +00001697 log.Fields{"device-id": oFsm.deviceID})
mpagenko9a304ea2020-12-16 15:54:01 +00001698 // Can't call FSM Event directly, decoupling it
mpagenkofc4f56e2020-11-04 17:17:49 +00001699 go func(a_pBaseFsm *fsm.FSM) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001700 _ = a_pBaseFsm.Event(VlanEvReset)
mpagenkofc4f56e2020-11-04 17:17:49 +00001701 }(pConfigVlanStateBaseFsm)
1702 return
1703 }
mpagenko01e726e2020-10-23 09:45:29 +00001704 }
1705
mpagenko15ff4a52021-03-02 10:09:20 +00001706 oFsm.mutexFlowParams.Lock()
mpagenko01e726e2020-10-23 09:45:29 +00001707 if loVlanEntryClear == 1 {
1708 oFsm.vlanFilterList[0] = 0 //first entry is the only that can contain the previous only-one element
1709 oFsm.numVlanFilterEntries = 0
1710 } else if loVlanEntryClear == 2 {
1711 // new VlanFilterList should be one entry smaller now - copy from last configured entry
1712 // this loop now includes the 0 element on previous last valid entry
1713 for i := uint8(0); i <= oFsm.numVlanFilterEntries; i++ {
1714 oFsm.vlanFilterList[i] = vtfdFilterList[i]
1715 }
1716 oFsm.numVlanFilterEntries--
1717 }
mpagenko15ff4a52021-03-02 10:09:20 +00001718 oFsm.mutexFlowParams.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00001719 }
1720 }
1721
mpagenkofc4f56e2020-11-04 17:17:49 +00001722 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
dbainbri4d3a0dc2020-12-02 00:33:42 +00001723 go oFsm.removeEvtocdEntries(ctx, loRuleParams)
mpagenkofc4f56e2020-11-04 17:17:49 +00001724 } else {
1725 // OMCI processing is not done, expectation is to have the ONU in some basic config state accordingly
dbainbri4d3a0dc2020-12-02 00:33:42 +00001726 logger.Debugw(ctx, "UniVlanConfigFsm remove EVTOCD OMCI handling skipped based on device state", log.Fields{
mpagenkofc4f56e2020-11-04 17:17:49 +00001727 "device-id": oFsm.deviceID})
mpagenko9a304ea2020-12-16 15:54:01 +00001728 // Can't call FSM Event directly, decoupling it
mpagenkofc4f56e2020-11-04 17:17:49 +00001729 go func(a_pBaseFsm *fsm.FSM) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001730 _ = a_pBaseFsm.Event(VlanEvRemFlowDone, loRuleParams.TpID)
mpagenkofc4f56e2020-11-04 17:17:49 +00001731 }(pConfigVlanStateBaseFsm)
1732 }
mpagenkodff5dda2020-08-28 11:52:01 +00001733}
1734
dbainbri4d3a0dc2020-12-02 00:33:42 +00001735func (oFsm *UniVlanConfigFsm) enterVlanCleanupDone(ctx context.Context, e *fsm.Event) {
Girish Gowdra26a40922021-01-29 17:14:34 -08001736 var tpID uint8
1737 // Extract the tpID
1738 if len(e.Args) > 0 {
1739 tpID = e.Args[0].(uint8)
1740 logger.Debugw(ctx, "UniVlanConfigFsm - flow removed for tp id", log.Fields{"device-id": oFsm.deviceID, "tpID": e.Args[0].(uint8)})
1741 } else {
1742 logger.Warnw(ctx, "UniVlanConfigFsm - tp id not available", log.Fields{"device-id": oFsm.deviceID})
1743 }
mpagenko01e726e2020-10-23 09:45:29 +00001744 oFsm.mutexFlowParams.Lock()
mpagenkof1fc3862021-02-16 10:09:52 +00001745 deletedCookie := oFsm.uniRemoveFlowsSlice[0].cookie
mpagenkof1d21d12021-06-11 13:14:45 +00001746
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001747 pConfigVlanStateAFsm := oFsm.PAdaptFsm
mpagenkof582d6a2021-06-18 15:58:10 +00001748 if pConfigVlanStateAFsm == nil {
1749 logger.Errorw(ctx, "invalid Fsm pointer - unresolvable - abort",
1750 log.Fields{"device-id": oFsm.deviceID})
1751 //would have to be fixed from outside somehow
1752 return
1753 }
1754
mpagenkof1d21d12021-06-11 13:14:45 +00001755 // here we need o finally remove the removed data also from uniVlanFlowParamsSlice and possibly have to
1756 // stop the suspension of a add-activity waiting for the end of removal
mpagenkof582d6a2021-06-18 15:58:10 +00001757 //call from 'configured' state of the rule
1758 if err := oFsm.removeFlowFromParamsSlice(ctx, deletedCookie, true); err != nil {
1759 //something quite inconsistent detected, perhaps just try to recover with FSM reset
1760 oFsm.mutexFlowParams.Unlock()
1761 logger.Errorw(ctx, "UniVlanConfigFsm - could not clear database - abort", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001762 go func(a_pAFsm *cmn.AdapterFsm) {
1763 _ = a_pAFsm.PFsm.Event(VlanEvReset)
mpagenkof582d6a2021-06-18 15:58:10 +00001764 }(pConfigVlanStateAFsm)
1765 return
1766 }
mpagenkof1d21d12021-06-11 13:14:45 +00001767 if oFsm.uniRemoveFlowsSlice[0].isSuspendedOnAdd {
1768 removeChannel := oFsm.uniRemoveFlowsSlice[0].removeChannel
1769 oFsm.mutexFlowParams.Unlock()
1770 removeChannel <- true
1771 oFsm.mutexFlowParams.Lock()
1772 }
1773
mpagenkof1fc3862021-02-16 10:09:52 +00001774 logger.Debugw(ctx, "UniVlanConfigFsm - removing the removal data", log.Fields{
1775 "in state": e.FSM.Current(), "device-id": oFsm.deviceID,
1776 "removed cookie": deletedCookie, "waitForDeleteCookie": oFsm.delayNewRuleCookie})
1777
Girish Gowdrae95687a2021-09-08 16:30:58 -07001778 // Store the reference to the flow response channel before this entry in the slice is deleted
1779 flowRespChan := oFsm.uniRemoveFlowsSlice[0].respChan
1780
mpagenko01e726e2020-10-23 09:45:29 +00001781 if len(oFsm.uniRemoveFlowsSlice) <= 1 {
1782 oFsm.uniRemoveFlowsSlice = nil //reset the slice
dbainbri4d3a0dc2020-12-02 00:33:42 +00001783 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - last remove-flow deleted", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001784 "device-id": oFsm.deviceID})
1785 } else {
1786 //cut off the actual flow by slicing out the first element
1787 oFsm.uniRemoveFlowsSlice = append(
1788 oFsm.uniRemoveFlowsSlice[:0],
1789 oFsm.uniRemoveFlowsSlice[1:]...)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001790 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - specific flow deleted from data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001791 "device-id": oFsm.deviceID})
1792 }
1793 oFsm.mutexFlowParams.Unlock()
1794
mpagenkof1fc3862021-02-16 10:09:52 +00001795 oFsm.requestEventOffset = uint8(cDeviceEventOffsetRemoveWithKvStore) //offset for last flow-remove activity (with kvStore request)
mpagenko01e726e2020-10-23 09:45:29 +00001796 //return to the basic config verification state
mpagenkof582d6a2021-06-18 15:58:10 +00001797 // Can't call FSM Event directly, decoupling it
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001798 go func(a_pAFsm *cmn.AdapterFsm) {
1799 _ = a_pAFsm.PFsm.Event(VlanEvFlowDataRemoved)
mpagenkof582d6a2021-06-18 15:58:10 +00001800 }(pConfigVlanStateAFsm)
Girish Gowdra26a40922021-01-29 17:14:34 -08001801
mpagenkobb47bc22021-04-20 13:29:09 +00001802 oFsm.mutexFlowParams.Lock()
Girish Gowdra26a40922021-01-29 17:14:34 -08001803 noOfFlowRem := len(oFsm.uniRemoveFlowsSlice)
mpagenkof1fc3862021-02-16 10:09:52 +00001804 if deletedCookie == oFsm.delayNewRuleCookie {
1805 // flush the channel CookieDeleted to ensure it is not lingering from some previous (aborted) activity
1806 select {
1807 case <-oFsm.chCookieDeleted:
1808 logger.Debug(ctx, "flushed CookieDeleted")
1809 default:
1810 }
1811 oFsm.chCookieDeleted <- true // let the waiting AddFlow thread continue
1812 }
mpagenkobb47bc22021-04-20 13:29:09 +00001813 // If all pending flow-removes are completed and TP ID is valid go on processing any pending TP delete
1814 if oFsm.signalOnFlowDelete && noOfFlowRem == 0 && tpID > 0 {
1815 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 -08001816 // If we are here then all flows are removed.
mpagenkobb47bc22021-04-20 13:29:09 +00001817 if len(oFsm.flowDeleteChannel) == 0 { //channel not yet in use
1818 oFsm.flowDeleteChannel <- true
1819 oFsm.signalOnFlowDelete = false
1820 }
Girish Gowdra26a40922021-01-29 17:14:34 -08001821 }
mpagenkobb47bc22021-04-20 13:29:09 +00001822 oFsm.mutexFlowParams.Unlock()
Girish Gowdrae95687a2021-09-08 16:30:58 -07001823
1824 // send response on the response channel for the removed flow.
Holger Hildebrandtc192bc42021-10-28 14:38:31 +00001825 oFsm.pushReponseOnFlowResponseChannel(ctx, flowRespChan, nil)
mpagenkodff5dda2020-08-28 11:52:01 +00001826}
1827
dbainbri4d3a0dc2020-12-02 00:33:42 +00001828func (oFsm *UniVlanConfigFsm) enterResetting(ctx context.Context, e *fsm.Event) {
1829 logger.Debugw(ctx, "UniVlanConfigFsm resetting", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001830
mpagenko0f543222021-11-03 16:24:14 +00001831 oFsm.mutexPLastTxMeInstance.Lock()
1832 oFsm.pLastTxMeInstance = nil //to avoid misinterpretation in case of some lingering frame reception processing
1833 oFsm.mutexPLastTxMeInstance.Unlock()
1834
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001835 pConfigVlanStateAFsm := oFsm.PAdaptFsm
mpagenkodff5dda2020-08-28 11:52:01 +00001836 if pConfigVlanStateAFsm != nil {
1837 // abort running message processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001838 fsmAbortMsg := cmn.Message{
1839 Type: cmn.TestMsg,
1840 Data: cmn.TestMessage{
1841 TestMessageVal: cmn.AbortMessageProcessing,
mpagenkodff5dda2020-08-28 11:52:01 +00001842 },
1843 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001844 pConfigVlanStateAFsm.CommChan <- fsmAbortMsg
mpagenkodff5dda2020-08-28 11:52:01 +00001845
mpagenko0f543222021-11-03 16:24:14 +00001846 //internal data is not explicitly removed, this is left to garbage collection after complete FSM removal
1847 // but some channels have to be cleared to avoid unintended waiting for events, that have no meaning anymore now
1848
1849 oFsm.mutexFlowParams.RLock()
1850 if oFsm.delayNewRuleCookie != 0 {
1851 // looks like the waiting AddFlow is stuck
1852 oFsm.mutexFlowParams.RUnlock()
1853 //use asynchronous channel sending to avoid stucking on non-waiting receiver
1854 select {
1855 case oFsm.chCookieDeleted <- false: // let the waiting AddFlow thread terminate
1856 default:
mpagenkodff5dda2020-08-28 11:52:01 +00001857 }
mpagenko0f543222021-11-03 16:24:14 +00001858 oFsm.mutexFlowParams.RLock()
1859 }
1860 if len(oFsm.uniRemoveFlowsSlice) > 0 {
1861 for _, removeUniFlowParams := range oFsm.uniRemoveFlowsSlice {
1862 if removeUniFlowParams.isSuspendedOnAdd {
1863 removeChannel := removeUniFlowParams.removeChannel
1864 logger.Debugw(ctx, "UniVlanConfigFsm flow clear-up - abort suspended rule-add", log.Fields{
1865 "device-id": oFsm.deviceID, "cookie": removeUniFlowParams.cookie})
1866 oFsm.mutexFlowParams.RUnlock()
1867 //use asynchronous channel sending to avoid stucking on non-waiting receiver
1868 select {
1869 case removeChannel <- false:
1870 default:
1871 }
1872 oFsm.mutexFlowParams.RLock()
1873 }
1874 // Send response on response channel if the caller is waiting on it.
1875 var err error = nil
1876 if !oFsm.isCanceled {
1877 //only if the FSM is not canceled on external request use some error indication for the respChan
1878 // so only at real internal FSM abortion some error code is sent back
1879 // on the deleteFlow with the hope the system may handle such error situation (possibly retrying)
1880 err = fmt.Errorf("internal-error")
1881 }
1882 //if the FSM was cancelled on external request the assumption is, that all processing has to be stopped
1883 // assumed in connection with some ONU down/removal indication in which case all flows can be considered as removed
1884 oFsm.pushReponseOnFlowResponseChannel(ctx, removeUniFlowParams.respChan, err)
1885 }
1886 }
1887
1888 if oFsm.pDeviceHandler != nil {
1889 if len(oFsm.uniVlanFlowParamsSlice) > 0 {
1890 if !oFsm.isCanceled {
1891 //if the FSM is not canceled on external request use "internal-error" for the respChan
1892 for _, vlanRule := range oFsm.uniVlanFlowParamsSlice {
1893 // Send response on response channel if the caller is waiting on it with according error indication.
1894 oFsm.pushReponseOnFlowResponseChannel(ctx, vlanRule.RespChan, fmt.Errorf("internal-error"))
1895 }
1896 //permanently remove possibly stored persistent data
1897 var emptySlice = make([]cmn.UniVlanFlowParams, 0)
1898 _ = oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID, &emptySlice, true) //ignore errors
1899 } else {
1900 // reset (cancel) of all Fsm is always accompanied by global persistency data removal
1901 // no need to remove specific data in this case here
1902 // TODO: cancelation may also abort a running flowAdd activity in which case it would be better
1903 // to also resopnd on the respChan with some error ("config canceled"), but that is a bit hard to decide here
1904 // so just left open by now
1905 logger.Debugw(ctx, "UniVlanConfigFsm persistency data not cleared", log.Fields{"device-id": oFsm.deviceID})
1906 }
1907 }
1908 oFsm.mutexFlowParams.RUnlock()
1909
1910 //try to let the FSM proceed to 'disabled'
1911 // Can't call FSM Event directly, decoupling it
1912 go func(a_pAFsm *cmn.AdapterFsm) {
1913 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
1914 _ = a_pAFsm.PFsm.Event(VlanEvRestart)
1915 }
1916 }(pConfigVlanStateAFsm)
1917 return
1918 }
1919 oFsm.mutexFlowParams.RUnlock()
1920 logger.Warnw(ctx, "UniVlanConfigFsm - device handler already vanished",
1921 log.Fields{"device-id": oFsm.deviceID})
1922 return
mpagenkodff5dda2020-08-28 11:52:01 +00001923 }
mpagenko0f543222021-11-03 16:24:14 +00001924 logger.Warnw(ctx, "UniVlanConfigFsm - FSM pointer already vanished",
1925 log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001926}
1927
dbainbri4d3a0dc2020-12-02 00:33:42 +00001928func (oFsm *UniVlanConfigFsm) enterDisabled(ctx context.Context, e *fsm.Event) {
1929 logger.Debugw(ctx, "UniVlanConfigFsm enters disabled state", log.Fields{"device-id": oFsm.deviceID})
mpagenkof1d21d12021-06-11 13:14:45 +00001930
mpagenkodff5dda2020-08-28 11:52:01 +00001931 if oFsm.pDeviceHandler != nil {
mpagenko2418ab02020-11-12 12:58:06 +00001932 //request removal of 'reference' in the Handler (completely clear the FSM and its data)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001933 go oFsm.pDeviceHandler.RemoveVlanFilterFsm(ctx, oFsm.pOnuUniPort)
mpagenkof1d21d12021-06-11 13:14:45 +00001934 return
mpagenkodff5dda2020-08-28 11:52:01 +00001935 }
mpagenko0f543222021-11-03 16:24:14 +00001936 logger.Warnw(ctx, "UniVlanConfigFsm - device handler already vanished",
1937 log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001938}
1939
dbainbri4d3a0dc2020-12-02 00:33:42 +00001940func (oFsm *UniVlanConfigFsm) processOmciVlanMessages(ctx context.Context) { //ctx context.Context?
1941 logger.Debugw(ctx, "Start UniVlanConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001942loop:
1943 for {
mpagenkodff5dda2020-08-28 11:52:01 +00001944 // case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +00001945 // logger.Info(ctx,"MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001946 // break loop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001947 message, ok := <-oFsm.PAdaptFsm.CommChan
Himani Chawla4d908332020-08-31 12:30:20 +05301948 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001949 logger.Info(ctx, "UniVlanConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301950 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001951 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
Himani Chawla4d908332020-08-31 12:30:20 +05301952 break loop
1953 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001954 logger.Debugw(ctx, "UniVlanConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301955
1956 switch message.Type {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001957 case cmn.TestMsg:
1958 msg, _ := message.Data.(cmn.TestMessage)
1959 if msg.TestMessageVal == cmn.AbortMessageProcessing {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001960 logger.Infow(ctx, "UniVlanConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001961 break loop
1962 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001963 logger.Warnw(ctx, "UniVlanConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001964 case cmn.OMCI:
1965 msg, _ := message.Data.(cmn.OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001966 oFsm.handleOmciVlanConfigMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301967 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +00001968 logger.Warn(ctx, "UniVlanConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID,
Himani Chawla4d908332020-08-31 12:30:20 +05301969 "message.Type": message.Type})
mpagenkodff5dda2020-08-28 11:52:01 +00001970 }
1971 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001972 logger.Infow(ctx, "End UniVlanConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001973}
1974
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001975func (oFsm *UniVlanConfigFsm) handleOmciVlanConfigMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001976 logger.Debugw(ctx, "Rx OMCI UniVlanConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00001977 "msgType": msg.OmciMsg.MessageType})
1978
1979 switch msg.OmciMsg.MessageType {
1980 case omci.CreateResponseType:
mpagenko01e726e2020-10-23 09:45:29 +00001981 { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-(
dbainbri4d3a0dc2020-12-02 00:33:42 +00001982 if err := oFsm.handleOmciCreateResponseMessage(ctx, msg.OmciPacket); err != nil {
Holger Hildebrandtabfef032022-02-25 12:40:20 +00001983 logger.Warnw(ctx, "CreateResponse handling aborted",
1984 log.Fields{"device-id": oFsm.deviceID, "err": err})
mpagenkodff5dda2020-08-28 11:52:01 +00001985 return
1986 }
mpagenkodff5dda2020-08-28 11:52:01 +00001987 } //CreateResponseType
1988 case omci.SetResponseType:
mpagenko01e726e2020-10-23 09:45:29 +00001989 { //leave that here as direct code as most often used
mpagenkodff5dda2020-08-28 11:52:01 +00001990 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
1991 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001992 logger.Errorw(ctx, "Omci Msg layer could not be detected for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001993 log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001994 return
1995 }
1996 msgObj, msgOk := msgLayer.(*omci.SetResponse)
1997 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001998 logger.Errorw(ctx, "Omci Msg layer could not be assigned for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001999 log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00002000 return
2001 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00002002 logger.Debugw(ctx, "UniVlanConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenkodff5dda2020-08-28 11:52:01 +00002003 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002004 logger.Errorw(ctx, "UniVlanConfigFsm Omci SetResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00002005 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
mpagenkodff5dda2020-08-28 11:52:01 +00002006 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
2007 return
2008 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002009 oFsm.mutexPLastTxMeInstance.RLock()
2010 if oFsm.pLastTxMeInstance != nil {
2011 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
2012 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
2013 switch oFsm.pLastTxMeInstance.GetName() {
ozgecanetsia82b91a62021-05-21 18:54:49 +03002014 case "VlanTaggingFilterData", "ExtendedVlanTaggingOperationConfigurationData", "MulticastOperationsProfile", "GemPortNetworkCtp":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002015 { // let the MultiEntity config proceed by stopping the wait function
2016 oFsm.mutexPLastTxMeInstance.RUnlock()
2017 oFsm.omciMIdsResponseReceived <- true
2018 return
2019 }
2020 default:
2021 {
2022 logger.Warnw(ctx, "Unsupported ME name received!",
2023 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
2024 }
mpagenkodff5dda2020-08-28 11:52:01 +00002025 }
2026 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002027 } else {
2028 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00002029 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002030 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002031 } //SetResponseType
mpagenko01e726e2020-10-23 09:45:29 +00002032 case omci.DeleteResponseType:
2033 { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-(
dbainbri4d3a0dc2020-12-02 00:33:42 +00002034 if err := oFsm.handleOmciDeleteResponseMessage(ctx, msg.OmciPacket); err != nil {
Holger Hildebrandtabfef032022-02-25 12:40:20 +00002035 logger.Warnw(ctx, "DeleteResponse handling aborted",
2036 log.Fields{"device-id": oFsm.deviceID, "err": err})
mpagenko01e726e2020-10-23 09:45:29 +00002037 return
2038 }
2039 } //DeleteResponseType
mpagenkodff5dda2020-08-28 11:52:01 +00002040 default:
2041 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002042 logger.Errorw(ctx, "Rx OMCI unhandled MsgType",
mpagenko01e726e2020-10-23 09:45:29 +00002043 log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00002044 return
2045 }
2046 }
2047}
2048
dbainbri4d3a0dc2020-12-02 00:33:42 +00002049func (oFsm *UniVlanConfigFsm) handleOmciCreateResponseMessage(ctx context.Context, apOmciPacket *gp.Packet) error {
mpagenko01e726e2020-10-23 09:45:29 +00002050 msgLayer := (*apOmciPacket).Layer(omci.LayerTypeCreateResponse)
2051 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002052 logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00002053 log.Fields{"device-id": oFsm.deviceID})
2054 return fmt.Errorf("omci msg layer could not be detected for CreateResponse for device-id %x",
2055 oFsm.deviceID)
2056 }
2057 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
2058 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002059 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00002060 log.Fields{"device-id": oFsm.deviceID})
2061 return fmt.Errorf("omci msg layer could not be assigned for CreateResponse for device-id %x",
2062 oFsm.deviceID)
2063 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00002064 logger.Debugw(ctx, "UniVlanConfigFsm CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002065 if msgObj.Result != me.Success && msgObj.Result != me.InstanceExists {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002066 logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": oFsm.deviceID,
mpagenko01e726e2020-10-23 09:45:29 +00002067 "Error": msgObj.Result})
2068 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
2069 return fmt.Errorf("omci CreateResponse Error for device-id %x",
2070 oFsm.deviceID)
2071 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002072 oFsm.mutexPLastTxMeInstance.RLock()
2073 if oFsm.pLastTxMeInstance != nil {
2074 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
2075 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
2076 // to satisfy StaticCodeAnalysis I had to move the small processing into a separate method :-(
2077 switch oFsm.pLastTxMeInstance.GetName() {
2078 case "VlanTaggingFilterData", "MulticastOperationsProfile",
2079 "MulticastSubscriberConfigInfo", "MacBridgePortConfigurationData",
ozgecanetsia82b91a62021-05-21 18:54:49 +03002080 "ExtendedVlanTaggingOperationConfigurationData", "TrafficDescriptor":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002081 {
2082 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002083 if oFsm.PAdaptFsm.PFsm.Current() == VlanStConfigVtfd {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002084 // Only if CreateResponse is received from first flow entry - let the FSM proceed ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002085 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvRxConfigVtfd)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002086 } else { // let the MultiEntity config proceed by stopping the wait function
2087 oFsm.omciMIdsResponseReceived <- true
2088 }
2089 return nil
2090 }
2091 default:
2092 {
2093 logger.Warnw(ctx, "Unsupported ME name received!",
2094 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00002095 }
2096 }
2097 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002098 } else {
2099 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00002100 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002101 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00002102 return nil
2103}
2104
dbainbri4d3a0dc2020-12-02 00:33:42 +00002105func (oFsm *UniVlanConfigFsm) handleOmciDeleteResponseMessage(ctx context.Context, apOmciPacket *gp.Packet) error {
mpagenko01e726e2020-10-23 09:45:29 +00002106 msgLayer := (*apOmciPacket).Layer(omci.LayerTypeDeleteResponse)
2107 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002108 logger.Errorw(ctx, "UniVlanConfigFsm - Omci Msg layer could not be detected for DeleteResponse",
mpagenko01e726e2020-10-23 09:45:29 +00002109 log.Fields{"device-id": oFsm.deviceID})
2110 return fmt.Errorf("omci msg layer could not be detected for DeleteResponse for device-id %x",
2111 oFsm.deviceID)
2112 }
2113 msgObj, msgOk := msgLayer.(*omci.DeleteResponse)
2114 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002115 logger.Errorw(ctx, "UniVlanConfigFsm - Omci Msg layer could not be assigned for DeleteResponse",
mpagenko01e726e2020-10-23 09:45:29 +00002116 log.Fields{"device-id": oFsm.deviceID})
2117 return fmt.Errorf("omci msg layer could not be assigned for DeleteResponse for device-id %x",
2118 oFsm.deviceID)
2119 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00002120 logger.Debugw(ctx, "UniVlanConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenko01e726e2020-10-23 09:45:29 +00002121 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002122 logger.Errorw(ctx, "UniVlanConfigFsm - Omci DeleteResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00002123 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
2124 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
2125 return fmt.Errorf("omci DeleteResponse Error for device-id %x",
2126 oFsm.deviceID)
2127 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002128 oFsm.mutexPLastTxMeInstance.RLock()
2129 if oFsm.pLastTxMeInstance != nil {
2130 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
2131 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
2132 switch oFsm.pLastTxMeInstance.GetName() {
ozgecanetsia82b91a62021-05-21 18:54:49 +03002133 case "VlanTaggingFilterData", "ExtendedVlanTaggingOperationConfigurationData", "TrafficDescriptor":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002134 { // let the MultiEntity config proceed by stopping the wait function
2135 oFsm.mutexPLastTxMeInstance.RUnlock()
2136 oFsm.omciMIdsResponseReceived <- true
2137 return nil
2138 }
2139 default:
2140 {
2141 logger.Warnw(ctx, "Unsupported ME name received!",
2142 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
2143 }
mpagenko01e726e2020-10-23 09:45:29 +00002144 }
2145 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002146 } else {
2147 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00002148 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002149 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00002150 return nil
2151}
2152
dbainbri4d3a0dc2020-12-02 00:33:42 +00002153func (oFsm *UniVlanConfigFsm) performConfigEvtocdEntries(ctx context.Context, aFlowEntryNo uint8) error {
mpagenkof1d21d12021-06-11 13:14:45 +00002154 oFsm.mutexFlowParams.RLock()
2155 evtocdID := oFsm.evtocdID
2156 oFsm.mutexFlowParams.RUnlock()
2157
Holger Hildebrandt394c5522020-09-11 11:23:01 +00002158 if aFlowEntryNo == 0 {
2159 // EthType set only at first flow element
mpagenkodff5dda2020-08-28 11:52:01 +00002160 // EVTOCD ME is expected to exist at this point already from MIB-Download (with AssociationType/Pointer)
2161 // we need to extend the configuration by EthType definition and, to be sure, downstream 'inverse' mode
dbainbri4d3a0dc2020-12-02 00:33:42 +00002162 logger.Debugw(ctx, "UniVlanConfigFsm Tx Create::EVTOCD", log.Fields{
mpagenkof1d21d12021-06-11 13:14:45 +00002163 "EntitytId": strconv.FormatInt(int64(evtocdID), 16),
mpagenkodff5dda2020-08-28 11:52:01 +00002164 "i/oEthType": strconv.FormatInt(int64(cDefaultTpid), 16),
mpagenko01e726e2020-10-23 09:45:29 +00002165 "device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002166 associationType := 2 // default to UniPPTP
2167 if oFsm.pOnuUniPort.PortType == cmn.UniVEIP {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002168 associationType = 10
2169 }
2170 // Create the EVTOCD ME
mpagenkodff5dda2020-08-28 11:52:01 +00002171 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002172 EntityID: evtocdID,
mpagenkodff5dda2020-08-28 11:52:01 +00002173 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00002174 me.ExtendedVlanTaggingOperationConfigurationData_AssociationType: uint8(associationType),
2175 me.ExtendedVlanTaggingOperationConfigurationData_AssociatedMePointer: oFsm.pOnuUniPort.EntityID,
mpagenkodff5dda2020-08-28 11:52:01 +00002176 },
2177 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002178 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002179 meInstance, err := oFsm.pOmciCC.SendCreateEvtocdVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(),
2180 true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002181 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002182 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002183 logger.Errorw(ctx, "CreateEvtocdVar create failed, aborting UniVlanConfigFsm!",
2184 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002185 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002186 return fmt.Errorf("evtocd instance create failed %s, error %s", oFsm.deviceID, err)
2187 }
mpagenkodff5dda2020-08-28 11:52:01 +00002188 //accept also nil as (error) return value for writing to LastTx
2189 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00002190 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002191 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002192
2193 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002194 err = oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00002195 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002196 logger.Errorw(ctx, "Evtocd create failed, aborting VlanConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002197 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002198 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002199 return fmt.Errorf("evtocd create failed %s, error %s", oFsm.deviceID, err)
2200 }
2201
2202 // Set the EVTOCD ME default params
2203 meParams = me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002204 EntityID: evtocdID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002205 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00002206 me.ExtendedVlanTaggingOperationConfigurationData_InputTpid: uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base
2207 me.ExtendedVlanTaggingOperationConfigurationData_OutputTpid: uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base
2208 me.ExtendedVlanTaggingOperationConfigurationData_DownstreamMode: uint8(cDefaultDownstreamMode),
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002209 },
2210 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002211 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002212 meInstance, err = oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2213 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2214 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002215 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002216 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002217 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2218 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002219 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002220 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
2221 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002222 //accept also nil as (error) return value for writing to LastTx
2223 // - this avoids misinterpretation of new received OMCI messages
2224 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002225 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002226
2227 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00002228 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002229 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002230 logger.Errorw(ctx, "Evtocd set TPID failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002231 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002232 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002233 return fmt.Errorf("evtocd set TPID failed %s, error %s", oFsm.deviceID, err)
mpagenkodff5dda2020-08-28 11:52:01 +00002234 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00002235 } //first flow element
mpagenkodff5dda2020-08-28 11:52:01 +00002236
mpagenko551a4d42020-12-08 18:09:20 +00002237 oFsm.mutexFlowParams.RLock()
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05302238 if oFsm.actualUniFlowParam.VlanRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) &&
2239 uint32(oFsm.actualUniFlowParam.VlanRuleParams.InnerCvlan) == uint32(of.OfpVlanId_OFPVID_NONE) {
mpagenkodff5dda2020-08-28 11:52:01 +00002240 //transparent transmission required
mpagenko551a4d42020-12-08 18:09:20 +00002241 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00002242 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD single tagged transparent rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00002243 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00002244 sliceEvtocdRule := make([]uint8, 16)
2245 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2246 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2247 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2248 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2249 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2250
2251 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2252 cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule
2253 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
2254 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2255 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2256
2257 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
2258 0<<cTreatTTROffset| // Do not pop any tags
2259 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
2260 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2261 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
2262
2263 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
2264 cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag
2265 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2266 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
2267
2268 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002269 EntityID: evtocdID,
mpagenkodff5dda2020-08-28 11:52:01 +00002270 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00002271 me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule,
mpagenkodff5dda2020-08-28 11:52:01 +00002272 },
2273 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002274 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002275 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2276 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2277 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002278 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002279 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002280 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2281 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002282 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002283 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
2284 }
mpagenkodff5dda2020-08-28 11:52:01 +00002285 //accept also nil as (error) return value for writing to LastTx
2286 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00002287 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002288 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002289
2290 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002291 err = oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00002292 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002293 logger.Errorw(ctx, "Evtocd set transparent singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002294 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002295 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002296 return fmt.Errorf("evtocd set transparent singletagged rule failed %s, error %s", oFsm.deviceID, err)
2297
mpagenkodff5dda2020-08-28 11:52:01 +00002298 }
2299 } else {
2300 // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario
2301 if oFsm.acceptIncrementalEvtoOption {
Girish Gowdrae95687a2021-09-08 16:30:58 -07002302 matchPcp := oFsm.actualUniFlowParam.VlanRuleParams.MatchPcp
2303 matchVid := oFsm.actualUniFlowParam.VlanRuleParams.MatchVid
2304 setPcp := oFsm.actualUniFlowParam.VlanRuleParams.SetPcp
2305 setVid := oFsm.actualUniFlowParam.VlanRuleParams.SetVid
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05302306 innerCvlan := oFsm.actualUniFlowParam.VlanRuleParams.InnerCvlan
mpagenkodff5dda2020-08-28 11:52:01 +00002307 sliceEvtocdRule := make([]uint8, 16)
mpagenkodff5dda2020-08-28 11:52:01 +00002308
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05302309 if uint32(oFsm.actualUniFlowParam.VlanRuleParams.InnerCvlan) == uint32(of.OfpVlanId_OFPVID_NONE) {
2310 // this defines VID translation scenario: singletagged->singletagged (if not transparent)
2311 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD single tagged translation rule", log.Fields{
2312 "match-pcp": matchPcp, "match-vid": matchVid, "set-pcp": setPcp, "set-vid:": setVid, "device-id": oFsm.deviceID})
2313 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2314 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2315 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2316 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2317 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
mpagenkodff5dda2020-08-28 11:52:01 +00002318
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05302319 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2320 oFsm.actualUniFlowParam.VlanRuleParams.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN
2321 oFsm.actualUniFlowParam.VlanRuleParams.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID
2322 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2323 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
mpagenkodff5dda2020-08-28 11:52:01 +00002324
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05302325 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
2326 oFsm.actualUniFlowParam.VlanRuleParams.TagsToRemove<<cTreatTTROffset| // either 1 or 0
2327 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
2328 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2329 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
2330
2331 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
2332 oFsm.actualUniFlowParam.VlanRuleParams.SetPcp<<cTreatPrioOffset| // as configured in flow
2333 oFsm.actualUniFlowParam.VlanRuleParams.SetVid<<cTreatVidOffset| //as configured in flow
2334 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
2335
2336 } else {
2337 //Double tagged case, if innerCvlan is 4096 then transparent, else match on the innerCvlan
2338 //As of now only a match and no action can be done on the inner tag .
2339 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD double tagged translation rule", log.Fields{
2340 "match-pcp": matchPcp, "match-vid": matchVid, "set-pcp": setPcp, "set-vid:": setVid, "inner-cvlan:": innerCvlan, "device-id": oFsm.deviceID})
2341 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2342 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2343 oFsm.actualUniFlowParam.VlanRuleParams.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or filter priority
2344 oFsm.actualUniFlowParam.VlanRuleParams.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID
2345 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2346
2347 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2348 cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule
2349 uint32(innerCvlan)<<cFilterVidOffset| // transparent of innercvlan is 4096 or filter with innercvlan
2350 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2351 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2352
2353 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
2354 oFsm.actualUniFlowParam.VlanRuleParams.TagsToRemove<<cTreatTTROffset| // either 1 or 0
2355 cCopyPrioFromOuter<<cTreatPrioOffset| // add tag and copy prio from outer from the received frame
2356 setVid<<cTreatVidOffset| // Set VID
2357 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
2358
2359 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
2360 cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag
2361 uint32(innerCvlan)<<cTreatVidOffset| //as configured in flow
2362 cDontCareTpid<<cTreatTpidOffset) // Set TPID = 0x8100
2363 }
mpagenko551a4d42020-12-08 18:09:20 +00002364 oFsm.mutexFlowParams.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002365 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002366 EntityID: evtocdID,
mpagenkodff5dda2020-08-28 11:52:01 +00002367 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00002368 me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule,
mpagenkodff5dda2020-08-28 11:52:01 +00002369 },
2370 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002371 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002372 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2373 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2374 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002375 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002376 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002377 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2378 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002379 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002380 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
2381 }
mpagenkodff5dda2020-08-28 11:52:01 +00002382 //accept also nil as (error) return value for writing to LastTx
2383 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00002384 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002385 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002386
2387 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002388 err = oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00002389 if err != nil {
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05302390 logger.Errorw(ctx, "Evtocd set rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002391 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002392 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05302393 return fmt.Errorf("evtocd set rule failed %s, error %s", oFsm.deviceID, err)
mpagenkodff5dda2020-08-28 11:52:01 +00002394 }
2395 } else {
2396 //not transparent and not acceptIncrementalEvtoOption untagged/priotagged->singletagged
2397 { // just for local var's
2398 // this defines stacking scenario: untagged->singletagged
dbainbri4d3a0dc2020-12-02 00:33:42 +00002399 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD untagged->singletagged rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00002400 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00002401 sliceEvtocdRule := make([]uint8, 16)
2402 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2403 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2404 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2405 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2406 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2407
2408 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2409 cPrioIgnoreTag<<cFilterPrioOffset| // Not an inner-tag rule
2410 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
2411 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2412 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2413
2414 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
2415 0<<cTreatTTROffset| // Do not pop any tags
2416 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
2417 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2418 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
2419
2420 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
2421 0<<cTreatPrioOffset| // vlan prio set to 0
2422 // (as done in Py code, maybe better option would be setPcp here, which still could be 0?)
Girish Gowdrae95687a2021-09-08 16:30:58 -07002423 oFsm.actualUniFlowParam.VlanRuleParams.SetVid<<cTreatVidOffset| // Outer VID don't care
mpagenkodff5dda2020-08-28 11:52:01 +00002424 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
2425
mpagenko551a4d42020-12-08 18:09:20 +00002426 oFsm.mutexFlowParams.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002427 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002428 EntityID: evtocdID,
mpagenkodff5dda2020-08-28 11:52:01 +00002429 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00002430 me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule,
mpagenkodff5dda2020-08-28 11:52:01 +00002431 },
2432 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002433 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002434 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2435 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2436 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002437 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002438 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002439 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2440 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002441 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002442 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
2443 }
mpagenkodff5dda2020-08-28 11:52:01 +00002444 //accept also nil as (error) return value for writing to LastTx
2445 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00002446 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002447 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002448
2449 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002450 err = oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00002451 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002452 logger.Errorw(ctx, "Evtocd set untagged->singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002453 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002454 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002455 return fmt.Errorf("evtocd set untagged->singletagged rule failed %s, error %s", oFsm.deviceID, err)
2456
mpagenkodff5dda2020-08-28 11:52:01 +00002457 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00002458 } // just for local var's
mpagenkodff5dda2020-08-28 11:52:01 +00002459 { // just for local var's
2460 // this defines 'stacking' scenario: priotagged->singletagged
dbainbri4d3a0dc2020-12-02 00:33:42 +00002461 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD priotagged->singletagged rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00002462 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00002463 sliceEvtocdRule := make([]uint8, 16)
2464 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2465 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2466 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2467 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2468 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2469
2470 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2471 cPrioDoNotFilter<<cFilterPrioOffset| // Do not Filter on innerprio
2472 0<<cFilterVidOffset| // filter on inner vid 0 (prioTagged)
2473 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2474 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2475
2476 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
2477 1<<cTreatTTROffset| // pop the prio-tag
2478 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
2479 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2480 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
2481
mpagenko551a4d42020-12-08 18:09:20 +00002482 oFsm.mutexFlowParams.RLock()
mpagenkodff5dda2020-08-28 11:52:01 +00002483 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
2484 cCopyPrioFromInner<<cTreatPrioOffset| // vlan copy from PrioTag
2485 // (as done in Py code, maybe better option would be setPcp here, which still could be PrioCopy?)
Girish Gowdrae95687a2021-09-08 16:30:58 -07002486 oFsm.actualUniFlowParam.VlanRuleParams.SetVid<<cTreatVidOffset| // Outer VID as configured
mpagenkodff5dda2020-08-28 11:52:01 +00002487 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
mpagenko551a4d42020-12-08 18:09:20 +00002488 oFsm.mutexFlowParams.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002489
2490 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002491 EntityID: evtocdID,
mpagenkodff5dda2020-08-28 11:52:01 +00002492 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00002493 me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule,
mpagenkodff5dda2020-08-28 11:52:01 +00002494 },
2495 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002496 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002497 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2498 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2499 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002500 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002501 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002502 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2503 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002504 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002505 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
2506 }
mpagenkodff5dda2020-08-28 11:52:01 +00002507 //accept also nil as (error) return value for writing to LastTx
2508 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00002509 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002510 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002511
2512 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002513 err = oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00002514 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002515 logger.Errorw(ctx, "Evtocd set priotagged->singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002516 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002517 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002518 return fmt.Errorf("evtocd set priotagged->singletagged rule failed %s, error %s", oFsm.deviceID, err)
2519
mpagenkodff5dda2020-08-28 11:52:01 +00002520 }
2521 } //just for local var's
2522 }
2523 }
2524
mpagenkofc4f56e2020-11-04 17:17:49 +00002525 // if Config has been done for all EVTOCD entries let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00002526 logger.Debugw(ctx, "EVTOCD set loop finished", log.Fields{"device-id": oFsm.deviceID})
mpagenkof1d21d12021-06-11 13:14:45 +00002527 oFsm.mutexFlowParams.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002528 oFsm.ConfiguredUniFlow++ // one (more) flow configured
mpagenkof1d21d12021-06-11 13:14:45 +00002529 oFsm.mutexFlowParams.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002530 return nil
mpagenkodff5dda2020-08-28 11:52:01 +00002531}
2532
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002533func (oFsm *UniVlanConfigFsm) removeEvtocdEntries(ctx context.Context, aRuleParams cmn.UniVlanRuleParams) {
mpagenkof1d21d12021-06-11 13:14:45 +00002534 oFsm.mutexFlowParams.RLock()
2535 evtocdID := oFsm.evtocdID
2536 oFsm.mutexFlowParams.RUnlock()
2537
mpagenko01e726e2020-10-23 09:45:29 +00002538 // configured Input/Output TPID is not modified again - no influence if no filter is applied
2539 if aRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
2540 //transparent transmission was set
2541 //perhaps the config is not needed for removal,
2542 // but the specific InnerTpid setting is removed in favor of the real default forwarding rule
dbainbri4d3a0dc2020-12-02 00:33:42 +00002543 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD reset to default single tagged rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00002544 "device-id": oFsm.deviceID})
2545 sliceEvtocdRule := make([]uint8, 16)
2546 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2547 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2548 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2549 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2550 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2551
2552 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2553 cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule
2554 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
2555 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2556 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2557
2558 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
2559 0<<cTreatTTROffset| // Do not pop any tags
2560 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
2561 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2562 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
2563
2564 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
2565 cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag
2566 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2567 cDontCareTpid<<cTreatTpidOffset) // copy TPID and DEI
2568
2569 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002570 EntityID: evtocdID,
mpagenko01e726e2020-10-23 09:45:29 +00002571 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00002572 me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule,
mpagenko01e726e2020-10-23 09:45:29 +00002573 },
2574 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002575 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002576 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2577 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2578 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002579 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002580 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002581 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2582 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002583 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002584 return
2585 }
mpagenko01e726e2020-10-23 09:45:29 +00002586 //accept also nil as (error) return value for writing to LastTx
2587 // - this avoids misinterpretation of new received OMCI messages
2588 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002589 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00002590
2591 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002592 err = oFsm.waitforOmciResponse(ctx)
mpagenko01e726e2020-10-23 09:45:29 +00002593 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002594 logger.Errorw(ctx, "Evtocd reset singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002595 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002596 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
mpagenko01e726e2020-10-23 09:45:29 +00002597 return
2598 }
2599 } else {
2600 // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario
mpagenkof1d21d12021-06-11 13:14:45 +00002601 oFsm.mutexFlowParams.RLock()
mpagenko01e726e2020-10-23 09:45:29 +00002602 if oFsm.acceptIncrementalEvtoOption {
mpagenkof1d21d12021-06-11 13:14:45 +00002603 oFsm.mutexFlowParams.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00002604 sliceEvtocdRule := make([]uint8, 16)
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05302605 if uint32(aRuleParams.InnerCvlan) == uint32(of.OfpVlanId_OFPVID_NONE) {
mpagenko01e726e2020-10-23 09:45:29 +00002606
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05302607 // this defines VID translation scenario: singletagged->singletagged (if not transparent)
2608 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD clear single tagged translation rule", log.Fields{
2609 "device-id": oFsm.deviceID, "match-vlan": aRuleParams.MatchVid})
2610 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2611 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2612 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2613 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2614 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
mpagenko01e726e2020-10-23 09:45:29 +00002615
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05302616 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2617 aRuleParams.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN
2618 aRuleParams.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID
2619 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2620 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
mpagenko01e726e2020-10-23 09:45:29 +00002621
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05302622 // delete indication for the indicated Filter
2623 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], 0xFFFFFFFF)
2624 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], 0xFFFFFFFF)
2625
2626 } else {
2627 // this defines VID translation scenario: dobletagged-doubletagged (if not transparent)
2628 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD clear double tagged rule", log.Fields{
2629 "device-id": oFsm.deviceID, "match-vlan": aRuleParams.MatchVid, "innerCvlan": aRuleParams.InnerCvlan})
2630 sliceEvtocdRule := make([]uint8, 16)
2631 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2632 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2633 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2634 aRuleParams.MatchVid<<cFilterVidOffset| // Do not filter on outer vid
2635 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2636
2637 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2638 cPrioIgnoreTag<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN
2639 cDoNotFilterVid<<cFilterVidOffset| // DNFonVid or ignore tag
2640 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2641 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2642
2643 // delete indication for the indicated Filter
2644 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], 0xFFFFFFFF)
2645 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], 0xFFFFFFFF)
2646 }
mpagenko01e726e2020-10-23 09:45:29 +00002647 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002648 EntityID: evtocdID,
mpagenko01e726e2020-10-23 09:45:29 +00002649 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00002650 me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule,
mpagenko01e726e2020-10-23 09:45:29 +00002651 },
2652 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002653 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002654 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2655 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2656 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002657 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002658 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002659 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2660 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002661 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002662 return
2663 }
mpagenko01e726e2020-10-23 09:45:29 +00002664 //accept also nil as (error) return value for writing to LastTx
2665 // - this avoids misinterpretation of new received OMCI messages
2666 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002667 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00002668
2669 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002670 err = oFsm.waitforOmciResponse(ctx)
mpagenko01e726e2020-10-23 09:45:29 +00002671 if err != nil {
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05302672 logger.Errorw(ctx, "Evtocd clear rule failed, aborting VlanConfig FSM!",
2673 log.Fields{"device-id": oFsm.deviceID,
2674 "match-vlan": aRuleParams.MatchVid,
2675 "InnerCvlan": aRuleParams.InnerCvlan})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002676 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
mpagenko01e726e2020-10-23 09:45:29 +00002677 return
2678 }
2679 } else {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002680 // VOL-3685
2681 // NOTE: With ALPHA ONUs it was seen that just resetting a particular entry in the EVTOCD table
2682 // and re-configuring a new entry would not work. The old entry is removed and new entry is created
2683 // indeed, but the traffic landing upstream would carry old vlan sometimes.
2684 // This is only a WORKAROUND which basically deletes the entire EVTOCD ME and re-creates it again
2685 // later when the flow is being re-installed.
2686 // Of course this is applicable to case only where single service (or single tcont) is in use and
2687 // there is only one service vlan (oFsm.acceptIncrementalEvtoOption is false in this case).
2688 // Interstingly this problem has not been observed in multi-tcont (or multi-service) scenario (in
2689 // which case the oFsm.acceptIncrementalEvtoOption is set to true).
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002690 if oFsm.ConfiguredUniFlow == 1 && !oFsm.acceptIncrementalEvtoOption {
mpagenkof1d21d12021-06-11 13:14:45 +00002691 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00002692 logger.Debugw(ctx, "UniVlanConfigFsm Tx Remove::EVTOCD", log.Fields{"device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002693 // When there are no more EVTOCD vlan configurations on the ONU and acceptIncrementalEvtoOption
2694 // is not enabled, delete the EVTOCD ME.
mpagenko01e726e2020-10-23 09:45:29 +00002695 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002696 EntityID: evtocdID,
mpagenko01e726e2020-10-23 09:45:29 +00002697 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002698 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002699 meInstance, err := oFsm.pOmciCC.SendDeleteEvtocd(log.WithSpanFromContext(context.TODO(), ctx),
2700 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2701 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002702 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002703 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002704 logger.Errorw(ctx, "DeleteEvtocdVar delete failed, aborting UniVlanConfigFsm!",
2705 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002706 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002707 return
2708 }
mpagenko01e726e2020-10-23 09:45:29 +00002709 //accept also nil as (error) return value for writing to LastTx
2710 // - this avoids misinterpretation of new received OMCI messages
2711 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002712 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00002713
2714 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002715 err = oFsm.waitforOmciResponse(ctx)
mpagenko01e726e2020-10-23 09:45:29 +00002716 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002717 logger.Errorw(ctx, "Evtocd delete rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00002718 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002719 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
mpagenko01e726e2020-10-23 09:45:29 +00002720 return
2721 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002722 } else {
2723 // NOTE : We should ideally never ether this section when oFsm.acceptIncrementalEvtoOption is set to false
2724 // This is true for only ATT/DT workflow
dbainbri4d3a0dc2020-12-02 00:33:42 +00002725 logger.Debugw(ctx, "UniVlanConfigFsm: Remove EVTOCD set operation",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002726 log.Fields{"configured-flow": oFsm.ConfiguredUniFlow, "incremental-evto": oFsm.acceptIncrementalEvtoOption})
mpagenkof1d21d12021-06-11 13:14:45 +00002727 oFsm.mutexFlowParams.RUnlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002728 //not transparent and not acceptIncrementalEvtoOption: untagged/priotagged->singletagged
2729 { // just for local var's
2730 // this defines stacking scenario: untagged->singletagged
2731 //TODO!! in theory there could be different rules running in setting different PCP/VID'S
2732 // for untagged/priotagged, last rule wins (and remains the only one), maybe that should be
2733 // checked already at flow-add (and rejected) - to be observed if such is possible in Voltha
2734 // delete now assumes there is only one such rule!
dbainbri4d3a0dc2020-12-02 00:33:42 +00002735 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD reset untagged rule to default", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002736 "device-id": oFsm.deviceID})
2737 sliceEvtocdRule := make([]uint8, 16)
2738 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2739 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2740 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2741 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2742 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
mpagenko01e726e2020-10-23 09:45:29 +00002743
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002744 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2745 cPrioIgnoreTag<<cFilterPrioOffset| // Not an inner-tag rule
2746 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
2747 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2748 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
mpagenko01e726e2020-10-23 09:45:29 +00002749
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002750 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
2751 0<<cTreatTTROffset| // Do not pop any tags
2752 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
2753 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2754 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
mpagenko01e726e2020-10-23 09:45:29 +00002755
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002756 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
2757 cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag
2758 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
2759 cDontCareTpid<<cTreatTpidOffset) // copy TPID and DEI
mpagenko01e726e2020-10-23 09:45:29 +00002760
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002761 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002762 EntityID: evtocdID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002763 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00002764 me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002765 },
2766 }
Girish Gowdra754ffb12021-06-30 16:30:12 -07002767 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002768 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(context.TODO(),
2769 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2770 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002771 if err != nil {
Girish Gowdra754ffb12021-06-30 16:30:12 -07002772 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002773 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2774 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002775 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002776 return
2777 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002778 //accept also nil as (error) return value for writing to LastTx
2779 // - this avoids misinterpretation of new received OMCI messages
2780 oFsm.pLastTxMeInstance = meInstance
Girish Gowdra754ffb12021-06-30 16:30:12 -07002781 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002782
2783 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002784 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002785 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002786 logger.Errorw(ctx, "Evtocd reset untagged rule to default failed, aborting VlanConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002787 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002788 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002789 return
2790 }
2791 } // just for local var's
2792 { // just for local var's
2793 // this defines 'stacking' scenario: priotagged->singletagged
dbainbri4d3a0dc2020-12-02 00:33:42 +00002794 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD delete priotagged rule", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002795 "device-id": oFsm.deviceID})
2796 sliceEvtocdRule := make([]uint8, 16)
2797 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
2798 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
2799 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
2800 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
2801 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
2802
2803 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
2804 cPrioDoNotFilter<<cFilterPrioOffset| // Do not Filter on innerprio
2805 0<<cFilterVidOffset| // filter on inner vid 0 (prioTagged)
2806 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
2807 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
2808
2809 // delete indication for the indicated Filter
2810 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], 0xFFFFFFFF)
2811 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], 0xFFFFFFFF)
2812
2813 meParams := me.ParamData{
mpagenkof1d21d12021-06-11 13:14:45 +00002814 EntityID: evtocdID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002815 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00002816 me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002817 },
2818 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002819 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002820 meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
2821 oFsm.pDeviceHandler.GetOmciTimeout(), true,
2822 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002823 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002824 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002825 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
2826 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002827 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002828 return
2829 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002830 //accept also nil as (error) return value for writing to LastTx
2831 // - this avoids misinterpretation of new received OMCI messages
2832 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002833 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002834
2835 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03002836 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002837 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002838 logger.Errorw(ctx, "Evtocd delete priotagged rule failed, aborting VlanConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002839 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002840 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002841 return
2842 }
mpagenko01e726e2020-10-23 09:45:29 +00002843 }
2844 } //just for local var's
2845 }
2846 }
mpagenkofc4f56e2020-11-04 17:17:49 +00002847 // if Config has been done for all EVTOCD entries let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00002848 logger.Debugw(ctx, "EVTOCD filter remove loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002849 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvRemFlowDone, aRuleParams.TpID)
mpagenko01e726e2020-10-23 09:45:29 +00002850}
2851
dbainbri4d3a0dc2020-12-02 00:33:42 +00002852func (oFsm *UniVlanConfigFsm) waitforOmciResponse(ctx context.Context) error {
mpagenko7d6bb022021-03-11 15:07:55 +00002853 oFsm.mutexIsAwaitingResponse.Lock()
mpagenkocf48e452021-04-23 09:23:00 +00002854 if oFsm.isCanceled {
2855 // FSM already canceled before entering wait
2856 logger.Debugw(ctx, "UniVlanConfigFsm wait-for-multi-entity-response aborted (on enter)", log.Fields{"for device-id": oFsm.deviceID})
2857 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002858 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenkocf48e452021-04-23 09:23:00 +00002859 }
mpagenko7d6bb022021-03-11 15:07:55 +00002860 oFsm.isAwaitingResponse = true
2861 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002862 select {
Himani Chawla26e555c2020-08-31 12:30:20 +05302863 // maybe be also some outside cancel (but no context modeled for the moment ...)
mpagenkodff5dda2020-08-28 11:52:01 +00002864 // case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +00002865 // logger.Infow(ctx,"LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +00002866 case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //AS FOR THE OTHER OMCI FSM's
dbainbri4d3a0dc2020-12-02 00:33:42 +00002867 logger.Warnw(ctx, "UniVlanConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00002868 oFsm.mutexIsAwaitingResponse.Lock()
2869 oFsm.isAwaitingResponse = false
2870 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00002871 return fmt.Errorf("uniVlanConfigFsm multi entity timeout %s", oFsm.deviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00002872 case success := <-oFsm.omciMIdsResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +05302873 if success {
mpagenkocf48e452021-04-23 09:23:00 +00002874 logger.Debugw(ctx, "UniVlanConfigFsm multi entity response received", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00002875 oFsm.mutexIsAwaitingResponse.Lock()
2876 oFsm.isAwaitingResponse = false
2877 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00002878 return nil
2879 }
mpagenko7d6bb022021-03-11 15:07:55 +00002880 // waiting was aborted (probably on external request)
mpagenkocf48e452021-04-23 09:23:00 +00002881 logger.Debugw(ctx, "UniVlanConfigFsm wait-for-multi-entity-response aborted", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00002882 oFsm.mutexIsAwaitingResponse.Lock()
2883 oFsm.isAwaitingResponse = false
2884 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002885 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenkodff5dda2020-08-28 11:52:01 +00002886 }
2887}
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002888
mpagenko551a4d42020-12-08 18:09:20 +00002889func (oFsm *UniVlanConfigFsm) performSettingMulticastME(ctx context.Context, tpID uint8, multicastGemPortID uint16, vlanID uint32) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002890 logger.Debugw(ctx, "Setting Multicast MEs", log.Fields{"device-id": oFsm.deviceID, "tpID": tpID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002891 "multicastGemPortID": multicastGemPortID, "vlanID": vlanID})
dbainbri4d3a0dc2020-12-02 00:33:42 +00002892 errCreateMOP := oFsm.performCreatingMulticastOperationProfile(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002893 if errCreateMOP != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002894 logger.Errorw(ctx, "MulticastOperationProfile create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002895 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002896 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002897 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, errCreateMOP)
2898 }
2899
dbainbri4d3a0dc2020-12-02 00:33:42 +00002900 errSettingMOP := oFsm.performSettingMulticastOperationProfile(ctx, multicastGemPortID, vlanID)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002901 if errSettingMOP != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002902 logger.Errorw(ctx, "MulticastOperationProfile setting failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002903 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002904 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002905 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, errSettingMOP)
2906 }
2907
dbainbri4d3a0dc2020-12-02 00:33:42 +00002908 errCreateMSCI := oFsm.performCreatingMulticastSubscriberConfigInfo(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002909 if errCreateMSCI != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002910 logger.Errorw(ctx, "MulticastOperationProfile setting failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002911 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002912 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002913 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, errCreateMSCI)
2914 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002915 macBpCdEID, errMacBpCdEID := cmn.GenerateMcastANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo))
Mahir Gunyel6781f962021-05-16 23:30:08 -07002916 if errMacBpCdEID != nil {
2917 logger.Errorw(ctx, "MulticastMacBridgePortConfigData entity id generation failed, aborting AniConfig FSM!",
2918 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002919 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
Mahir Gunyel6781f962021-05-16 23:30:08 -07002920 return fmt.Errorf("generateMcastANISideMBPCDEID responseError %s, error %s", oFsm.deviceID, errMacBpCdEID)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002921
Mahir Gunyel6781f962021-05-16 23:30:08 -07002922 }
2923 logger.Debugw(ctx, "UniVlanConfigFsm set macBpCdEID for mcast", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002924 "EntitytId": strconv.FormatInt(int64(macBpCdEID), 16), "macBpNo": oFsm.pOnuUniPort.MacBpNo,
2925 "in state": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002926 meParams := me.ParamData{
Mahir Gunyel6781f962021-05-16 23:30:08 -07002927 EntityID: macBpCdEID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002928 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00002929 me.MacBridgePortConfigurationData_BridgeIdPointer: cmn.MacBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.MacBpNo),
2930 me.MacBridgePortConfigurationData_PortNum: 0xf0, //fixed unique ANI side indication
2931 me.MacBridgePortConfigurationData_TpType: 6, //MCGemIWTP
2932 me.MacBridgePortConfigurationData_TpPointer: multicastGemPortID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002933 },
2934 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002935 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002936 meInstance, err := oFsm.pOmciCC.SendCreateMBPConfigDataVar(context.TODO(),
2937 oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002938 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002939 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002940 logger.Errorw(ctx, "MBPConfigDataVar create failed, aborting AniConfig FSM!",
2941 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002942 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002943 return fmt.Errorf("creatingMulticastSubscriberConfigInfo createError #{oFsm.deviceID}, error #{err}")
2944 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002945 //accept also nil as (error) return value for writing to LastTx
2946 // - this avoids misinterpretation of new received OMCI messages
2947 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002948 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002949 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002950 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002951 logger.Errorw(ctx, "CreateMBPConfigData failed, aborting AniConfig FSM!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002952 log.Fields{"device-id": oFsm.deviceID, "MBPConfigDataID": cmn.MacBridgeServiceProfileEID})
2953 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002954 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, err)
2955 }
2956
2957 // ==> Start creating VTFD for mcast vlan
2958
2959 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
2960 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
Mahir Gunyel6781f962021-05-16 23:30:08 -07002961 mcastVtfdID := macBpCdEID
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002962
dbainbri4d3a0dc2020-12-02 00:33:42 +00002963 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD for mcast", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002964 "EntitytId": strconv.FormatInt(int64(mcastVtfdID), 16), "mcastVlanID": vlanID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002965 "in state": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002966 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
2967
2968 // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME
2969 // VTFD has to be created afresh with a new entity ID that has the same entity ID as the MBPCD ME for every
2970 // new vlan associated with a different TP.
2971 vtfdFilterList[0] = uint16(vlanID)
2972
2973 meParams = me.ParamData{
2974 EntityID: mcastVtfdID,
2975 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00002976 me.VlanTaggingFilterData_VlanFilterList: vtfdFilterList,
2977 me.VlanTaggingFilterData_ForwardOperation: uint8(0x10), //VID investigation
2978 me.VlanTaggingFilterData_NumberOfEntries: oFsm.numVlanFilterEntries,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002979 },
2980 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002981 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002982 meInstance, err = oFsm.pOmciCC.SendCreateVtfdVar(context.TODO(),
2983 oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002984 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002985 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03002986 logger.Errorw(ctx, "CreateVtfdVar create failed, aborting UniVlanConfigFsm!",
2987 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002988 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03002989 return fmt.Errorf("createMcastVlanFilterData creationError %s, error %s", oFsm.deviceID, err)
2990 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002991 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00002992 oFsm.mutexPLastTxMeInstance.Unlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00002993 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002994 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002995 logger.Errorw(ctx, "CreateMcastVlanFilterData failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002996 log.Fields{"device-id": oFsm.deviceID, "mcastVtfdID": mcastVtfdID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002997 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002998 return fmt.Errorf("createMcastVlanFilterData responseError %s, error %s", oFsm.deviceID, err)
2999 }
3000
3001 return nil
3002}
3003
dbainbri4d3a0dc2020-12-02 00:33:42 +00003004func (oFsm *UniVlanConfigFsm) performCreatingMulticastSubscriberConfigInfo(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003005 instID, err := cmn.GenerateUNISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003006 if err != nil {
Mahir Gunyel6781f962021-05-16 23:30:08 -07003007 logger.Errorw(ctx, "error generrating me instance id",
3008 log.Fields{"device-id": oFsm.deviceID, "error": err})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003009 return err
3010 }
Mahir Gunyel6781f962021-05-16 23:30:08 -07003011 logger.Debugw(ctx, "UniVlanConfigFsm create MulticastSubscriberConfigInfo",
3012 log.Fields{"device-id": oFsm.deviceID, "EntityId": instID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003013 meParams := me.ParamData{
3014 EntityID: instID,
3015 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00003016 me.MulticastSubscriberConfigInfo_MeType: 0,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003017 //Direct reference to the Operation profile
3018 //TODO ANI side used on UNI side, not the clearest option.
ozgecanetsia5c88b762021-03-23 10:27:15 +03003019 "MulticastOperationsProfilePointer": instID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003020 },
3021 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003022 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003023 meInstance, err := oFsm.pOmciCC.SendCreateMulticastSubConfigInfoVar(context.TODO(),
3024 oFsm.pDeviceHandler.GetOmciTimeout(), true,
3025 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03003026 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003027 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03003028 logger.Errorw(ctx, "CreateMulticastSubConfigInfoVar create failed, aborting UniVlanConfigFSM!",
3029 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003030 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03003031 return fmt.Errorf("creatingMulticastSubscriberConfigInfo interface creationError %s, error %s",
3032 oFsm.deviceID, err)
3033 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003034 //accept also nil as (error) return value for writing to LastTx
3035 // - this avoids misinterpretation of new received OMCI messages
3036 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003037 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003038 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00003039 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003040 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003041 logger.Errorw(ctx, "CreateMulticastSubConfigInfo create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003042 log.Fields{"device-id": oFsm.deviceID, "MulticastSubConfigInfo": instID})
3043 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s", oFsm.deviceID)
3044 }
3045 return nil
3046}
3047
dbainbri4d3a0dc2020-12-02 00:33:42 +00003048func (oFsm *UniVlanConfigFsm) performCreatingMulticastOperationProfile(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003049 instID, err := cmn.GenerateUNISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo))
ozgecanetsia5c88b762021-03-23 10:27:15 +03003050 if err != nil {
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03003051 logger.Errorw(ctx, "error generating me instance id",
3052 log.Fields{"device-id": oFsm.deviceID, "error": err})
ozgecanetsia5c88b762021-03-23 10:27:15 +03003053 return err
3054 }
Mahir Gunyel6781f962021-05-16 23:30:08 -07003055 logger.Debugw(ctx, "UniVlanConfigFsm create MulticastOperationProfile",
3056 log.Fields{"device-id": oFsm.deviceID, "EntityId": instID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003057 meParams := me.ParamData{
3058 EntityID: instID,
3059 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00003060 me.MulticastOperationsProfile_IgmpVersion: 2,
3061 me.MulticastOperationsProfile_IgmpFunction: 0,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003062 //0 means false
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00003063 me.MulticastOperationsProfile_ImmediateLeave: 0,
3064 me.MulticastOperationsProfile_Robustness: 2,
3065 me.MulticastOperationsProfile_QuerierIpAddress: 0,
3066 me.MulticastOperationsProfile_QueryInterval: 125,
3067 me.MulticastOperationsProfile_QueryMaxResponseTime: 100,
3068 me.MulticastOperationsProfile_LastMemberQueryInterval: 10,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003069 //0 means false
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00003070 me.MulticastOperationsProfile_UnauthorizedJoinRequestBehaviour: 0,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003071 },
3072 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003073 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003074 meInstance, err := oFsm.pOmciCC.SendCreateMulticastOperationProfileVar(context.TODO(),
3075 oFsm.pDeviceHandler.GetOmciTimeout(), true,
3076 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03003077 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003078 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03003079 logger.Errorw(ctx, "CreateMulticastOperationProfileVar create failed, aborting UniVlanConfigFsm!",
3080 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003081 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03003082 return fmt.Errorf("createMulticastOperationProfileVar responseError %s, error %s", oFsm.deviceID, err)
3083 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003084 //accept also nil as (error) return value for writing to LastTx
3085 // - this avoids misinterpretation of new received OMCI messages
3086 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003087 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003088 //verify response
ozgecanetsia5c88b762021-03-23 10:27:15 +03003089 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003090 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003091 logger.Errorw(ctx, "CreateMulticastOperationProfile create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003092 log.Fields{"device-id": oFsm.deviceID, "MulticastOperationProfileID": instID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03003093 return fmt.Errorf("createMulticastOperationProfile responseError %s, error %s", oFsm.deviceID, err)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003094 }
3095 return nil
3096}
3097
dbainbri4d3a0dc2020-12-02 00:33:42 +00003098func (oFsm *UniVlanConfigFsm) performSettingMulticastOperationProfile(ctx context.Context, multicastGemPortID uint16, vlanID uint32) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003099 instID, err := cmn.GenerateUNISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo))
ozgecanetsia5c88b762021-03-23 10:27:15 +03003100 if err != nil {
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03003101 logger.Errorw(ctx, "error generating me instance id",
3102 log.Fields{"device-id": oFsm.deviceID, "error": err})
ozgecanetsia5c88b762021-03-23 10:27:15 +03003103 return err
3104 }
Mahir Gunyel6781f962021-05-16 23:30:08 -07003105 logger.Debugw(ctx, "UniVlanConfigFsm set MulticastOperationProfile",
3106 log.Fields{"device-id": oFsm.deviceID, "EntityId": instID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003107 //TODO check that this is correct
3108 // Table control
3109 //setCtrl = 1
3110 //rowPartId = 0
3111 //test = 0
3112 //rowKey = 0
3113 tableCtrlStr := "0100000000000000"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003114 tableCtrl := cmn.AsByteSlice(tableCtrlStr)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003115 dynamicAccessCL := make([]uint8, 24)
3116 copy(dynamicAccessCL, tableCtrl)
3117 //Multicast GemPortId
3118 binary.BigEndian.PutUint16(dynamicAccessCL[2:], multicastGemPortID)
3119 // python version waits for installation of flows, see line 723 onward of
3120 // brcm_openomci_onu_handler.py
3121 binary.BigEndian.PutUint16(dynamicAccessCL[4:], uint16(vlanID))
3122 //Source IP all to 0
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003123 binary.BigEndian.PutUint32(dynamicAccessCL[6:], cmn.IPToInt32(net.IPv4(0, 0, 0, 0)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003124 //TODO start and end are hardcoded, get from TP
3125 // Destination IP address start of range
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003126 binary.BigEndian.PutUint32(dynamicAccessCL[10:], cmn.IPToInt32(net.IPv4(225, 0, 0, 0)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003127 // Destination IP address end of range
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003128 binary.BigEndian.PutUint32(dynamicAccessCL[14:], cmn.IPToInt32(net.IPv4(239, 255, 255, 255)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003129 //imputed group bandwidth
3130 binary.BigEndian.PutUint16(dynamicAccessCL[18:], 0)
3131
3132 meParams := me.ParamData{
3133 EntityID: instID,
3134 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00003135 me.MulticastOperationsProfile_DynamicAccessControlListTable: dynamicAccessCL,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003136 },
3137 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003138 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003139 meInstance, err := oFsm.pOmciCC.SendSetMulticastOperationProfileVar(context.TODO(),
3140 oFsm.pDeviceHandler.GetOmciTimeout(), true,
3141 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03003142 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003143 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03003144 logger.Errorw(ctx, "SetMulticastOperationProfileVar set failed, aborting UniVlanConfigFsm!",
3145 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003146 _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03003147 return fmt.Errorf("setMulticastOperationProfile responseError %s, error %s", oFsm.deviceID, err)
3148 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003149 //accept also nil as (error) return value for writing to LastTx
3150 // - this avoids misinterpretation of new received OMCI messages
3151 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003152 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003153 //verify response
ozgecanetsia5c88b762021-03-23 10:27:15 +03003154 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003155 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003156 logger.Errorw(ctx, "CreateMulticastOperationProfile create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003157 log.Fields{"device-id": oFsm.deviceID, "MulticastOperationProfileID": instID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03003158 return fmt.Errorf("createMulticastOperationProfile responseError %s, error %s", oFsm.deviceID, err)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003159 }
3160 return nil
3161}
Girish Gowdra26a40922021-01-29 17:14:34 -08003162
khenaidoo42dcdfd2021-10-19 17:34:12 -04003163func (oFsm *UniVlanConfigFsm) createTrafficDescriptor(ctx context.Context, aMeter *of.OfpMeterConfig,
ozgecanetsia82b91a62021-05-21 18:54:49 +03003164 tpID uint8, uniID uint8, gemPortID uint16) error {
3165 logger.Infow(ctx, "Starting create traffic descriptor", log.Fields{"device-id": oFsm.deviceID, "uniID": uniID, "tpID": tpID})
3166 // uniTPKey generate id to Traffic Descriptor ME. We need to create two of them. They should be unique. Because of that
3167 // I created unique TD ID by flow direction.
3168 // TODO! Traffic descriptor ME ID will check
3169 trafficDescriptorID := gemPortID
3170 if aMeter == nil {
3171 return fmt.Errorf("meter not found %s", oFsm.deviceID)
3172 }
3173 trafficShapingInfo, err := meters.GetTrafficShapingInfo(ctx, aMeter)
3174 if err != nil {
3175 logger.Errorw(ctx, "Traffic Shaping Info get failed", log.Fields{"device-id": oFsm.deviceID})
3176 return err
3177 }
ozgecanetsiaf5c76842021-11-18 10:43:47 +03003178 cir := (trafficShapingInfo.Cir + trafficShapingInfo.Gir) * 125 // kbps --> bps --> Bps
ozgecanetsia82b91a62021-05-21 18:54:49 +03003179 cbs := trafficShapingInfo.Cbs
ozgecanetsiaf5c76842021-11-18 10:43:47 +03003180 pir := trafficShapingInfo.Pir * 125 // kbps --> bps --> Bps
ozgecanetsia82b91a62021-05-21 18:54:49 +03003181 pbs := trafficShapingInfo.Pbs
3182
3183 logger.Infow(ctx, "cir-pir-cbs-pbs", log.Fields{"device-id": oFsm.deviceID, "cir": cir, "pir": pir, "cbs": cbs, "pbs": pbs})
3184 meParams := me.ParamData{
3185 EntityID: trafficDescriptorID,
3186 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00003187 me.TrafficDescriptor_Cir: cir,
3188 me.TrafficDescriptor_Pir: pir,
3189 me.TrafficDescriptor_Cbs: cbs,
3190 me.TrafficDescriptor_Pbs: pbs,
3191 me.TrafficDescriptor_ColourMode: 1,
3192 me.TrafficDescriptor_IngressColourMarking: 3,
3193 me.TrafficDescriptor_EgressColourMarking: 3,
3194 me.TrafficDescriptor_MeterType: 1,
ozgecanetsia82b91a62021-05-21 18:54:49 +03003195 },
3196 }
Girish Gowdra754ffb12021-06-30 16:30:12 -07003197 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003198 meInstance, errCreateTD := oFsm.pOmciCC.SendCreateTDVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(),
3199 true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsia82b91a62021-05-21 18:54:49 +03003200 if errCreateTD != nil {
Girish Gowdra754ffb12021-06-30 16:30:12 -07003201 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia82b91a62021-05-21 18:54:49 +03003202 logger.Errorw(ctx, "Traffic Descriptor create failed", log.Fields{"device-id": oFsm.deviceID})
3203 return err
3204 }
3205 oFsm.pLastTxMeInstance = meInstance
Girish Gowdra754ffb12021-06-30 16:30:12 -07003206 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia82b91a62021-05-21 18:54:49 +03003207 err = oFsm.waitforOmciResponse(ctx)
3208 if err != nil {
3209 logger.Errorw(ctx, "Traffic Descriptor create failed, aborting VlanConfig FSM!", log.Fields{"device-id": oFsm.deviceID})
3210 return err
3211 }
3212
Girish Gowdra09e5f212021-09-30 16:28:36 -07003213 // 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
3214 err = oFsm.setTrafficDescriptorToGemPortNWCTP(ctx, gemPortID, gemPortID)
ozgecanetsia82b91a62021-05-21 18:54:49 +03003215 if err != nil {
3216 logger.Errorw(ctx, "Traffic Descriptor set failed to Gem Port Network CTP, aborting VlanConfig FSM!", log.Fields{"device-id": oFsm.deviceID})
3217 return err
3218 }
3219 logger.Infow(ctx, "Set TD Info to GemPortNWCTP successfully", log.Fields{"device-id": oFsm.deviceID, "gem-port-id": gemPortID, "td-id": trafficDescriptorID})
3220
3221 return nil
3222}
3223
Girish Gowdra09e5f212021-09-30 16:28:36 -07003224func (oFsm *UniVlanConfigFsm) setTrafficDescriptorToGemPortNWCTP(ctx context.Context, gemPortEntityID uint16, trafficDescriptorEntityID uint16) error {
3225 logger.Debugw(ctx, "Starting Set Traffic Descriptor to GemPortNWCTP",
3226 log.Fields{"device-id": oFsm.deviceID, "gem-port-entity-id": gemPortEntityID, "traffic-descriptor-entity-id": trafficDescriptorEntityID})
ozgecanetsia82b91a62021-05-21 18:54:49 +03003227 meParams := me.ParamData{
Girish Gowdra09e5f212021-09-30 16:28:36 -07003228 EntityID: gemPortEntityID,
ozgecanetsia82b91a62021-05-21 18:54:49 +03003229 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00003230 me.GemPortNetworkCtp_TrafficDescriptorProfilePointerForUpstream: trafficDescriptorEntityID,
ozgecanetsia82b91a62021-05-21 18:54:49 +03003231 },
3232 }
Girish Gowdra754ffb12021-06-30 16:30:12 -07003233 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003234 meInstance, err := oFsm.pOmciCC.SendSetGemNCTPVar(log.WithSpanFromContext(context.TODO(), ctx),
3235 oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsia82b91a62021-05-21 18:54:49 +03003236 if err != nil {
Girish Gowdra754ffb12021-06-30 16:30:12 -07003237 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia82b91a62021-05-21 18:54:49 +03003238 logger.Errorw(ctx, "GemNCTP set failed", log.Fields{"device-id": oFsm.deviceID})
3239 return err
3240 }
3241 oFsm.pLastTxMeInstance = meInstance
Girish Gowdra754ffb12021-06-30 16:30:12 -07003242 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia82b91a62021-05-21 18:54:49 +03003243 err = oFsm.waitforOmciResponse(ctx)
3244 if err != nil {
3245 logger.Errorw(ctx, "Upstream Traffic Descriptor set failed, aborting VlanConfig FSM!", log.Fields{"device-id": oFsm.deviceID})
3246 return err
3247 }
3248 return nil
3249}
3250
Girish Gowdra26a40922021-01-29 17:14:34 -08003251// IsFlowRemovePending returns true if there are pending flows to remove, else false.
Holger Hildebrandtc192bc42021-10-28 14:38:31 +00003252func (oFsm *UniVlanConfigFsm) IsFlowRemovePending(ctx context.Context, aFlowDeleteChannel chan<- bool) bool {
3253 if oFsm == nil {
3254 logger.Error(ctx, "no valid UniVlanConfigFsm!")
3255 return false
3256 }
mpagenkobb47bc22021-04-20 13:29:09 +00003257 oFsm.mutexFlowParams.Lock()
3258 defer oFsm.mutexFlowParams.Unlock()
3259 if len(oFsm.uniRemoveFlowsSlice) > 0 {
3260 //flow removal is still ongoing/pending
3261 oFsm.signalOnFlowDelete = true
3262 oFsm.flowDeleteChannel = aFlowDeleteChannel
3263 return true
3264 }
3265 return false
Girish Gowdra26a40922021-01-29 17:14:34 -08003266}
Holger Hildebrandt968eb8f2021-09-17 07:41:12 +00003267
3268func (oFsm *UniVlanConfigFsm) reconcileVlanFilterList(ctx context.Context, aSetVid uint16) {
3269 // VOL-4342 - reconcile vlanFilterList[] for possible later flow removal
3270 if aSetVid == uint16(of.OfpVlanId_OFPVID_PRESENT) {
3271 logger.Debugw(ctx, "reconciling - transparent setup: no VTFD config was required",
3272 log.Fields{"device-id": oFsm.deviceID})
3273 } else {
3274 oFsm.vlanFilterList[oFsm.numVlanFilterEntries] = aSetVid
3275 logger.Debugw(ctx, "reconciling - Vid of VTFD stored in list", log.Fields{
3276 "index": oFsm.numVlanFilterEntries,
3277 "vid": strconv.FormatInt(int64(oFsm.vlanFilterList[oFsm.numVlanFilterEntries]), 16),
3278 "device-id": oFsm.deviceID})
3279 oFsm.numVlanFilterEntries++
3280 }
3281}
Girish Gowdrae95687a2021-09-08 16:30:58 -07003282
Holger Hildebrandtc192bc42021-10-28 14:38:31 +00003283// pushReponseOnFlowResponseChannel pushes response on the response channel if available
3284func (oFsm *UniVlanConfigFsm) pushReponseOnFlowResponseChannel(ctx context.Context, respChan *chan error, err error) {
Girish Gowdrae95687a2021-09-08 16:30:58 -07003285 if respChan != nil {
3286 // 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
3287 select {
3288 case *respChan <- err:
3289 logger.Debugw(ctx, "submitted-response-for-flow", log.Fields{"device-id": oFsm.deviceID, "err": err})
3290 default:
3291 }
3292 }
3293}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00003294
3295// PrepareForGarbageCollection - remove references to prepare for garbage collection
3296func (oFsm *UniVlanConfigFsm) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
3297 logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
3298 oFsm.pDeviceHandler = nil
3299 oFsm.pOnuDeviceEntry = nil
3300 oFsm.pOmciCC = nil
3301}