blob: 308d3af1a2c341ffe18a4b29724449f5596a64ec [file] [log] [blame]
mpagenkodff5dda2020-08-28 11:52:01 +00001/*
2 * Copyright 2020-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
19
20import (
21 "context"
22 "encoding/binary"
Andrea Campanella6515c582020-10-05 11:25:00 +020023 "fmt"
ozgecanetsiab5000ef2020-11-27 14:38:20 +030024 "net"
mpagenkodff5dda2020-08-28 11:52:01 +000025 "strconv"
Holger Hildebrandt394c5522020-09-11 11:23:01 +000026 "sync"
mpagenkodff5dda2020-08-28 11:52:01 +000027 "time"
28
mpagenko01e726e2020-10-23 09:45:29 +000029 gp "github.com/google/gopacket"
mpagenkodff5dda2020-08-28 11:52:01 +000030 "github.com/looplab/fsm"
31 "github.com/opencord/omci-lib-go"
32 me "github.com/opencord/omci-lib-go/generated"
dbainbri4d3a0dc2020-12-02 00:33:42 +000033 "github.com/opencord/voltha-lib-go/v4/pkg/log"
34 of "github.com/opencord/voltha-protos/v4/go/openflow_13"
mpagenkodff5dda2020-08-28 11:52:01 +000035)
36
37const (
38 // internal predefined values
39 cDefaultDownstreamMode = 0
40 cDefaultTpid = 0x8100
mpagenko01e726e2020-10-23 09:45:29 +000041 cVtfdTableSize = 12 //as per G.988
42 cMaxAllowedFlows = cVtfdTableSize //which might be under discussion, for the moment connected to limit of VLAN's within VTFD
mpagenkodff5dda2020-08-28 11:52:01 +000043)
44
45const (
mpagenkof1fc3862021-02-16 10:09:52 +000046 // internal offsets for requestEvent according to definition in onu_device_entry::OnuDeviceEvent
47 cDeviceEventOffsetAddWithKvStore = 0 //OmciVlanFilterAddDone - OmciVlanFilterAddDone cannot use because of lint
48 cDeviceEventOffsetAddNoKvStore = OmciVlanFilterAddDoneNoKvStore - OmciVlanFilterAddDone
49 cDeviceEventOffsetRemoveWithKvStore = OmciVlanFilterRemDone - OmciVlanFilterAddDone
50 cDeviceEventOffsetRemoveNoKvStore = OmciVlanFilterRemDoneNoKvStore - OmciVlanFilterAddDone
51)
52
53const (
mpagenkodff5dda2020-08-28 11:52:01 +000054 // bit mask offsets for EVTOCD VlanTaggingOperationTable related to 32 bits (4 bytes)
55 cFilterPrioOffset = 28
56 cFilterVidOffset = 15
57 cFilterTpidOffset = 12
58 cFilterEtherTypeOffset = 0
59 cTreatTTROffset = 30
60 cTreatPrioOffset = 16
61 cTreatVidOffset = 3
62 cTreatTpidOffset = 0
63)
64const (
65 // byte offsets for EVTOCD VlanTaggingOperationTable related to overall 16 byte size with slice byte 0 as first Byte (MSB)
66 cFilterOuterOffset = 0
67 cFilterInnerOffset = 4
68 cTreatOuterOffset = 8
69 cTreatInnerOffset = 12
70)
71const (
72 // basic values used within EVTOCD VlanTaggingOperationTable in respect to their bitfields
73 cPrioIgnoreTag uint32 = 15
74 cPrioDefaultFilter uint32 = 14
75 cPrioDoNotFilter uint32 = 8
76 cDoNotFilterVid uint32 = 4096
77 cDoNotFilterTPID uint32 = 0
78 cDoNotFilterEtherType uint32 = 0
79 cDoNotAddPrio uint32 = 15
80 cCopyPrioFromInner uint32 = 8
Himani Chawla4d908332020-08-31 12:30:20 +053081 //cDontCarePrio uint32 = 0
mpagenkodff5dda2020-08-28 11:52:01 +000082 cDontCareVid uint32 = 0
83 cDontCareTpid uint32 = 0
84 cSetOutputTpidCopyDei uint32 = 4
85)
86
87const (
Holger Hildebrandt10d98192021-01-27 15:29:31 +000088 // events of config UNI port VLAN FSM
mpagenko535d6ef2021-02-26 13:15:34 +000089 vlanEvStart = "vlanEvStart"
90 vlanEvWaitTechProf = "vlanEvWaitTechProf"
91 vlanEvCancelOutstandingConfig = "vlanEvCancelOutstandingConfig"
92 vlanEvContinueConfig = "vlanEvContinueConfig"
93 vlanEvStartConfig = "vlanEvStartConfig"
94 vlanEvRxConfigVtfd = "vlanEvRxConfigVtfd"
95 vlanEvRxConfigEvtocd = "vlanEvRxConfigEvtocd"
96 vlanEvWaitTPIncr = "vlanEvWaitTPIncr"
97 vlanEvIncrFlowConfig = "vlanEvIncrFlowConfig"
98 vlanEvRenew = "vlanEvRenew"
99 vlanEvRemFlowConfig = "vlanEvRemFlowConfig"
100 vlanEvRemFlowDone = "vlanEvRemFlowDone"
101 vlanEvFlowDataRemoved = "vlanEvFlowDataRemoved"
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000102 //vlanEvTimeoutSimple = "vlanEvTimeoutSimple"
103 //vlanEvTimeoutMids = "vlanEvTimeoutMids"
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000104 vlanEvReset = "vlanEvReset"
105 vlanEvRestart = "vlanEvRestart"
106 vlanEvSkipOmciConfig = "vlanEvSkipOmciConfig"
107 vlanEvSkipIncFlowConfig = "vlanEvSkipIncFlowConfig"
mpagenkodff5dda2020-08-28 11:52:01 +0000108)
mpagenko01e726e2020-10-23 09:45:29 +0000109
mpagenkodff5dda2020-08-28 11:52:01 +0000110const (
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000111 // states of config UNI port VLAN FSM
mpagenkodff5dda2020-08-28 11:52:01 +0000112 vlanStDisabled = "vlanStDisabled"
113 vlanStStarting = "vlanStStarting"
114 vlanStWaitingTechProf = "vlanStWaitingTechProf"
115 vlanStConfigVtfd = "vlanStConfigVtfd"
116 vlanStConfigEvtocd = "vlanStConfigEvtocd"
117 vlanStConfigDone = "vlanStConfigDone"
mpagenko551a4d42020-12-08 18:09:20 +0000118 vlanStIncrFlowWaitTP = "vlanStIncrFlowWaitTP"
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000119 vlanStConfigIncrFlow = "vlanStConfigIncrFlow"
mpagenko01e726e2020-10-23 09:45:29 +0000120 vlanStRemoveFlow = "vlanStRemoveFlow"
mpagenkodff5dda2020-08-28 11:52:01 +0000121 vlanStCleanupDone = "vlanStCleanupDone"
122 vlanStResetting = "vlanStResetting"
123)
mpagenkof1fc3862021-02-16 10:09:52 +0000124const cVlanFsmIdleState = vlanStConfigDone // state where no OMCI activity is done (for a longer time)
125const cVlanFsmConfiguredState = vlanStConfigDone // state that indicates that at least some valid user related VLAN configuration should exist
mpagenkodff5dda2020-08-28 11:52:01 +0000126
mpagenko01e726e2020-10-23 09:45:29 +0000127type uniVlanRuleParams struct {
mpagenko551a4d42020-12-08 18:09:20 +0000128 TpID uint8 `json:"tp_id"`
mpagenko01e726e2020-10-23 09:45:29 +0000129 MatchVid uint32 `json:"match_vid"` //use uint32 types for allowing immediate bitshifting
130 MatchPcp uint32 `json:"match_pcp"`
131 TagsToRemove uint32 `json:"tags_to_remove"`
132 SetVid uint32 `json:"set_vid"`
133 SetPcp uint32 `json:"set_pcp"`
134}
135
136type uniVlanFlowParams struct {
137 CookieSlice []uint64 `json:"cookie_slice"`
138 VlanRuleParams uniVlanRuleParams `json:"vlan_rule_params"`
139}
140
141type uniRemoveVlanFlowParams struct {
142 cookie uint64 //just the last cookie valid for removal
143 vlanRuleParams uniVlanRuleParams
144}
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 {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530149 pDeviceHandler *deviceHandler
mpagenko01e726e2020-10-23 09:45:29 +0000150 deviceID string
Himani Chawla6d2ae152020-09-02 13:11:20 +0530151 pOmciCC *omciCC
152 pOnuUniPort *onuUniPort
153 pUniTechProf *onuUniTechProf
154 pOnuDB *onuDeviceDB
mpagenkodff5dda2020-08-28 11:52:01 +0000155 requestEvent OnuDeviceEvent
156 omciMIdsResponseReceived chan bool //seperate channel needed for checking multiInstance OMCI message responses
157 pAdaptFsm *AdapterFsm
158 acceptIncrementalEvtoOption bool
mpagenko2418ab02020-11-12 12:58:06 +0000159 clearPersistency 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
mpagenko9a304ea2020-12-16 15:54:01 +0000165 actualUniVlanConfigRule uniVlanRuleParams
mpagenko01e726e2020-10-23 09:45:29 +0000166 uniVlanFlowParamsSlice []uniVlanFlowParams
167 uniRemoveFlowsSlice []uniRemoveVlanFlowParams
Holger Hildebrandt394c5522020-09-11 11:23:01 +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
mpagenkodff5dda2020-08-28 11:52:01 +0000182}
183
mpagenko01e726e2020-10-23 09:45:29 +0000184//NewUniVlanConfigFsm is the 'constructor' for the state machine to config the PON ANI ports
185// of ONU UNI ports via OMCI
dbainbri4d3a0dc2020-12-02 00:33:42 +0000186func NewUniVlanConfigFsm(ctx context.Context, apDeviceHandler *deviceHandler, apDevOmciCC *omciCC, apUniPort *onuUniPort,
mpagenko551a4d42020-12-08 18:09:20 +0000187 apUniTechProf *onuUniTechProf, apOnuDB *onuDeviceDB, aTechProfileID uint8,
mpagenko01e726e2020-10-23 09:45:29 +0000188 aRequestEvent OnuDeviceEvent, aName string, aCommChannel chan Message, aAcceptIncrementalEvto bool,
189 aCookieSlice []uint64, aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) *UniVlanConfigFsm {
mpagenkodff5dda2020-08-28 11:52:01 +0000190 instFsm := &UniVlanConfigFsm{
191 pDeviceHandler: apDeviceHandler,
mpagenko01e726e2020-10-23 09:45:29 +0000192 deviceID: apDeviceHandler.deviceID,
mpagenkodff5dda2020-08-28 11:52:01 +0000193 pOmciCC: apDevOmciCC,
194 pOnuUniPort: apUniPort,
195 pUniTechProf: apUniTechProf,
196 pOnuDB: apOnuDB,
mpagenkodff5dda2020-08-28 11:52:01 +0000197 requestEvent: aRequestEvent,
198 acceptIncrementalEvtoOption: aAcceptIncrementalEvto,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000199 numUniFlows: 0,
200 configuredUniFlow: 0,
mpagenko01e726e2020-10-23 09:45:29 +0000201 numRemoveFlows: 0,
mpagenko2418ab02020-11-12 12:58:06 +0000202 clearPersistency: true,
mpagenkodff5dda2020-08-28 11:52:01 +0000203 }
204
mpagenko01e726e2020-10-23 09:45:29 +0000205 instFsm.pAdaptFsm = NewAdapterFsm(aName, instFsm.deviceID, aCommChannel)
mpagenkodff5dda2020-08-28 11:52:01 +0000206 if instFsm.pAdaptFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000207 logger.Errorw(ctx, "UniVlanConfigFsm's AdapterFsm could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000208 "device-id": instFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000209 return nil
210 }
mpagenkodff5dda2020-08-28 11:52:01 +0000211 instFsm.pAdaptFsm.pFsm = fsm.NewFSM(
212 vlanStDisabled,
213 fsm.Events{
214 {Name: vlanEvStart, Src: []string{vlanStDisabled}, Dst: vlanStStarting},
215 {Name: vlanEvWaitTechProf, Src: []string{vlanStStarting}, Dst: vlanStWaitingTechProf},
mpagenko535d6ef2021-02-26 13:15:34 +0000216 {Name: vlanEvCancelOutstandingConfig, Src: []string{vlanStWaitingTechProf}, Dst: vlanStConfigDone},
mpagenkodff5dda2020-08-28 11:52:01 +0000217 {Name: vlanEvContinueConfig, Src: []string{vlanStWaitingTechProf}, Dst: vlanStConfigVtfd},
218 {Name: vlanEvStartConfig, Src: []string{vlanStStarting}, Dst: vlanStConfigVtfd},
219 {Name: vlanEvRxConfigVtfd, Src: []string{vlanStConfigVtfd}, Dst: vlanStConfigEvtocd},
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000220 {Name: vlanEvRxConfigEvtocd, Src: []string{vlanStConfigEvtocd, vlanStConfigIncrFlow},
221 Dst: vlanStConfigDone},
mpagenko551a4d42020-12-08 18:09:20 +0000222 {Name: vlanEvRenew, Src: []string{vlanStConfigDone}, Dst: vlanStStarting},
223 {Name: vlanEvWaitTPIncr, Src: []string{vlanStConfigDone}, Dst: vlanStIncrFlowWaitTP},
224 {Name: vlanEvIncrFlowConfig, Src: []string{vlanStConfigDone, vlanStIncrFlowWaitTP},
225 Dst: vlanStConfigIncrFlow},
mpagenko01e726e2020-10-23 09:45:29 +0000226 {Name: vlanEvRemFlowConfig, Src: []string{vlanStConfigDone}, Dst: vlanStRemoveFlow},
227 {Name: vlanEvRemFlowDone, Src: []string{vlanStRemoveFlow}, Dst: vlanStCleanupDone},
228 {Name: vlanEvFlowDataRemoved, Src: []string{vlanStCleanupDone}, Dst: vlanStConfigDone},
mpagenkodff5dda2020-08-28 11:52:01 +0000229 /*
230 {Name: vlanEvTimeoutSimple, Src: []string{
231 vlanStCreatingDot1PMapper, vlanStCreatingMBPCD, vlanStSettingTconts, vlanStSettingDot1PMapper}, Dst: vlanStStarting},
232 {Name: vlanEvTimeoutMids, Src: []string{
233 vlanStCreatingGemNCTPs, vlanStCreatingGemIWs, vlanStSettingPQs}, Dst: vlanStStarting},
234 */
235 // exceptional treatment for all states except vlanStResetting
236 {Name: vlanEvReset, Src: []string{vlanStStarting, vlanStWaitingTechProf,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000237 vlanStConfigVtfd, vlanStConfigEvtocd, vlanStConfigDone, vlanStConfigIncrFlow,
mpagenko01e726e2020-10-23 09:45:29 +0000238 vlanStRemoveFlow, vlanStCleanupDone},
mpagenkodff5dda2020-08-28 11:52:01 +0000239 Dst: vlanStResetting},
240 // the only way to get to resource-cleared disabled state again is via "resseting"
241 {Name: vlanEvRestart, Src: []string{vlanStResetting}, Dst: vlanStDisabled},
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000242 // transitions for reconcile handling according to VOL-3834
243 {Name: vlanEvSkipOmciConfig, Src: []string{vlanStStarting}, Dst: vlanStConfigDone},
244 {Name: vlanEvSkipOmciConfig, Src: []string{vlanStConfigDone}, Dst: vlanStConfigIncrFlow},
245 {Name: vlanEvSkipIncFlowConfig, Src: []string{vlanStConfigIncrFlow}, Dst: vlanStConfigDone},
mpagenkodff5dda2020-08-28 11:52:01 +0000246 },
mpagenkodff5dda2020-08-28 11:52:01 +0000247 fsm.Callbacks{
dbainbri4d3a0dc2020-12-02 00:33:42 +0000248 "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(ctx, e) },
249 "enter_" + vlanStStarting: func(e *fsm.Event) { instFsm.enterConfigStarting(ctx, e) },
250 "enter_" + vlanStConfigVtfd: func(e *fsm.Event) { instFsm.enterConfigVtfd(ctx, e) },
251 "enter_" + vlanStConfigEvtocd: func(e *fsm.Event) { instFsm.enterConfigEvtocd(ctx, e) },
252 "enter_" + vlanStConfigDone: func(e *fsm.Event) { instFsm.enterVlanConfigDone(ctx, e) },
253 "enter_" + vlanStConfigIncrFlow: func(e *fsm.Event) { instFsm.enterConfigIncrFlow(ctx, e) },
254 "enter_" + vlanStRemoveFlow: func(e *fsm.Event) { instFsm.enterRemoveFlow(ctx, e) },
255 "enter_" + vlanStCleanupDone: func(e *fsm.Event) { instFsm.enterVlanCleanupDone(ctx, e) },
256 "enter_" + vlanStResetting: func(e *fsm.Event) { instFsm.enterResetting(ctx, e) },
257 "enter_" + vlanStDisabled: func(e *fsm.Event) { instFsm.enterDisabled(ctx, e) },
mpagenkodff5dda2020-08-28 11:52:01 +0000258 },
259 )
260 if instFsm.pAdaptFsm.pFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000261 logger.Errorw(ctx, "UniVlanConfigFsm's Base FSM could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000262 "device-id": instFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000263 return nil
264 }
265
dbainbri4d3a0dc2020-12-02 00:33:42 +0000266 _ = instFsm.initUniFlowParams(ctx, aTechProfileID, aCookieSlice, aMatchVlan, aSetVlan, aSetPcp)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000267
dbainbri4d3a0dc2020-12-02 00:33:42 +0000268 logger.Debugw(ctx, "UniVlanConfigFsm created", log.Fields{"device-id": instFsm.deviceID,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000269 "accIncrEvto": instFsm.acceptIncrementalEvtoOption})
mpagenkodff5dda2020-08-28 11:52:01 +0000270 return instFsm
271}
272
mpagenko01e726e2020-10-23 09:45:29 +0000273//initUniFlowParams is a simplified form of SetUniFlowParams() used for first flow parameters configuration
mpagenko551a4d42020-12-08 18:09:20 +0000274func (oFsm *UniVlanConfigFsm) initUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64,
mpagenko01e726e2020-10-23 09:45:29 +0000275 aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) error {
276 loRuleParams := uniVlanRuleParams{
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000277 TpID: aTpID,
278 MatchVid: uint32(aMatchVlan),
279 SetVid: uint32(aSetVlan),
280 SetPcp: uint32(aSetPcp),
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000281 }
282 // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters
mpagenko01e726e2020-10-23 09:45:29 +0000283 loRuleParams.TagsToRemove = 1 //one tag to remove as default setting
284 loRuleParams.MatchPcp = cPrioDoNotFilter // do not Filter on prio as default
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000285
mpagenko01e726e2020-10-23 09:45:29 +0000286 if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000287 //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 +0000288 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000289 //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther)
290 } else {
291 if !oFsm.acceptIncrementalEvtoOption {
292 //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries
mpagenko01e726e2020-10-23 09:45:29 +0000293 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000294 }
295 }
296
mpagenko01e726e2020-10-23 09:45:29 +0000297 if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000298 // no prio/vid filtering requested
mpagenko01e726e2020-10-23 09:45:29 +0000299 loRuleParams.TagsToRemove = 0 //no tag pop action
300 loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering
301 if loRuleParams.SetPcp == cCopyPrioFromInner {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000302 //in case of no filtering and configured PrioCopy ensure default prio setting to 0
303 // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged
304 // might collide with NoMatchVid/CopyPrio(/setVid) setting
305 // this was some precondition setting taken over from py adapter ..
mpagenko01e726e2020-10-23 09:45:29 +0000306 loRuleParams.SetPcp = 0
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000307 }
308 }
mpagenko01e726e2020-10-23 09:45:29 +0000309
310 loFlowParams := uniVlanFlowParams{VlanRuleParams: loRuleParams}
311 loFlowParams.CookieSlice = make([]uint64, 0)
312 loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...)
313
314 //no mutex protection is required for initial access and adding the first flow is always possible
315 oFsm.uniVlanFlowParamsSlice = make([]uniVlanFlowParams, 0)
316 oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000317 logger.Debugw(ctx, "first UniVlanConfigFsm flow added", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000318 "Cookies": oFsm.uniVlanFlowParamsSlice[0].CookieSlice,
319 "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16),
320 "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
321 "SetPcp": loRuleParams.SetPcp,
322 "device-id": oFsm.deviceID})
323 oFsm.numUniFlows = 1
324 oFsm.uniRemoveFlowsSlice = make([]uniRemoveVlanFlowParams, 0) //initially nothing to remove
325
326 //permanently store flow config for reconcile case
dbainbri4d3a0dc2020-12-02 00:33:42 +0000327 if err := oFsm.pDeviceHandler.storePersUniFlowConfig(ctx, oFsm.pOnuUniPort.uniID,
mpagenkof1fc3862021-02-16 10:09:52 +0000328 &oFsm.uniVlanFlowParamsSlice, true); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000329 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +0000330 return err
331 }
332
333 return nil
334}
335
mpagenko7d6bb022021-03-11 15:07:55 +0000336//CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM
mpagenko73143992021-04-09 15:17:10 +0000337func (oFsm *UniVlanConfigFsm) CancelProcessing(ctx context.Context) {
mpagenko7d6bb022021-03-11 15:07:55 +0000338 //mutex protection is required for possible concurrent access to FSM members
mpagenkocf48e452021-04-23 09:23:00 +0000339 oFsm.mutexIsAwaitingResponse.Lock()
340 oFsm.isCanceled = true
mpagenko7d6bb022021-03-11 15:07:55 +0000341 if oFsm.isAwaitingResponse {
mpagenkocf48e452021-04-23 09:23:00 +0000342 //attention: for an unbuffered channel the sender is blocked until the value is received (processed)!
343 // accordingly the mutex must be released before sending to channel here (mutex acquired in receiver)
344 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko7d6bb022021-03-11 15:07:55 +0000345 //use channel to indicate that the response waiting shall be aborted
346 oFsm.omciMIdsResponseReceived <- false
mpagenkocf48e452021-04-23 09:23:00 +0000347 } else {
348 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko7d6bb022021-03-11 15:07:55 +0000349 }
mpagenkocf48e452021-04-23 09:23:00 +0000350
mpagenko7d6bb022021-03-11 15:07:55 +0000351 // in any case (even if it might be automatically requested by above cancellation of waiting) ensure resetting the FSM
352 pAdaptFsm := oFsm.pAdaptFsm
353 if pAdaptFsm != nil {
mpagenkobb47bc22021-04-20 13:29:09 +0000354 if fsmErr := pAdaptFsm.pFsm.Event(vlanEvReset); fsmErr != nil {
mpagenkocf48e452021-04-23 09:23:00 +0000355 logger.Errorw(ctx, "reset-event failed in UniVlanConfigFsm!",
mpagenkobb47bc22021-04-20 13:29:09 +0000356 log.Fields{"fsmState": oFsm.pAdaptFsm.pFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000357 }
mpagenko7d6bb022021-03-11 15:07:55 +0000358 }
359}
360
mpagenko551a4d42020-12-08 18:09:20 +0000361//GetWaitingTpID returns the TpId that the FSM might be waiting for continuation (0 if none)
362func (oFsm *UniVlanConfigFsm) GetWaitingTpID() uint8 {
363 //mutex protection is required for possible concurrent access to FSM members
364 oFsm.mutexFlowParams.RLock()
365 defer oFsm.mutexFlowParams.RUnlock()
366 return oFsm.TpIDWaitingFor
367}
368
mpagenko2418ab02020-11-12 12:58:06 +0000369//RequestClearPersistency sets the internal flag to not clear persistency data (false=NoClear)
370func (oFsm *UniVlanConfigFsm) RequestClearPersistency(aClear bool) {
371 //mutex protection is required for possible concurrent access to FSM members
mpagenko15ff4a52021-03-02 10:09:20 +0000372 oFsm.mutexFlowParams.Lock()
373 defer oFsm.mutexFlowParams.Unlock()
mpagenko2418ab02020-11-12 12:58:06 +0000374 oFsm.clearPersistency = aClear
375}
376
mpagenko01e726e2020-10-23 09:45:29 +0000377//SetUniFlowParams verifies on existence of flow parameters to be configured,
378// optionally udates the cookie list or appends a new flow if there is space
379// if possible the FSM is trigggerd to start with the processing
mpagenko551a4d42020-12-08 18:09:20 +0000380// ignore complexity by now
381// nolint: gocyclo
382func (oFsm *UniVlanConfigFsm) SetUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64,
mpagenko01e726e2020-10-23 09:45:29 +0000383 aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) error {
384 loRuleParams := uniVlanRuleParams{
385 TpID: aTpID,
386 MatchVid: uint32(aMatchVlan),
387 SetVid: uint32(aSetVlan),
388 SetPcp: uint32(aSetPcp),
389 }
390 // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters
391 loRuleParams.TagsToRemove = 1 //one tag to remove as default setting
392 loRuleParams.MatchPcp = cPrioDoNotFilter // do not Filter on prio as default
393
394 if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
395 //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries
396 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
397 //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther)
398 } else {
399 if !oFsm.acceptIncrementalEvtoOption {
400 //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries
401 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
402 }
403 }
404
405 if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
406 // no prio/vid filtering requested
407 loRuleParams.TagsToRemove = 0 //no tag pop action
408 loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering
409 if loRuleParams.SetPcp == cCopyPrioFromInner {
410 //in case of no filtering and configured PrioCopy ensure default prio setting to 0
411 // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged
412 // might collide with NoMatchVid/CopyPrio(/setVid) setting
413 // this was some precondition setting taken over from py adapter ..
414 loRuleParams.SetPcp = 0
415 }
416 }
417
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000418 flowEntryMatch := false
mpagenko01e726e2020-10-23 09:45:29 +0000419 flowCookieModify := false
mpagenkof1fc3862021-02-16 10:09:52 +0000420 requestAppendRule := false
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000421 //mutex protection is required for possible concurrent access to FSM members
422 oFsm.mutexFlowParams.Lock()
mpagenko01e726e2020-10-23 09:45:29 +0000423 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
424 //TODO: Verify if using e.g. hashes for the structures here for comparison may generate
425 // countable run time optimization (perhaps with including the hash in kvStore storage?)
426 if storedUniFlowParams.VlanRuleParams == loRuleParams {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000427 flowEntryMatch = true
dbainbri4d3a0dc2020-12-02 00:33:42 +0000428 logger.Debugw(ctx, "UniVlanConfigFsm flow setting - rule already exists", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000429 "device-id": oFsm.deviceID})
430 var cookieMatch bool
431 for _, newCookie := range aCookieSlice { // for all cookies available in the arguments
432 cookieMatch = false
433 for _, cookie := range storedUniFlowParams.CookieSlice {
434 if cookie == newCookie {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000435 logger.Debugw(ctx, "UniVlanConfigFsm flow setting - and cookie already exists", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000436 "device-id": oFsm.deviceID, "cookie": cookie})
437 cookieMatch = true
438 break //found new cookie - no further search for this requested cookie
439 }
440 }
441 if !cookieMatch {
mpagenkof1fc3862021-02-16 10:09:52 +0000442 delayedCookie := oFsm.delayNewRuleForCookie(ctx, aCookieSlice)
443 if delayedCookie != 0 {
444 //a delay for adding the cookie to this rule is requested
445 // take care of the mutex which is already locked here, need to unlock/lock accordingly to prevent deadlock in suspension
446 oFsm.mutexFlowParams.Unlock()
447 oFsm.suspendNewRule(ctx)
448 flowCookieModify, requestAppendRule = oFsm.reviseFlowConstellation(ctx, delayedCookie, loRuleParams)
449 oFsm.mutexFlowParams.Lock()
450 } else {
451 logger.Debugw(ctx, "UniVlanConfigFsm flow setting -adding new cookie", log.Fields{
452 "device-id": oFsm.deviceID, "cookie": newCookie})
453 //as range works with copies of the slice we have to write to the original slice!!
454 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(oFsm.uniVlanFlowParamsSlice[flow].CookieSlice,
455 newCookie)
456 flowCookieModify = true
457 }
mpagenko01e726e2020-10-23 09:45:29 +0000458 }
459 } //for all new cookies
460 break // found rule - no further rule search
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000461 }
462 }
mpagenkof1fc3862021-02-16 10:09:52 +0000463 oFsm.mutexFlowParams.Unlock()
464
465 if !flowEntryMatch { //it is (was) a new rule
466 delayedCookie := oFsm.suspendIfRequiredNewRule(ctx, aCookieSlice)
467 requestAppendRule = true //default assumption here is that rule is to be appended
468 flowCookieModify = true //and that the the flow data base is to be updated
469 if delayedCookie != 0 { //it was suspended
470 flowCookieModify, requestAppendRule = oFsm.reviseFlowConstellation(ctx, delayedCookie, loRuleParams)
471 }
472 }
473 kvStoreWrite := false //default setting is to not write to kvStore immediately - will be done on FSM execution finally
474 if requestAppendRule {
475 oFsm.mutexFlowParams.Lock()
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000476 if oFsm.numUniFlows < cMaxAllowedFlows {
mpagenko01e726e2020-10-23 09:45:29 +0000477 loFlowParams := uniVlanFlowParams{VlanRuleParams: loRuleParams}
478 loFlowParams.CookieSlice = make([]uint64, 0)
479 loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...)
480 oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000481 logger.Debugw(ctx, "UniVlanConfigFsm flow add", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000482 "Cookies": oFsm.uniVlanFlowParamsSlice[oFsm.numUniFlows].CookieSlice,
483 "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16),
484 "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
Girish Gowdra041dcb32020-11-16 16:54:30 -0800485 "SetPcp": loRuleParams.SetPcp, "numberofFlows": oFsm.numUniFlows + 1,
mpagenko01e726e2020-10-23 09:45:29 +0000486 "device-id": oFsm.deviceID})
487
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000488 oFsm.numUniFlows++
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000489 pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm
490
491 if oFsm.pDeviceHandler.isSkipOnuConfigReconciling() {
492 logger.Debugw(ctx, "reconciling - skip omci-config of additional vlan rule",
493 log.Fields{"fsmState": oFsm.pAdaptFsm.pFsm.Current(), "device-id": oFsm.deviceID})
mpagenkobb47bc22021-04-20 13:29:09 +0000494 //attention: take care to release the mutexFlowParams when calling the FSM directly -
495 // synchronous FSM 'event/state' functions may rely on this mutex
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000496 oFsm.mutexFlowParams.Unlock()
497 if pConfigVlanStateBaseFsm.Is(vlanStConfigDone) {
mpagenkobb47bc22021-04-20 13:29:09 +0000498 if fsmErr := pConfigVlanStateBaseFsm.Event(vlanEvSkipOmciConfig); fsmErr != nil {
499 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
500 log.Fields{"fsmState": oFsm.pAdaptFsm.pFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
501 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000502 }
503 return nil
504 }
mpagenko01e726e2020-10-23 09:45:29 +0000505 // note: theoretical it would be possible to clear the same rule from the remove slice
506 // (for entries that have not yet been started with removal)
507 // but that is getting quite complicated - maybe a future optimization in case it should prove reasonable
508 // anyway the precondition here is that the FSM checks for rules to delete first and adds new rules afterwards
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000509
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000510 if pConfigVlanStateBaseFsm.Is(vlanStConfigDone) {
511 //have to re-trigger the FSM to proceed with outstanding incremental flow configuration
mpagenko551a4d42020-12-08 18:09:20 +0000512 if oFsm.configuredUniFlow == 0 {
513 // this is a restart with a complete new flow, we can re-use the initial flow config control
514 // including the check, if the related techProfile is (still) available (probably also removed in between)
mpagenkobb47bc22021-04-20 13:29:09 +0000515 //attention: take care to release the mutexFlowParams when calling the FSM directly -
516 // synchronous FSM 'event/state' functions may rely on this mutex
517 oFsm.mutexFlowParams.Unlock()
518 if fsmErr := pConfigVlanStateBaseFsm.Event(vlanEvRenew); fsmErr != nil {
519 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
520 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
521 }
mpagenko551a4d42020-12-08 18:09:20 +0000522 } else {
523 //some further flows are to be configured
mpagenko9a304ea2020-12-16 15:54:01 +0000524 //store the actual rule that shall be worked upon in the following transient states
525 oFsm.actualUniVlanConfigRule = oFsm.uniVlanFlowParamsSlice[oFsm.configuredUniFlow].VlanRuleParams
mpagenko551a4d42020-12-08 18:09:20 +0000526 //tpId of the next rule to be configured
mpagenko9a304ea2020-12-16 15:54:01 +0000527 tpID := oFsm.actualUniVlanConfigRule.TpID
mpagenko551a4d42020-12-08 18:09:20 +0000528 loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.uniID, tpID)
529 oFsm.TpIDWaitingFor = tpID
mpagenko9a304ea2020-12-16 15:54:01 +0000530 logger.Debugw(ctx, "UniVlanConfigFsm - incremental config request (on setConfig)", log.Fields{
531 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID,
532 "set-Vlan": oFsm.actualUniVlanConfigRule.SetVid, "tp-id": tpID, "ProfDone": loTechProfDone})
mpagenkobb47bc22021-04-20 13:29:09 +0000533
534 //attention: take care to release the mutexFlowParams when calling the FSM directly -
535 // synchronous FSM 'event/state' functions may rely on this mutex
536 oFsm.mutexFlowParams.Unlock()
537 var fsmErr error
538 if loTechProfDone {
539 // let the vlan processing continue with next rule
540 fsmErr = pConfigVlanStateBaseFsm.Event(vlanEvIncrFlowConfig)
541 } else {
542 // set to waiting for Techprofile
543 fsmErr = pConfigVlanStateBaseFsm.Event(vlanEvWaitTPIncr)
544 }
545 if fsmErr != nil {
546 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
547 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
548 }
mpagenko551a4d42020-12-08 18:09:20 +0000549 }
mpagenkobb47bc22021-04-20 13:29:09 +0000550 } else {
551 // if not in the appropriate state a new entry will be automatically considered later
552 // when the configDone state is reached
553 oFsm.mutexFlowParams.Unlock()
554 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000555 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000556 logger.Errorw(ctx, "UniVlanConfigFsm flow limit exceeded", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000557 "device-id": oFsm.deviceID, "flow-number": oFsm.numUniFlows})
mpagenko15ff4a52021-03-02 10:09:20 +0000558 oFsm.mutexFlowParams.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +0000559 return fmt.Errorf(" UniVlanConfigFsm flow limit exceeded %s", oFsm.deviceID)
560 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000561 } else {
562 // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately
mpagenkof1fc3862021-02-16 10:09:52 +0000563 kvStoreWrite = true // ensure actual data write to kvStore immediately (no FSM activity)
mpagenko15ff4a52021-03-02 10:09:20 +0000564 oFsm.mutexFlowParams.RLock()
mpagenkofc4f56e2020-11-04 17:17:49 +0000565 if oFsm.numUniFlows == oFsm.configuredUniFlow {
566 //all requested rules really have been configured
567 // state transition notification is checked in deviceHandler
mpagenko15ff4a52021-03-02 10:09:20 +0000568 oFsm.mutexFlowParams.RUnlock()
mpagenkofc4f56e2020-11-04 17:17:49 +0000569 if oFsm.pDeviceHandler != nil {
570 //also the related TechProfile was already configured
dbainbri4d3a0dc2020-12-02 00:33:42 +0000571 logger.Debugw(ctx, "UniVlanConfigFsm rule already set - send immediate add-success event for reason update", log.Fields{
mpagenkofc4f56e2020-11-04 17:17:49 +0000572 "device-id": oFsm.deviceID})
mpagenkof1fc3862021-02-16 10:09:52 +0000573 // success indication without the need to write to kvStore (done already below with updated data from storePersUniFlowConfig())
574 go oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetAddNoKvStore))
mpagenkofc4f56e2020-11-04 17:17:49 +0000575 }
576 } else {
577 // avoid device reason update as the rule config connected to this flow may still be in progress
578 // and the device reason should only be updated on success of rule config
dbainbri4d3a0dc2020-12-02 00:33:42 +0000579 logger.Debugw(ctx, "UniVlanConfigFsm rule already set but configuration ongoing, suppress early add-success event for reason update",
mpagenkofc4f56e2020-11-04 17:17:49 +0000580 log.Fields{"device-id": oFsm.deviceID,
581 "NumberofRules": oFsm.numUniFlows, "Configured rules": oFsm.configuredUniFlow})
mpagenko15ff4a52021-03-02 10:09:20 +0000582 oFsm.mutexFlowParams.RUnlock()
mpagenkofc4f56e2020-11-04 17:17:49 +0000583 }
584 }
mpagenko01e726e2020-10-23 09:45:29 +0000585
mpagenkof1fc3862021-02-16 10:09:52 +0000586 if flowCookieModify { // some change was done to the flow entries
mpagenko01e726e2020-10-23 09:45:29 +0000587 //permanently store flow config for reconcile case
mpagenko15ff4a52021-03-02 10:09:20 +0000588 oFsm.mutexFlowParams.RLock()
mpagenkof1fc3862021-02-16 10:09:52 +0000589 if err := oFsm.pDeviceHandler.storePersUniFlowConfig(ctx, oFsm.pOnuUniPort.uniID,
590 &oFsm.uniVlanFlowParamsSlice, kvStoreWrite); err != nil {
mpagenko15ff4a52021-03-02 10:09:20 +0000591 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000592 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +0000593 return err
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000594 }
mpagenko15ff4a52021-03-02 10:09:20 +0000595 oFsm.mutexFlowParams.RUnlock()
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000596 }
597 return nil
598}
599
mpagenkof1fc3862021-02-16 10:09:52 +0000600// VOL-3828 flow config sequence workaround ########### start ##########
601func (oFsm *UniVlanConfigFsm) delayNewRuleForCookie(ctx context.Context, aCookieSlice []uint64) uint64 {
602 //assumes mutexFlowParams.Lock() protection from caller!
603 if oFsm.delayNewRuleCookie == 0 && len(aCookieSlice) == 1 {
604 // if not already waiting, limitation for this workaround is to just have one overlapping cookie/rule
605 // suspend check is done only of there is only one cookie in the request
606 // background: more elements only expected in reconcile use case, where no conflicting sequence is to be expected
607 newCookie := aCookieSlice[0]
608 for _, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
609 for _, cookie := range storedUniFlowParams.CookieSlice {
610 if cookie == newCookie {
611 logger.Debugw(ctx, "UniVlanConfigFsm flow setting - new cookie still exists for some rule", log.Fields{
612 "device-id": oFsm.deviceID, "cookie": cookie, "exists with SetVlan": storedUniFlowParams.VlanRuleParams.SetVid})
613 oFsm.delayNewRuleCookie = newCookie
614 return newCookie //found new cookie in some existing rule
615 }
616 } // for all stored cookies of the actual inspected rule
617 } //for all rules
618 }
619 return 0 //no delay requested
620}
621func (oFsm *UniVlanConfigFsm) suspendNewRule(ctx context.Context) {
622 oFsm.mutexFlowParams.RLock()
623 logger.Infow(ctx, "Need to suspend adding this rule as long as the cookie is still connected to some other rule", log.Fields{
624 "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie})
625 oFsm.mutexFlowParams.RUnlock()
626 select {
627 case <-oFsm.chCookieDeleted:
628 logger.Infow(ctx, "resume adding this rule after having deleted cookie in some other rule", log.Fields{
629 "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000630 case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second):
mpagenkof1fc3862021-02-16 10:09:52 +0000631 logger.Errorw(ctx, "timeout waiting for deletion of cookie in some other rule, just try to continue", log.Fields{
632 "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie})
633 }
634 oFsm.mutexFlowParams.Lock()
635 oFsm.delayNewRuleCookie = 0
636 oFsm.mutexFlowParams.Unlock()
637}
638func (oFsm *UniVlanConfigFsm) suspendIfRequiredNewRule(ctx context.Context, aCookieSlice []uint64) uint64 {
639 oFsm.mutexFlowParams.Lock()
640 delayedCookie := oFsm.delayNewRuleForCookie(ctx, aCookieSlice)
641 oFsm.mutexFlowParams.Unlock()
642
643 if delayedCookie != 0 {
644 oFsm.suspendNewRule(ctx)
645 }
646 return delayedCookie
647}
648
649//returns flowModified, RuleAppendRequest
650func (oFsm *UniVlanConfigFsm) reviseFlowConstellation(ctx context.Context, aCookie uint64, aUniVlanRuleParams uniVlanRuleParams) (bool, bool) {
651 flowEntryMatch := false
652 oFsm.mutexFlowParams.Lock()
653 defer oFsm.mutexFlowParams.Unlock()
654 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
655 if storedUniFlowParams.VlanRuleParams == aUniVlanRuleParams {
656 flowEntryMatch = true
657 logger.Debugw(ctx, "UniVlanConfigFsm flow revise - rule already exists", log.Fields{
658 "device-id": oFsm.deviceID})
659 cookieMatch := false
660 for _, cookie := range storedUniFlowParams.CookieSlice {
661 if cookie == aCookie {
662 logger.Debugw(ctx, "UniVlanConfigFsm flow revise - and cookie already exists", log.Fields{
663 "device-id": oFsm.deviceID, "cookie": cookie})
664 cookieMatch = true
665 break //found new cookie - no further search for this requested cookie
666 }
667 }
668 if !cookieMatch {
669 logger.Debugw(ctx, "UniVlanConfigFsm flow revise -adding new cookie", log.Fields{
670 "device-id": oFsm.deviceID, "cookie": aCookie})
671 //as range works with copies of the slice we have to write to the original slice!!
672 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(oFsm.uniVlanFlowParamsSlice[flow].CookieSlice,
673 aCookie)
674 return true, false //flowModified, NoRuleAppend
675 }
676 break // found rule - no further rule search
677 }
678 }
679 if !flowEntryMatch { //it is a new rule
680 return true, true //flowModified, RuleAppend
681 }
682 return false, false //flowNotModified, NoRuleAppend
683}
684
685// VOL-3828 flow config sequence workaround ########### end ##########
686
mpagenko01e726e2020-10-23 09:45:29 +0000687//RemoveUniFlowParams verifies on existence of flow cookie,
688// if found removes cookie from flow cookie list and if this is empty
689// initiates removal of the flow related configuration from the ONU (via OMCI)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000690func (oFsm *UniVlanConfigFsm) RemoveUniFlowParams(ctx context.Context, aCookie uint64) error {
mpagenkof1fc3862021-02-16 10:09:52 +0000691 var deletedCookie uint64
mpagenko01e726e2020-10-23 09:45:29 +0000692 flowCookieMatch := false
693 //mutex protection is required for possible concurrent access to FSM members
694 oFsm.mutexFlowParams.Lock()
695 defer oFsm.mutexFlowParams.Unlock()
mpagenkof1fc3862021-02-16 10:09:52 +0000696remove_loop:
mpagenko01e726e2020-10-23 09:45:29 +0000697 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
698 for i, cookie := range storedUniFlowParams.CookieSlice {
699 if cookie == aCookie {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000700 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - cookie found", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000701 "device-id": oFsm.deviceID, "cookie": cookie})
702 flowCookieMatch = true
mpagenkof1fc3862021-02-16 10:09:52 +0000703 deletedCookie = aCookie
704 kvStoreWrite := false //default setting is to not write to kvStore immediately - will be done on FSM execution finally
mpagenko01e726e2020-10-23 09:45:29 +0000705 //remove the cookie from the cookie slice and verify it is getting empty
706 if len(storedUniFlowParams.CookieSlice) == 1 {
mpagenko535d6ef2021-02-26 13:15:34 +0000707 pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm
708 var cancelPendingConfig bool = false
709 var loRemoveParams uniRemoveVlanFlowParams = uniRemoveVlanFlowParams{}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000710 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - full flow removal", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000711 "device-id": oFsm.deviceID})
mpagenko15ff4a52021-03-02 10:09:20 +0000712 //rwCore flow recovery may be the reason for this delete, in which case the flowToBeDeleted may be the same
mpagenko535d6ef2021-02-26 13:15:34 +0000713 // as the one still waiting in the FSM as toAdd but waiting for TechProfileConfig
mpagenko15ff4a52021-03-02 10:09:20 +0000714 // so we have to check if we have to abort the outstanding AddRequest and regard the current DelRequest as done
mpagenko535d6ef2021-02-26 13:15:34 +0000715 // if the Fsm is in some other transient (config) state, we will reach the DelRequest later and correctly process it then
716 if pConfigVlanStateBaseFsm.Is(vlanStWaitingTechProf) {
717 logger.Debugw(ctx, "UniVlanConfigFsm was waiting for TechProf config with this rule, aborting the outstanding config",
718 log.Fields{"device-id": oFsm.deviceID})
719 cancelPendingConfig = true
720 } else {
721 //create a new element for the removeVlanFlow slice
722 loRemoveParams = uniRemoveVlanFlowParams{
723 vlanRuleParams: storedUniFlowParams.VlanRuleParams,
724 cookie: aCookie,
725 }
726 oFsm.uniRemoveFlowsSlice = append(oFsm.uniRemoveFlowsSlice, loRemoveParams)
mpagenko01e726e2020-10-23 09:45:29 +0000727 }
mpagenko01e726e2020-10-23 09:45:29 +0000728
729 //and remove the actual element from the addVlanFlow slice
730 // oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = nil //automatically done by garbage collector
731 if len(oFsm.uniVlanFlowParamsSlice) <= 1 {
732 oFsm.numUniFlows = 0 //no more flows
733 oFsm.configuredUniFlow = 0 //no more flows configured
734 oFsm.uniVlanFlowParamsSlice = nil //reset the slice
mpagenko2418ab02020-11-12 12:58:06 +0000735 //at this point it is evident that no flow anymore refers to a still possibly active Techprofile
mpagenko535d6ef2021-02-26 13:15:34 +0000736 //request that this profile gets deleted before a new flow add is allowed (except for some aborted add)
737 if !cancelPendingConfig {
738 oFsm.pUniTechProf.setProfileToDelete(oFsm.pOnuUniPort.uniID, loRemoveParams.vlanRuleParams.TpID, true)
739 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000740 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - no more flows", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000741 "device-id": oFsm.deviceID})
742 } else {
743 oFsm.numUniFlows--
744 if oFsm.configuredUniFlow > 0 {
745 oFsm.configuredUniFlow--
746 //TODO!! might be needed to consider still outstanding configure requests ..
747 // so a flow at removal might still not be configured !?!
748 }
mpagenko2418ab02020-11-12 12:58:06 +0000749 usedTpID := storedUniFlowParams.VlanRuleParams.TpID
mpagenko01e726e2020-10-23 09:45:29 +0000750 //cut off the requested flow by slicing out this element
751 oFsm.uniVlanFlowParamsSlice = append(
752 oFsm.uniVlanFlowParamsSlice[:flow], oFsm.uniVlanFlowParamsSlice[flow+1:]...)
mpagenko2418ab02020-11-12 12:58:06 +0000753 //here we have to check, if there are still other flows referencing to the actual ProfileId
754 // before we can request that this profile gets deleted before a new flow add is allowed
mpagenkof1fc3862021-02-16 10:09:52 +0000755 // (needed to extract to function due to lint complexity)
mpagenko535d6ef2021-02-26 13:15:34 +0000756 if !cancelPendingConfig {
757 oFsm.updateTechProfileToDelete(ctx, usedTpID)
758 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000759 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - specific flow removed from data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000760 "device-id": oFsm.deviceID})
761 }
762 //trigger the FSM to remove the relevant rule
mpagenko535d6ef2021-02-26 13:15:34 +0000763 if cancelPendingConfig {
764 oFsm.requestEventOffset = uint8(cDeviceEventOffsetRemoveWithKvStore) //offset for last flow-remove activity (with kvStore request)
mpagenkobb47bc22021-04-20 13:29:09 +0000765 //attention: take care to release and re-take the mutexFlowParams when calling the FSM directly -
766 // synchronous FSM 'event/state' functions may rely on this mutex
767 oFsm.mutexFlowParams.Unlock()
768 if fsmErr := pConfigVlanStateBaseFsm.Event(vlanEvCancelOutstandingConfig); fsmErr != nil {
769 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
770 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
771 }
772 oFsm.mutexFlowParams.Lock()
mpagenko535d6ef2021-02-26 13:15:34 +0000773 } else {
774 if pConfigVlanStateBaseFsm.Is(vlanStConfigDone) {
775 logger.Debugw(ctx, "UniVlanConfigFsm rule removal request", log.Fields{
776 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID,
777 "tp-id": loRemoveParams.vlanRuleParams.TpID,
778 "set-Vlan": loRemoveParams.vlanRuleParams.SetVid})
779 //have to re-trigger the FSM to proceed with outstanding incremental flow configuration
mpagenkobb47bc22021-04-20 13:29:09 +0000780 //attention: take care to release and re-take the mutexFlowParams when calling the FSM directly -
781 // synchronous FSM 'event/state' functions may rely on this mutex
782 oFsm.mutexFlowParams.Unlock()
783 if fsmErr := pConfigVlanStateBaseFsm.Event(vlanEvRemFlowConfig); fsmErr != nil {
784 logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!",
785 log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID})
786 }
787 oFsm.mutexFlowParams.Lock()
mpagenko535d6ef2021-02-26 13:15:34 +0000788 } // if not in the appropriate state a new entry will be automatically considered later
789 // when the configDone state is reached
790 }
mpagenko01e726e2020-10-23 09:45:29 +0000791 } else {
mpagenko01e726e2020-10-23 09:45:29 +0000792 //cut off the requested cookie by slicing out this element
793 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(
794 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[:i],
795 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[i+1:]...)
mpagenkofc4f56e2020-11-04 17:17:49 +0000796 // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately
mpagenkof1fc3862021-02-16 10:09:52 +0000797 kvStoreWrite = true // ensure actual data write to kvStore immediately (no FSM activity)
mpagenkofc4f56e2020-11-04 17:17:49 +0000798 // state transition notification is checked in deviceHandler
799 if oFsm.pDeviceHandler != nil {
mpagenkof1fc3862021-02-16 10:09:52 +0000800 // success indication without the need to write to kvStore (done already below with updated data from storePersUniFlowConfig())
801 go oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetRemoveNoKvStore))
mpagenkofc4f56e2020-11-04 17:17:49 +0000802 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000803 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - rule persists with still valid cookies", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000804 "device-id": oFsm.deviceID, "cookies": oFsm.uniVlanFlowParamsSlice[flow].CookieSlice})
mpagenkof1fc3862021-02-16 10:09:52 +0000805 if deletedCookie == oFsm.delayNewRuleCookie {
806 //the delayedNewCookie is the one that is currently deleted, but the rule still exist with other cookies
807 //as long as there are further cookies for this rule indicate there is still some cookie to be deleted
808 //simply use the first one
809 oFsm.delayNewRuleCookie = oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[0]
810 logger.Debugw(ctx, "UniVlanConfigFsm remaining cookie awaited for deletion before new rule add", log.Fields{
811 "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie})
812 }
mpagenko01e726e2020-10-23 09:45:29 +0000813 }
mpagenko01e726e2020-10-23 09:45:29 +0000814 //permanently store the modified flow config for reconcile case
mpagenkofc4f56e2020-11-04 17:17:49 +0000815 if oFsm.pDeviceHandler != nil {
mpagenkof1fc3862021-02-16 10:09:52 +0000816 if err := oFsm.pDeviceHandler.storePersUniFlowConfig(ctx, oFsm.pOnuUniPort.uniID,
817 &oFsm.uniVlanFlowParamsSlice, kvStoreWrite); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000818 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +0000819 return err
820 }
mpagenko01e726e2020-10-23 09:45:29 +0000821 }
mpagenkof1fc3862021-02-16 10:09:52 +0000822 break remove_loop //found the cookie - no further search for this requested cookie
mpagenko01e726e2020-10-23 09:45:29 +0000823 }
824 }
mpagenko01e726e2020-10-23 09:45:29 +0000825 } //search all flows
826 if !flowCookieMatch { //some cookie remove-request for a cookie that does not exist in the FSM data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000827 logger.Warnw(ctx, "UniVlanConfigFsm flow removal - remove-cookie not found", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000828 "device-id": oFsm.deviceID, "remove-cookie": aCookie})
829 // but accept the request with success as no such cookie (flow) does exist
mpagenkofc4f56e2020-11-04 17:17:49 +0000830 // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately
831 // state transition notification is checked in deviceHandler
832 if oFsm.pDeviceHandler != nil {
mpagenkof1fc3862021-02-16 10:09:52 +0000833 // success indication without the need to write to kvStore (no change)
834 go oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetRemoveNoKvStore))
mpagenkofc4f56e2020-11-04 17:17:49 +0000835 }
mpagenko01e726e2020-10-23 09:45:29 +0000836 return nil
837 } //unknown cookie
838
839 return nil
840}
841
mpagenkof1fc3862021-02-16 10:09:52 +0000842func (oFsm *UniVlanConfigFsm) updateTechProfileToDelete(ctx context.Context, usedTpID uint8) {
843 //here we have to check, if there are still other flows referencing to the actual ProfileId
844 // before we can request that this profile gets deleted before a new flow add is allowed
845 tpIDInOtherFlows := false
846 for _, tpUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
847 if tpUniFlowParams.VlanRuleParams.TpID == usedTpID {
848 tpIDInOtherFlows = true
849 break // search loop can be left
850 }
851 }
852 if tpIDInOtherFlows {
853 logger.Debugw(ctx, "UniVlanConfigFsm tp-id used in deleted flow is still used in other flows", log.Fields{
854 "device-id": oFsm.deviceID, "tp-id": usedTpID})
855 } else {
856 logger.Debugw(ctx, "UniVlanConfigFsm tp-id used in deleted flow is not used anymore", log.Fields{
857 "device-id": oFsm.deviceID, "tp-id": usedTpID})
858 //request that this profile gets deleted before a new flow add is allowed
859 oFsm.pUniTechProf.setProfileToDelete(oFsm.pOnuUniPort.uniID, usedTpID, true)
860 }
861}
862
dbainbri4d3a0dc2020-12-02 00:33:42 +0000863func (oFsm *UniVlanConfigFsm) enterConfigStarting(ctx context.Context, e *fsm.Event) {
864 logger.Debugw(ctx, "UniVlanConfigFsm start", log.Fields{"in state": e.FSM.Current(),
mpagenko01e726e2020-10-23 09:45:29 +0000865 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000866
867 // this FSM is not intended for re-start, needs always new creation for a new run
mpagenko01e726e2020-10-23 09:45:29 +0000868 // (self-destroying - compare enterDisabled())
mpagenkodff5dda2020-08-28 11:52:01 +0000869 oFsm.omciMIdsResponseReceived = make(chan bool)
mpagenkof1fc3862021-02-16 10:09:52 +0000870 oFsm.chCookieDeleted = make(chan bool)
mpagenkodff5dda2020-08-28 11:52:01 +0000871 // start go routine for processing of LockState messages
dbainbri4d3a0dc2020-12-02 00:33:42 +0000872 go oFsm.processOmciVlanMessages(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +0000873 //let the state machine run forward from here directly
874 pConfigVlanStateAFsm := oFsm.pAdaptFsm
875 if pConfigVlanStateAFsm != nil {
mpagenko9a304ea2020-12-16 15:54:01 +0000876
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000877 if oFsm.pDeviceHandler.isSkipOnuConfigReconciling() {
878 logger.Debugw(ctx, "reconciling - skip omci-config of vlan rule",
879 log.Fields{"fsmState": oFsm.pAdaptFsm.pFsm.Current(), "device-id": oFsm.deviceID})
880 go func(a_pAFsm *AdapterFsm) {
881 _ = a_pAFsm.pFsm.Event(vlanEvSkipOmciConfig)
882 }(pConfigVlanStateAFsm)
883 return
884 }
885 oFsm.mutexFlowParams.Lock()
mpagenko9a304ea2020-12-16 15:54:01 +0000886 //possibly the entry is not valid anymore based on intermediate delete requests
887 //just a basic protection ...
888 if len(oFsm.uniVlanFlowParamsSlice) == 0 {
889 oFsm.mutexFlowParams.Unlock()
890 logger.Debugw(ctx, "UniVlanConfigFsm start: no rule entry anymore available", log.Fields{
891 "device-id": oFsm.deviceID})
892 // Can't call FSM Event directly, decoupling it
893 go func(a_pAFsm *AdapterFsm) {
894 _ = a_pAFsm.pFsm.Event(vlanEvReset)
895 }(pConfigVlanStateAFsm)
896 return
897 }
mpagenko9a304ea2020-12-16 15:54:01 +0000898 //access to uniVlanFlowParamsSlice is done on first element only here per definition
899 //store the actual rule that shall be worked upon in the following transient states
900 oFsm.actualUniVlanConfigRule = oFsm.uniVlanFlowParamsSlice[0].VlanRuleParams
mpagenko9a304ea2020-12-16 15:54:01 +0000901 tpID := oFsm.actualUniVlanConfigRule.TpID
902 oFsm.TpIDWaitingFor = tpID
mpagenko551a4d42020-12-08 18:09:20 +0000903 loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.uniID, uint8(tpID))
mpagenko9a304ea2020-12-16 15:54:01 +0000904 logger.Debugw(ctx, "UniVlanConfigFsm - start with first rule", log.Fields{
905 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID,
906 "set-Vlan": oFsm.actualUniVlanConfigRule.SetVid, "tp-id": tpID, "ProfDone": loTechProfDone})
mpagenko551a4d42020-12-08 18:09:20 +0000907 //cmp also usage in EVTOCDE create in omci_cc
908 oFsm.evtocdID = macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo)
mpagenko535d6ef2021-02-26 13:15:34 +0000909 oFsm.mutexFlowParams.Unlock()
mpagenko9a304ea2020-12-16 15:54:01 +0000910 // Can't call FSM Event directly, decoupling it
mpagenko551a4d42020-12-08 18:09:20 +0000911 go func(aPAFsm *AdapterFsm, aTechProfDone bool) {
912 if aPAFsm != nil && aPAFsm.pFsm != nil {
913 if aTechProfDone {
mpagenkodff5dda2020-08-28 11:52:01 +0000914 // let the vlan processing begin
mpagenko551a4d42020-12-08 18:09:20 +0000915 _ = aPAFsm.pFsm.Event(vlanEvStartConfig)
mpagenkodff5dda2020-08-28 11:52:01 +0000916 } else {
917 // set to waiting for Techprofile
mpagenko551a4d42020-12-08 18:09:20 +0000918 _ = aPAFsm.pFsm.Event(vlanEvWaitTechProf)
mpagenkodff5dda2020-08-28 11:52:01 +0000919 }
920 }
mpagenko551a4d42020-12-08 18:09:20 +0000921 }(pConfigVlanStateAFsm, loTechProfDone)
922 } else {
923 logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{
924 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
925 //should never happen, else: recovery would be needed from outside the FSM
926 return
mpagenkodff5dda2020-08-28 11:52:01 +0000927 }
928}
929
dbainbri4d3a0dc2020-12-02 00:33:42 +0000930func (oFsm *UniVlanConfigFsm) enterConfigVtfd(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000931 //mutex protection is required for possible concurrent access to FSM members
932 oFsm.mutexFlowParams.Lock()
mpagenko551a4d42020-12-08 18:09:20 +0000933 oFsm.TpIDWaitingFor = 0 //reset indication to avoid misinterpretation
mpagenko9a304ea2020-12-16 15:54:01 +0000934 if oFsm.actualUniVlanConfigRule.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
mpagenkodff5dda2020-08-28 11:52:01 +0000935 // meaning transparent setup - no specific VTFD setting required
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000936 oFsm.mutexFlowParams.Unlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000937 logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD config required", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000938 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000939 // let the FSM proceed ... (from within this state all internal pointers may be expected to be correct)
mpagenkodff5dda2020-08-28 11:52:01 +0000940 pConfigVlanStateAFsm := oFsm.pAdaptFsm
mpagenko9a304ea2020-12-16 15:54:01 +0000941 // Can't call FSM Event directly, decoupling it
mpagenkodff5dda2020-08-28 11:52:01 +0000942 go func(a_pAFsm *AdapterFsm) {
Himani Chawla4d908332020-08-31 12:30:20 +0530943 _ = a_pAFsm.pFsm.Event(vlanEvRxConfigVtfd)
mpagenkodff5dda2020-08-28 11:52:01 +0000944 }(pConfigVlanStateAFsm)
945 } else {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300946 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
947 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
mpagenko9a304ea2020-12-16 15:54:01 +0000948 vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + uint16(oFsm.actualUniVlanConfigRule.TpID)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000949 logger.Debugw(ctx, "UniVlanConfigFsm create VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300950 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenko01e726e2020-10-23 09:45:29 +0000951 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
952 // setVid is assumed to be masked already by the caller to 12 bit
mpagenko9a304ea2020-12-16 15:54:01 +0000953 oFsm.vlanFilterList[0] = uint16(oFsm.actualUniVlanConfigRule.SetVid)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000954 oFsm.mutexFlowParams.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +0000955 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000956 vtfdFilterList[0] = oFsm.vlanFilterList[0]
957 oFsm.numVlanFilterEntries = 1
mpagenkodff5dda2020-08-28 11:52:01 +0000958 meParams := me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300959 EntityID: vtfdID,
mpagenkodff5dda2020-08-28 11:52:01 +0000960 Attributes: me.AttributeValueMap{
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000961 "VlanFilterList": vtfdFilterList, //omci lib wants a slice for serialization
962 "ForwardOperation": uint8(0x10), //VID investigation
963 "NumberOfEntries": oFsm.numVlanFilterEntries,
mpagenkodff5dda2020-08-28 11:52:01 +0000964 },
965 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000966 logger.Debugw(ctx, "UniVlanConfigFsm sendcreate VTFD", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000967 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000968 oFsm.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300969 meInstance, err := oFsm.pOmciCC.sendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true,
mpagenkodff5dda2020-08-28 11:52:01 +0000970 oFsm.pAdaptFsm.commChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300971 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000972 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300973 logger.Errorw(ctx, "VTFD create failed, aborting UniVlanConfig FSM!",
974 log.Fields{"device-id": oFsm.deviceID})
975 pConfigVlanStateAFsm := oFsm.pAdaptFsm
976 if pConfigVlanStateAFsm != nil {
977 go func(a_pAFsm *AdapterFsm) {
978 _ = a_pAFsm.pFsm.Event(vlanEvReset)
979 }(pConfigVlanStateAFsm)
980 }
981 return
982 }
mpagenkodff5dda2020-08-28 11:52:01 +0000983 //accept also nil as (error) return value for writing to LastTx
984 // - this avoids misinterpretation of new received OMCI messages
985 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
986 // send shall return (dual format) error code that can be used here for immediate error treatment
987 // (relevant to all used sendXX() methods in this (and other) FSM's)
mpagenko01e726e2020-10-23 09:45:29 +0000988 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000989 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +0000990 }
991}
992
dbainbri4d3a0dc2020-12-02 00:33:42 +0000993func (oFsm *UniVlanConfigFsm) enterConfigEvtocd(ctx context.Context, e *fsm.Event) {
994 logger.Debugw(ctx, "UniVlanConfigFsm - start config EVTOCD loop", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000995 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
mpagenkof1fc3862021-02-16 10:09:52 +0000996 oFsm.requestEventOffset = uint8(cDeviceEventOffsetAddWithKvStore) //0 offset for last flow-add activity
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300997 go func() {
mpagenko9a304ea2020-12-16 15:54:01 +0000998 //using the first element in the slice because it's the first flow per definition here
999 errEvto := oFsm.performConfigEvtocdEntries(ctx, 0)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001000 //This is correct passing scenario
1001 if errEvto == nil {
mpagenko9a304ea2020-12-16 15:54:01 +00001002 tpID := oFsm.actualUniVlanConfigRule.TpID
1003 vlanID := oFsm.actualUniVlanConfigRule.SetVid
dbainbri4d3a0dc2020-12-02 00:33:42 +00001004 for _, gemPort := range oFsm.pUniTechProf.getMulticastGemPorts(ctx, oFsm.pOnuUniPort.uniID, uint8(tpID)) {
1005 logger.Infow(ctx, "Setting multicast MEs, with first flow", log.Fields{"deviceID": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001006 "techProfile": tpID, "gemPort": gemPort, "vlanID": vlanID, "configuredUniFlow": oFsm.configuredUniFlow})
dbainbri4d3a0dc2020-12-02 00:33:42 +00001007 errCreateAllMulticastME := oFsm.performSettingMulticastME(ctx, tpID, gemPort,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001008 vlanID)
1009 if errCreateAllMulticastME != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001010 logger.Errorw(ctx, "Multicast ME create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001011 log.Fields{"device-id": oFsm.deviceID})
1012 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1013 }
1014 }
1015 //TODO Possibly insert new state for multicast --> possibly another jira/later time.
1016 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigEvtocd)
1017 }
1018 }()
mpagenkodff5dda2020-08-28 11:52:01 +00001019}
1020
dbainbri4d3a0dc2020-12-02 00:33:42 +00001021func (oFsm *UniVlanConfigFsm) enterVlanConfigDone(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001022
mpagenko9a304ea2020-12-16 15:54:01 +00001023 oFsm.mutexFlowParams.RLock()
1024 defer oFsm.mutexFlowParams.RUnlock()
1025
mpagenkof1fc3862021-02-16 10:09:52 +00001026 logger.Infow(ctx, "UniVlanConfigFsm config done - checking on more flows", log.Fields{
mpagenko551a4d42020-12-08 18:09:20 +00001027 "in state": e.FSM.Current(), "device-id": oFsm.deviceID,
1028 "overall-uni-rules": oFsm.numUniFlows, "configured-uni-rules": oFsm.configuredUniFlow})
1029 pConfigVlanStateAFsm := oFsm.pAdaptFsm
1030 if pConfigVlanStateAFsm == nil {
mpagenko551a4d42020-12-08 18:09:20 +00001031 logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{
1032 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
1033 //should never happen, else: recovery would be needed from outside the FSM
1034 return
1035 }
1036 pConfigVlanStateBaseFsm := pConfigVlanStateAFsm.pFsm
mpagenko01e726e2020-10-23 09:45:29 +00001037 if len(oFsm.uniRemoveFlowsSlice) > 0 {
1038 //some further flows are to be removed, removal always starts with the first element
mpagenko9a304ea2020-12-16 15:54:01 +00001039 logger.Debugw(ctx, "UniVlanConfigFsm rule removal from ConfigDone", log.Fields{
1040 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID,
1041 "tp-id": oFsm.uniRemoveFlowsSlice[0].vlanRuleParams.TpID,
1042 "set-Vlan": oFsm.uniRemoveFlowsSlice[0].vlanRuleParams.SetVid})
1043 // Can't call FSM Event directly, decoupling it
mpagenko01e726e2020-10-23 09:45:29 +00001044 go func(a_pBaseFsm *fsm.FSM) {
1045 _ = a_pBaseFsm.Event(vlanEvRemFlowConfig)
1046 }(pConfigVlanStateBaseFsm)
1047 return
1048 }
Holger Hildebrandt1b8f4ad2021-03-25 15:53:51 +00001049 if oFsm.pDeviceHandler.isSkipOnuConfigReconciling() {
1050 oFsm.configuredUniFlow = oFsm.numUniFlows
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001051 if !oFsm.pDeviceHandler.isReconcilingFlows() {
1052 logger.Debugw(ctx, "reconciling - flow processing finished", log.Fields{"device-id": oFsm.deviceID})
1053 oFsm.pDeviceHandler.chReconcilingFlowsFinished <- true
1054 }
Holger Hildebrandt1b8f4ad2021-03-25 15:53:51 +00001055 logger.Debugw(ctx, "reconciling - skip enterVlanConfigDone processing",
1056 log.Fields{"numUniFlows": oFsm.numUniFlows, "configuredUniFlow": oFsm.configuredUniFlow, "device-id": oFsm.deviceID})
1057 return
1058 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001059 if oFsm.numUniFlows > oFsm.configuredUniFlow {
mpagenko551a4d42020-12-08 18:09:20 +00001060 if oFsm.configuredUniFlow == 0 {
mpagenko551a4d42020-12-08 18:09:20 +00001061 // this is a restart with a complete new flow, we can re-use the initial flow config control
1062 // including the check, if the related techProfile is (still) available (probably also removed in between)
mpagenko9a304ea2020-12-16 15:54:01 +00001063 // Can't call FSM Event directly, decoupling it
mpagenko551a4d42020-12-08 18:09:20 +00001064 go func(a_pBaseFsm *fsm.FSM) {
1065 _ = a_pBaseFsm.Event(vlanEvRenew)
1066 }(pConfigVlanStateBaseFsm)
1067 return
1068 }
1069
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001070 //some further flows are to be configured
mpagenko9a304ea2020-12-16 15:54:01 +00001071 //store the actual rule that shall be worked upon in the following transient states
1072 oFsm.actualUniVlanConfigRule = oFsm.uniVlanFlowParamsSlice[oFsm.configuredUniFlow].VlanRuleParams
mpagenko551a4d42020-12-08 18:09:20 +00001073 //tpId of the next rule to be configured
mpagenko9a304ea2020-12-16 15:54:01 +00001074 tpID := oFsm.actualUniVlanConfigRule.TpID
mpagenko551a4d42020-12-08 18:09:20 +00001075 oFsm.TpIDWaitingFor = tpID
mpagenko551a4d42020-12-08 18:09:20 +00001076 loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.uniID, tpID)
mpagenko9a304ea2020-12-16 15:54:01 +00001077 logger.Debugw(ctx, "UniVlanConfigFsm - incremental config request", log.Fields{
1078 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID,
1079 "set-Vlan": oFsm.actualUniVlanConfigRule.SetVid, "tp-id": tpID, "ProfDone": loTechProfDone})
1080 // Can't call FSM Event directly, decoupling it
mpagenko551a4d42020-12-08 18:09:20 +00001081 go func(aPBaseFsm *fsm.FSM, aTechProfDone bool) {
1082 if aTechProfDone {
1083 // let the vlan processing continue with next rule
1084 _ = aPBaseFsm.Event(vlanEvIncrFlowConfig)
1085 } else {
1086 // set to waiting for Techprofile
1087 _ = aPBaseFsm.Event(vlanEvWaitTPIncr)
1088 }
1089 }(pConfigVlanStateBaseFsm, loTechProfDone)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001090 return
1091 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001092 logger.Debugw(ctx, "UniVlanConfigFsm - VLAN config done: send dh event notification", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001093 "device-id": oFsm.deviceID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001094 // it might appear that some flows are requested also after 'flowPushed' event has been generated ...
1095 // state transition notification is checked in deviceHandler
mpagenko551a4d42020-12-08 18:09:20 +00001096 // note: 'flowPushed' event is only generated if all 'pending' rules are configured
mpagenkodff5dda2020-08-28 11:52:01 +00001097 if oFsm.pDeviceHandler != nil {
mpagenkofc4f56e2020-11-04 17:17:49 +00001098 //making use of the add->remove successor enum assumption/definition
dbainbri4d3a0dc2020-12-02 00:33:42 +00001099 go oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent(uint8(oFsm.requestEvent)+oFsm.requestEventOffset))
mpagenkodff5dda2020-08-28 11:52:01 +00001100 }
1101}
1102
dbainbri4d3a0dc2020-12-02 00:33:42 +00001103func (oFsm *UniVlanConfigFsm) enterConfigIncrFlow(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001104
1105 if oFsm.pDeviceHandler.isSkipOnuConfigReconciling() {
1106 logger.Debugw(ctx, "reconciling - skip further processing for incremental flow",
1107 log.Fields{"fsmState": oFsm.pAdaptFsm.pFsm.Current(), "device-id": oFsm.deviceID})
1108 go func(a_pBaseFsm *fsm.FSM) {
1109 _ = a_pBaseFsm.Event(vlanEvSkipIncFlowConfig)
1110 }(oFsm.pAdaptFsm.pFsm)
1111 return
1112 }
mpagenko15ff4a52021-03-02 10:09:20 +00001113 oFsm.mutexFlowParams.Lock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001114 logger.Debugw(ctx, "UniVlanConfigFsm - start config further incremental flow", log.Fields{
Girish Gowdra041dcb32020-11-16 16:54:30 -08001115 "in state": e.FSM.Current(), "recent flow-number": oFsm.configuredUniFlow,
mpagenko01e726e2020-10-23 09:45:29 +00001116 "device-id": oFsm.deviceID})
mpagenko551a4d42020-12-08 18:09:20 +00001117 oFsm.TpIDWaitingFor = 0 //reset indication to avoid misinterpretation
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001118
mpagenko9a304ea2020-12-16 15:54:01 +00001119 if oFsm.actualUniVlanConfigRule.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001120 // meaning transparent setup - no specific VTFD setting required
1121 oFsm.mutexFlowParams.Unlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001122 logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD config required", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001123 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001124 } else {
mpagenkocf48e452021-04-23 09:23:00 +00001125 //TODO!!!: it was not really intended to keep this enter* FSM method waiting on OMCI response (preventing other state transitions)
1126 // so it would be conceptually better to wait for the response in background like for the other multi-entity processing
1127 // but as the OMCI sequence must be ensured, a separate new state would be required - perhaps later
1128 // in practice should have no influence by now as no other state transition is currently accepted (while cancel() is ensured)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001129 if oFsm.numVlanFilterEntries == 0 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001130 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
1131 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
mpagenko9a304ea2020-12-16 15:54:01 +00001132 vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + uint16(oFsm.actualUniVlanConfigRule.TpID)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001133 //no VTFD yet created
dbainbri4d3a0dc2020-12-02 00:33:42 +00001134 logger.Debugw(ctx, "UniVlanConfigFsm create VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001135 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001136 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001137 // 'SetVid' below is assumed to be masked already by the caller to 12 bit
mpagenko9a304ea2020-12-16 15:54:01 +00001138 oFsm.vlanFilterList[0] = uint16(oFsm.actualUniVlanConfigRule.SetVid)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001139
mpagenko01e726e2020-10-23 09:45:29 +00001140 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001141 vtfdFilterList[0] = oFsm.vlanFilterList[0]
1142 oFsm.numVlanFilterEntries = 1
1143 meParams := me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001144 EntityID: vtfdID,
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001145 Attributes: me.AttributeValueMap{
1146 "VlanFilterList": vtfdFilterList,
1147 "ForwardOperation": uint8(0x10), //VID investigation
1148 "NumberOfEntries": oFsm.numVlanFilterEntries,
1149 },
1150 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001151 oFsm.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001152 meInstance, err := oFsm.pOmciCC.sendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true,
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001153 oFsm.pAdaptFsm.commChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001154 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001155 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001156 logger.Errorw(ctx, "VTFD create failed, aborting UniVlanConfig FSM!",
1157 log.Fields{"device-id": oFsm.deviceID})
1158 pConfigVlanStateAFsm := oFsm.pAdaptFsm
1159 if pConfigVlanStateAFsm != nil {
1160 go func(a_pAFsm *AdapterFsm) {
1161 _ = a_pAFsm.pFsm.Event(vlanEvReset)
1162 }(pConfigVlanStateAFsm)
1163 }
1164 return
1165 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001166 //accept also nil as (error) return value for writing to LastTx
1167 // - this avoids misinterpretation of new received OMCI messages
1168 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1169 // send shall return (dual format) error code that can be used here for immediate error treatment
1170 // (relevant to all used sendXX() methods in this (and other) FSM's)
mpagenko01e726e2020-10-23 09:45:29 +00001171 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001172 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001173 } else {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001174 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
1175 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
mpagenko551a4d42020-12-08 18:09:20 +00001176 vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID +
mpagenko9a304ea2020-12-16 15:54:01 +00001177 uint16(oFsm.actualUniVlanConfigRule.TpID)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001178
dbainbri4d3a0dc2020-12-02 00:33:42 +00001179 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001180 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001181 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001182 // setVid is assumed to be masked already by the caller to 12 bit
1183 oFsm.vlanFilterList[oFsm.numVlanFilterEntries] =
mpagenko9a304ea2020-12-16 15:54:01 +00001184 uint16(oFsm.actualUniVlanConfigRule.SetVid)
mpagenko01e726e2020-10-23 09:45:29 +00001185 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001186
1187 // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME
1188 // VTFD has to be created afresh with a new entity ID that has the same entity ID as the MBPCD ME for every
1189 // new vlan associated with a different TP.
mpagenko9a304ea2020-12-16 15:54:01 +00001190 vtfdFilterList[0] = uint16(oFsm.actualUniVlanConfigRule.SetVid)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001191
1192 oFsm.numVlanFilterEntries++
1193 meParams := me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001194 EntityID: vtfdID,
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001195 Attributes: me.AttributeValueMap{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001196 "VlanFilterList": vtfdFilterList,
1197 "ForwardOperation": uint8(0x10), //VID investigation
1198 "NumberOfEntries": oFsm.numVlanFilterEntries,
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001199 },
1200 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001201 oFsm.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001202 meInstance, err := oFsm.pOmciCC.sendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true,
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001203 oFsm.pAdaptFsm.commChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001204 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001205 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001206 logger.Errorw(ctx, "UniVlanFsm create Vlan Tagging Filter ME result error",
1207 log.Fields{"device-id": oFsm.deviceID, "Error": err})
1208 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1209 return
1210 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001211 //accept also nil as (error) return value for writing to LastTx
1212 // - this avoids misinterpretation of new received OMCI messages
1213 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1214 // send shall return (dual format) error code that can be used here for immediate error treatment
1215 // (relevant to all used sendXX() methods in this (and other) FSM's)
mpagenko01e726e2020-10-23 09:45:29 +00001216 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001217 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001218 }
mpagenko15ff4a52021-03-02 10:09:20 +00001219 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001220 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001221 err := oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001222 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001223 logger.Errorw(ctx, "VTFD create/set failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001224 log.Fields{"device-id": oFsm.deviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +00001225 pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm
mpagenko9a304ea2020-12-16 15:54:01 +00001226 // Can't call FSM Event directly, decoupling it
mpagenkofc4f56e2020-11-04 17:17:49 +00001227 go func(a_pBaseFsm *fsm.FSM) {
1228 _ = a_pBaseFsm.Event(vlanEvReset)
1229 }(pConfigVlanStateBaseFsm)
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001230 return
1231 }
1232 }
mpagenko15ff4a52021-03-02 10:09:20 +00001233 oFsm.mutexFlowParams.Lock()
mpagenkof1fc3862021-02-16 10:09:52 +00001234 oFsm.requestEventOffset = uint8(cDeviceEventOffsetAddWithKvStore) //0 offset for last flow-add activity
mpagenko15ff4a52021-03-02 10:09:20 +00001235 oFsm.mutexFlowParams.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001236 go func() {
mpagenko15ff4a52021-03-02 10:09:20 +00001237 oFsm.mutexFlowParams.RLock()
mpagenko9a304ea2020-12-16 15:54:01 +00001238 tpID := oFsm.actualUniVlanConfigRule.TpID
mpagenko15ff4a52021-03-02 10:09:20 +00001239 configuredUniFlow := oFsm.configuredUniFlow
1240 oFsm.mutexFlowParams.RUnlock()
1241 errEvto := oFsm.performConfigEvtocdEntries(ctx, configuredUniFlow)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001242 //This is correct passing scenario
1243 if errEvto == nil {
1244 //TODO Possibly insert new state for multicast --> possibly another jira/later time.
dbainbri4d3a0dc2020-12-02 00:33:42 +00001245 for _, gemPort := range oFsm.pUniTechProf.getMulticastGemPorts(ctx, oFsm.pOnuUniPort.uniID, uint8(tpID)) {
mpagenko15ff4a52021-03-02 10:09:20 +00001246 oFsm.mutexFlowParams.RLock()
mpagenko9a304ea2020-12-16 15:54:01 +00001247 vlanID := oFsm.actualUniVlanConfigRule.SetVid
dbainbri4d3a0dc2020-12-02 00:33:42 +00001248 logger.Infow(ctx, "Setting multicast MEs for additional flows", log.Fields{"deviceID": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001249 "techProfile": tpID, "gemPort": gemPort,
1250 "vlanID": vlanID, "configuredUniFlow": oFsm.configuredUniFlow})
mpagenko15ff4a52021-03-02 10:09:20 +00001251 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001252 errCreateAllMulticastME := oFsm.performSettingMulticastME(ctx, tpID, gemPort, vlanID)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001253 if errCreateAllMulticastME != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001254 logger.Errorw(ctx, "Multicast ME create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001255 log.Fields{"device-id": oFsm.deviceID})
1256 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1257 }
1258 }
1259 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigEvtocd)
1260 }
1261 }()
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001262}
1263
dbainbri4d3a0dc2020-12-02 00:33:42 +00001264func (oFsm *UniVlanConfigFsm) enterRemoveFlow(ctx context.Context, e *fsm.Event) {
mpagenko551a4d42020-12-08 18:09:20 +00001265 oFsm.mutexFlowParams.RLock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001266 logger.Debugw(ctx, "UniVlanConfigFsm - start removing the top remove-flow", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001267 "in state": e.FSM.Current(), "with last cookie": oFsm.uniRemoveFlowsSlice[0].cookie,
1268 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001269
mpagenkofc4f56e2020-11-04 17:17:49 +00001270 pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001271 loAllowSpecificOmciConfig := oFsm.pDeviceHandler.isReadyForOmciConfig()
mpagenko01e726e2020-10-23 09:45:29 +00001272 loVlanEntryClear := uint8(0)
1273 loVlanEntryRmPos := uint8(0x80) //with indication 'invalid' in bit 7
1274 //shallow copy is sufficient as no reference variables are used within struct
1275 loRuleParams := oFsm.uniRemoveFlowsSlice[0].vlanRuleParams
mpagenko551a4d42020-12-08 18:09:20 +00001276 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001277 logger.Debugw(ctx, "UniVlanConfigFsm - remove-flow parameters are", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001278 "match vid": loRuleParams.MatchVid, "match Pcp": loRuleParams.MatchPcp,
1279 "set vid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
1280 "device-id": oFsm.deviceID})
1281
1282 if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
1283 // meaning transparent setup - no specific VTFD setting required
dbainbri4d3a0dc2020-12-02 00:33:42 +00001284 logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD removal required for transparent flow", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001285 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
1286 } else {
1287 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization and 're-copy'
1288 if oFsm.numVlanFilterEntries == 1 {
mpagenko551a4d42020-12-08 18:09:20 +00001289 vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + uint16(loRuleParams.TpID)
mpagenko01e726e2020-10-23 09:45:29 +00001290 //only one active VLAN entry (hopefully the SetVID we want to remove - should be, but not verified ..)
1291 // so we can just delete the VTFD entry
dbainbri4d3a0dc2020-12-02 00:33:42 +00001292 logger.Debugw(ctx, "UniVlanConfigFsm: VTFD delete (no more vlan filters)",
mpagenko01e726e2020-10-23 09:45:29 +00001293 log.Fields{"current vlan list": oFsm.vlanFilterList,
1294 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +00001295 loVlanEntryClear = 1 //full VlanFilter clear request
1296 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001297 oFsm.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001298 meInstance, err := oFsm.pOmciCC.sendDeleteVtfd(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001299 oFsm.pAdaptFsm.commChan, vtfdID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001300 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001301 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001302 logger.Errorw(ctx, "UniVlanFsm delete Vlan Tagging Filter ME result error",
1303 log.Fields{"device-id": oFsm.deviceID, "Error": err})
1304 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1305 return
1306 }
mpagenkofc4f56e2020-11-04 17:17:49 +00001307 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001308 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkofc4f56e2020-11-04 17:17:49 +00001309 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001310 logger.Debugw(ctx, "UniVlanConfigFsm delete VTFD OMCI handling skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001311 "device-id": oFsm.deviceID, "device-state": oFsm.pDeviceHandler.getDeviceReasonString()})
mpagenkofc4f56e2020-11-04 17:17:49 +00001312 }
mpagenko01e726e2020-10-23 09:45:29 +00001313 } else {
1314 //many VTFD already should exists - find and remove the one concerned by the actual remove rule
1315 // by updating the VTFD per set command with new valid list
dbainbri4d3a0dc2020-12-02 00:33:42 +00001316 logger.Debugw(ctx, "UniVlanConfigFsm: VTFD removal of requested VLAN from the list on OMCI",
mpagenko01e726e2020-10-23 09:45:29 +00001317 log.Fields{"current vlan list": oFsm.vlanFilterList,
1318 "set-vlan": loRuleParams.SetVid, "device-id": oFsm.deviceID})
1319 for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ {
1320 if loRuleParams.SetVid == uint32(oFsm.vlanFilterList[i]) {
1321 loVlanEntryRmPos = i
1322 break //abort search
1323 }
1324 }
1325 if loVlanEntryRmPos < cVtfdTableSize {
mpagenko551a4d42020-12-08 18:09:20 +00001326 vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + uint16(loRuleParams.TpID)
mpagenko01e726e2020-10-23 09:45:29 +00001327 //valid entry was found - to be eclipsed
1328 loVlanEntryClear = 2 //VlanFilter remove request for a specific entry
1329 for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ {
1330 if i < loVlanEntryRmPos {
1331 vtfdFilterList[i] = oFsm.vlanFilterList[i] //copy original
1332 } else if i < (cVtfdTableSize - 1) {
1333 vtfdFilterList[i] = oFsm.vlanFilterList[i+1] //copy successor (including 0 elements)
1334 } else {
1335 vtfdFilterList[i] = 0 //set last byte if needed
1336 }
1337 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001338 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001339 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001340 "new vlan list": vtfdFilterList, "device-id": oFsm.deviceID})
1341
mpagenkofc4f56e2020-11-04 17:17:49 +00001342 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001343 // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001344 oFsm.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001345 meInstance, err := oFsm.pOmciCC.sendDeleteVtfd(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001346 oFsm.pAdaptFsm.commChan, vtfdID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001347 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001348 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001349 logger.Errorw(ctx, "UniVlanFsm delete Vlan Tagging Filter ME result error",
1350 log.Fields{"device-id": oFsm.deviceID, "Error": err})
1351 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1352 return
1353 }
mpagenkofc4f56e2020-11-04 17:17:49 +00001354 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001355 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkofc4f56e2020-11-04 17:17:49 +00001356 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001357 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD OMCI handling skipped based on device state", log.Fields{
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001358 "device-id": oFsm.deviceID, "device-state": oFsm.pDeviceHandler.getDeviceReasonString()})
mpagenko01e726e2020-10-23 09:45:29 +00001359 }
mpagenko01e726e2020-10-23 09:45:29 +00001360 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001361 logger.Warnw(ctx, "UniVlanConfigFsm: requested VLAN for removal not found in list - ignore and continue (no VTFD set)",
mpagenko01e726e2020-10-23 09:45:29 +00001362 log.Fields{"device-id": oFsm.deviceID})
1363 }
1364 }
1365 if loVlanEntryClear > 0 {
mpagenkofc4f56e2020-11-04 17:17:49 +00001366 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
1367 //waiting on response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001368 err := oFsm.waitforOmciResponse(ctx)
mpagenkofc4f56e2020-11-04 17:17:49 +00001369 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001370 logger.Errorw(ctx, "VTFD delete/reset failed, aborting VlanConfig FSM!",
mpagenkofc4f56e2020-11-04 17:17:49 +00001371 log.Fields{"device-id": oFsm.deviceID})
mpagenko9a304ea2020-12-16 15:54:01 +00001372 // Can't call FSM Event directly, decoupling it
mpagenkofc4f56e2020-11-04 17:17:49 +00001373 go func(a_pBaseFsm *fsm.FSM) {
1374 _ = a_pBaseFsm.Event(vlanEvReset)
1375 }(pConfigVlanStateBaseFsm)
1376 return
1377 }
mpagenko01e726e2020-10-23 09:45:29 +00001378 }
1379
mpagenko15ff4a52021-03-02 10:09:20 +00001380 oFsm.mutexFlowParams.Lock()
mpagenko01e726e2020-10-23 09:45:29 +00001381 if loVlanEntryClear == 1 {
1382 oFsm.vlanFilterList[0] = 0 //first entry is the only that can contain the previous only-one element
1383 oFsm.numVlanFilterEntries = 0
1384 } else if loVlanEntryClear == 2 {
1385 // new VlanFilterList should be one entry smaller now - copy from last configured entry
1386 // this loop now includes the 0 element on previous last valid entry
1387 for i := uint8(0); i <= oFsm.numVlanFilterEntries; i++ {
1388 oFsm.vlanFilterList[i] = vtfdFilterList[i]
1389 }
1390 oFsm.numVlanFilterEntries--
1391 }
mpagenko15ff4a52021-03-02 10:09:20 +00001392 oFsm.mutexFlowParams.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00001393 }
1394 }
1395
mpagenkofc4f56e2020-11-04 17:17:49 +00001396 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
dbainbri4d3a0dc2020-12-02 00:33:42 +00001397 go oFsm.removeEvtocdEntries(ctx, loRuleParams)
mpagenkofc4f56e2020-11-04 17:17:49 +00001398 } else {
1399 // OMCI processing is not done, expectation is to have the ONU in some basic config state accordingly
dbainbri4d3a0dc2020-12-02 00:33:42 +00001400 logger.Debugw(ctx, "UniVlanConfigFsm remove EVTOCD OMCI handling skipped based on device state", log.Fields{
mpagenkofc4f56e2020-11-04 17:17:49 +00001401 "device-id": oFsm.deviceID})
mpagenko9a304ea2020-12-16 15:54:01 +00001402 // Can't call FSM Event directly, decoupling it
mpagenkofc4f56e2020-11-04 17:17:49 +00001403 go func(a_pBaseFsm *fsm.FSM) {
Girish Gowdra26a40922021-01-29 17:14:34 -08001404 _ = a_pBaseFsm.Event(vlanEvRemFlowDone, loRuleParams.TpID)
mpagenkofc4f56e2020-11-04 17:17:49 +00001405 }(pConfigVlanStateBaseFsm)
1406 }
mpagenkodff5dda2020-08-28 11:52:01 +00001407}
1408
dbainbri4d3a0dc2020-12-02 00:33:42 +00001409func (oFsm *UniVlanConfigFsm) enterVlanCleanupDone(ctx context.Context, e *fsm.Event) {
Girish Gowdra26a40922021-01-29 17:14:34 -08001410 var tpID uint8
1411 // Extract the tpID
1412 if len(e.Args) > 0 {
1413 tpID = e.Args[0].(uint8)
1414 logger.Debugw(ctx, "UniVlanConfigFsm - flow removed for tp id", log.Fields{"device-id": oFsm.deviceID, "tpID": e.Args[0].(uint8)})
1415 } else {
1416 logger.Warnw(ctx, "UniVlanConfigFsm - tp id not available", log.Fields{"device-id": oFsm.deviceID})
1417 }
mpagenko01e726e2020-10-23 09:45:29 +00001418 oFsm.mutexFlowParams.Lock()
mpagenkof1fc3862021-02-16 10:09:52 +00001419 deletedCookie := oFsm.uniRemoveFlowsSlice[0].cookie
1420 logger.Debugw(ctx, "UniVlanConfigFsm - removing the removal data", log.Fields{
1421 "in state": e.FSM.Current(), "device-id": oFsm.deviceID,
1422 "removed cookie": deletedCookie, "waitForDeleteCookie": oFsm.delayNewRuleCookie})
1423
mpagenko01e726e2020-10-23 09:45:29 +00001424 if len(oFsm.uniRemoveFlowsSlice) <= 1 {
1425 oFsm.uniRemoveFlowsSlice = nil //reset the slice
dbainbri4d3a0dc2020-12-02 00:33:42 +00001426 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - last remove-flow deleted", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001427 "device-id": oFsm.deviceID})
1428 } else {
1429 //cut off the actual flow by slicing out the first element
1430 oFsm.uniRemoveFlowsSlice = append(
1431 oFsm.uniRemoveFlowsSlice[:0],
1432 oFsm.uniRemoveFlowsSlice[1:]...)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001433 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - specific flow deleted from data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001434 "device-id": oFsm.deviceID})
1435 }
1436 oFsm.mutexFlowParams.Unlock()
1437
mpagenkof1fc3862021-02-16 10:09:52 +00001438 oFsm.requestEventOffset = uint8(cDeviceEventOffsetRemoveWithKvStore) //offset for last flow-remove activity (with kvStore request)
mpagenko01e726e2020-10-23 09:45:29 +00001439 //return to the basic config verification state
mpagenkodff5dda2020-08-28 11:52:01 +00001440 pConfigVlanStateAFsm := oFsm.pAdaptFsm
1441 if pConfigVlanStateAFsm != nil {
mpagenko9a304ea2020-12-16 15:54:01 +00001442 // Can't call FSM Event directly, decoupling it
mpagenkodff5dda2020-08-28 11:52:01 +00001443 go func(a_pAFsm *AdapterFsm) {
1444 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
mpagenko01e726e2020-10-23 09:45:29 +00001445 _ = a_pAFsm.pFsm.Event(vlanEvFlowDataRemoved)
mpagenkodff5dda2020-08-28 11:52:01 +00001446 }
1447 }(pConfigVlanStateAFsm)
1448 }
Girish Gowdra26a40922021-01-29 17:14:34 -08001449
mpagenkobb47bc22021-04-20 13:29:09 +00001450 oFsm.mutexFlowParams.Lock()
Girish Gowdra26a40922021-01-29 17:14:34 -08001451 noOfFlowRem := len(oFsm.uniRemoveFlowsSlice)
mpagenkof1fc3862021-02-16 10:09:52 +00001452 if deletedCookie == oFsm.delayNewRuleCookie {
1453 // flush the channel CookieDeleted to ensure it is not lingering from some previous (aborted) activity
1454 select {
1455 case <-oFsm.chCookieDeleted:
1456 logger.Debug(ctx, "flushed CookieDeleted")
1457 default:
1458 }
1459 oFsm.chCookieDeleted <- true // let the waiting AddFlow thread continue
1460 }
mpagenkobb47bc22021-04-20 13:29:09 +00001461 // If all pending flow-removes are completed and TP ID is valid go on processing any pending TP delete
1462 if oFsm.signalOnFlowDelete && noOfFlowRem == 0 && tpID > 0 {
1463 logger.Debugw(ctx, "signal flow removal for pending TP delete", log.Fields{"device-id": oFsm.deviceID, "tpID": tpID})
Girish Gowdra26a40922021-01-29 17:14:34 -08001464 // If we are here then all flows are removed.
mpagenkobb47bc22021-04-20 13:29:09 +00001465 if len(oFsm.flowDeleteChannel) == 0 { //channel not yet in use
1466 oFsm.flowDeleteChannel <- true
1467 oFsm.signalOnFlowDelete = false
1468 }
Girish Gowdra26a40922021-01-29 17:14:34 -08001469 }
mpagenkobb47bc22021-04-20 13:29:09 +00001470 oFsm.mutexFlowParams.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001471}
1472
dbainbri4d3a0dc2020-12-02 00:33:42 +00001473func (oFsm *UniVlanConfigFsm) enterResetting(ctx context.Context, e *fsm.Event) {
1474 logger.Debugw(ctx, "UniVlanConfigFsm resetting", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001475
1476 pConfigVlanStateAFsm := oFsm.pAdaptFsm
1477 if pConfigVlanStateAFsm != nil {
1478 // abort running message processing
1479 fsmAbortMsg := Message{
1480 Type: TestMsg,
1481 Data: TestMessage{
1482 TestMessageVal: AbortMessageProcessing,
1483 },
1484 }
1485 pConfigVlanStateAFsm.commChan <- fsmAbortMsg
1486
mpagenko9a304ea2020-12-16 15:54:01 +00001487 //try to restart the FSM to 'disabled'
1488 // Can't call FSM Event directly, decoupling it
mpagenkodff5dda2020-08-28 11:52:01 +00001489 go func(a_pAFsm *AdapterFsm) {
1490 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301491 _ = a_pAFsm.pFsm.Event(vlanEvRestart)
mpagenkodff5dda2020-08-28 11:52:01 +00001492 }
1493 }(pConfigVlanStateAFsm)
1494 }
1495}
1496
dbainbri4d3a0dc2020-12-02 00:33:42 +00001497func (oFsm *UniVlanConfigFsm) enterDisabled(ctx context.Context, e *fsm.Event) {
1498 logger.Debugw(ctx, "UniVlanConfigFsm enters disabled state", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001499 oFsm.mutexPLastTxMeInstance.Lock()
mpagenko01e726e2020-10-23 09:45:29 +00001500 oFsm.pLastTxMeInstance = nil
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001501 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001502 if oFsm.pDeviceHandler != nil {
mpagenko2418ab02020-11-12 12:58:06 +00001503 //TODO: to clarify with improved error treatment for VlanConfigFsm (timeout,reception) errors
1504 // current code removes the complete FSM including all flow/rule configuration done so far
1505 // this might be a bit to much, it would require fully new flow config from rwCore (at least on OnuDown/up)
1506 // maybe a more sophisticated approach is possible without clearing the data
mpagenko9a304ea2020-12-16 15:54:01 +00001507 oFsm.mutexFlowParams.RLock()
mpagenko2418ab02020-11-12 12:58:06 +00001508 if oFsm.clearPersistency {
1509 //permanently remove possibly stored persistent data
1510 if len(oFsm.uniVlanFlowParamsSlice) > 0 {
1511 var emptySlice = make([]uniVlanFlowParams, 0)
mpagenkof1fc3862021-02-16 10:09:52 +00001512 _ = oFsm.pDeviceHandler.storePersUniFlowConfig(ctx, oFsm.pOnuUniPort.uniID, &emptySlice, true) //ignore errors
mpagenko2418ab02020-11-12 12:58:06 +00001513 }
1514 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001515 logger.Debugw(ctx, "UniVlanConfigFsm persistency data not cleared", log.Fields{"device-id": oFsm.deviceID})
mpagenko2418ab02020-11-12 12:58:06 +00001516 }
mpagenkof1fc3862021-02-16 10:09:52 +00001517 if oFsm.delayNewRuleCookie != 0 {
1518 // looks like the waiting AddFlow is stuck
1519 oFsm.chCookieDeleted <- true // let the waiting AddFlow thread continue/treminate
1520 }
mpagenko9a304ea2020-12-16 15:54:01 +00001521 oFsm.mutexFlowParams.RUnlock()
mpagenko2418ab02020-11-12 12:58:06 +00001522 //request removal of 'reference' in the Handler (completely clear the FSM and its data)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001523 go oFsm.pDeviceHandler.RemoveVlanFilterFsm(ctx, oFsm.pOnuUniPort)
mpagenkodff5dda2020-08-28 11:52:01 +00001524 }
1525}
1526
dbainbri4d3a0dc2020-12-02 00:33:42 +00001527func (oFsm *UniVlanConfigFsm) processOmciVlanMessages(ctx context.Context) { //ctx context.Context?
1528 logger.Debugw(ctx, "Start UniVlanConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001529loop:
1530 for {
mpagenkodff5dda2020-08-28 11:52:01 +00001531 // case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +00001532 // logger.Info(ctx,"MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001533 // break loop
Himani Chawla4d908332020-08-31 12:30:20 +05301534 message, ok := <-oFsm.pAdaptFsm.commChan
1535 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001536 logger.Info(ctx, "UniVlanConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301537 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
1538 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1539 break loop
1540 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001541 logger.Debugw(ctx, "UniVlanConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301542
1543 switch message.Type {
1544 case TestMsg:
1545 msg, _ := message.Data.(TestMessage)
1546 if msg.TestMessageVal == AbortMessageProcessing {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001547 logger.Infow(ctx, "UniVlanConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001548 break loop
1549 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001550 logger.Warnw(ctx, "UniVlanConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal})
Himani Chawla4d908332020-08-31 12:30:20 +05301551 case OMCI:
1552 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001553 oFsm.handleOmciVlanConfigMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301554 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +00001555 logger.Warn(ctx, "UniVlanConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID,
Himani Chawla4d908332020-08-31 12:30:20 +05301556 "message.Type": message.Type})
mpagenkodff5dda2020-08-28 11:52:01 +00001557 }
1558 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001559 logger.Infow(ctx, "End UniVlanConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001560}
1561
dbainbri4d3a0dc2020-12-02 00:33:42 +00001562func (oFsm *UniVlanConfigFsm) handleOmciVlanConfigMessage(ctx context.Context, msg OmciMessage) {
1563 logger.Debugw(ctx, "Rx OMCI UniVlanConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00001564 "msgType": msg.OmciMsg.MessageType})
1565
1566 switch msg.OmciMsg.MessageType {
1567 case omci.CreateResponseType:
mpagenko01e726e2020-10-23 09:45:29 +00001568 { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-(
dbainbri4d3a0dc2020-12-02 00:33:42 +00001569 if err := oFsm.handleOmciCreateResponseMessage(ctx, msg.OmciPacket); err != nil {
1570 logger.Warnw(ctx, "CreateResponse handling aborted", log.Fields{"err": err})
mpagenkodff5dda2020-08-28 11:52:01 +00001571 return
1572 }
mpagenkodff5dda2020-08-28 11:52:01 +00001573 } //CreateResponseType
1574 case omci.SetResponseType:
mpagenko01e726e2020-10-23 09:45:29 +00001575 { //leave that here as direct code as most often used
mpagenkodff5dda2020-08-28 11:52:01 +00001576 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
1577 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001578 logger.Errorw(ctx, "Omci Msg layer could not be detected for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001579 log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001580 return
1581 }
1582 msgObj, msgOk := msgLayer.(*omci.SetResponse)
1583 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001584 logger.Errorw(ctx, "Omci Msg layer could not be assigned for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001585 log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001586 return
1587 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001588 logger.Debugw(ctx, "UniVlanConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenkodff5dda2020-08-28 11:52:01 +00001589 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001590 logger.Errorw(ctx, "UniVlanConfigFsm Omci SetResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00001591 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
mpagenkodff5dda2020-08-28 11:52:01 +00001592 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
1593 return
1594 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001595 oFsm.mutexPLastTxMeInstance.RLock()
1596 if oFsm.pLastTxMeInstance != nil {
1597 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1598 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1599 switch oFsm.pLastTxMeInstance.GetName() {
1600 case "VlanTaggingFilterData", "ExtendedVlanTaggingOperationConfigurationData", "MulticastOperationsProfile":
1601 { // let the MultiEntity config proceed by stopping the wait function
1602 oFsm.mutexPLastTxMeInstance.RUnlock()
1603 oFsm.omciMIdsResponseReceived <- true
1604 return
1605 }
1606 default:
1607 {
1608 logger.Warnw(ctx, "Unsupported ME name received!",
1609 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1610 }
mpagenkodff5dda2020-08-28 11:52:01 +00001611 }
1612 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001613 } else {
1614 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001615 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001616 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001617 } //SetResponseType
mpagenko01e726e2020-10-23 09:45:29 +00001618 case omci.DeleteResponseType:
1619 { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-(
dbainbri4d3a0dc2020-12-02 00:33:42 +00001620 if err := oFsm.handleOmciDeleteResponseMessage(ctx, msg.OmciPacket); err != nil {
1621 logger.Warnw(ctx, "DeleteResponse handling aborted", log.Fields{"err": err})
mpagenko01e726e2020-10-23 09:45:29 +00001622 return
1623 }
1624 } //DeleteResponseType
mpagenkodff5dda2020-08-28 11:52:01 +00001625 default:
1626 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001627 logger.Errorw(ctx, "Rx OMCI unhandled MsgType",
mpagenko01e726e2020-10-23 09:45:29 +00001628 log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001629 return
1630 }
1631 }
1632}
1633
dbainbri4d3a0dc2020-12-02 00:33:42 +00001634func (oFsm *UniVlanConfigFsm) handleOmciCreateResponseMessage(ctx context.Context, apOmciPacket *gp.Packet) error {
mpagenko01e726e2020-10-23 09:45:29 +00001635 msgLayer := (*apOmciPacket).Layer(omci.LayerTypeCreateResponse)
1636 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001637 logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001638 log.Fields{"device-id": oFsm.deviceID})
1639 return fmt.Errorf("omci msg layer could not be detected for CreateResponse for device-id %x",
1640 oFsm.deviceID)
1641 }
1642 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
1643 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001644 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001645 log.Fields{"device-id": oFsm.deviceID})
1646 return fmt.Errorf("omci msg layer could not be assigned for CreateResponse for device-id %x",
1647 oFsm.deviceID)
1648 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001649 logger.Debugw(ctx, "UniVlanConfigFsm CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001650 if msgObj.Result != me.Success && msgObj.Result != me.InstanceExists {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001651 logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": oFsm.deviceID,
mpagenko01e726e2020-10-23 09:45:29 +00001652 "Error": msgObj.Result})
1653 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
1654 return fmt.Errorf("omci CreateResponse Error for device-id %x",
1655 oFsm.deviceID)
1656 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001657 oFsm.mutexPLastTxMeInstance.RLock()
1658 if oFsm.pLastTxMeInstance != nil {
1659 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1660 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1661 // to satisfy StaticCodeAnalysis I had to move the small processing into a separate method :-(
1662 switch oFsm.pLastTxMeInstance.GetName() {
1663 case "VlanTaggingFilterData", "MulticastOperationsProfile",
1664 "MulticastSubscriberConfigInfo", "MacBridgePortConfigurationData",
1665 "ExtendedVlanTaggingOperationConfigurationData":
1666 {
1667 oFsm.mutexPLastTxMeInstance.RUnlock()
1668 if oFsm.pAdaptFsm.pFsm.Current() == vlanStConfigVtfd {
1669 // Only if CreateResponse is received from first flow entry - let the FSM proceed ...
1670 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigVtfd)
1671 } else { // let the MultiEntity config proceed by stopping the wait function
1672 oFsm.omciMIdsResponseReceived <- true
1673 }
1674 return nil
1675 }
1676 default:
1677 {
1678 logger.Warnw(ctx, "Unsupported ME name received!",
1679 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00001680 }
1681 }
1682 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001683 } else {
1684 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00001685 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001686 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00001687 return nil
1688}
1689
dbainbri4d3a0dc2020-12-02 00:33:42 +00001690func (oFsm *UniVlanConfigFsm) handleOmciDeleteResponseMessage(ctx context.Context, apOmciPacket *gp.Packet) error {
mpagenko01e726e2020-10-23 09:45:29 +00001691 msgLayer := (*apOmciPacket).Layer(omci.LayerTypeDeleteResponse)
1692 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001693 logger.Errorw(ctx, "UniVlanConfigFsm - Omci Msg layer could not be detected for DeleteResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001694 log.Fields{"device-id": oFsm.deviceID})
1695 return fmt.Errorf("omci msg layer could not be detected for DeleteResponse for device-id %x",
1696 oFsm.deviceID)
1697 }
1698 msgObj, msgOk := msgLayer.(*omci.DeleteResponse)
1699 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001700 logger.Errorw(ctx, "UniVlanConfigFsm - Omci Msg layer could not be assigned for DeleteResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001701 log.Fields{"device-id": oFsm.deviceID})
1702 return fmt.Errorf("omci msg layer could not be assigned for DeleteResponse for device-id %x",
1703 oFsm.deviceID)
1704 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001705 logger.Debugw(ctx, "UniVlanConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenko01e726e2020-10-23 09:45:29 +00001706 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001707 logger.Errorw(ctx, "UniVlanConfigFsm - Omci DeleteResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00001708 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
1709 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
1710 return fmt.Errorf("omci DeleteResponse Error for device-id %x",
1711 oFsm.deviceID)
1712 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001713 oFsm.mutexPLastTxMeInstance.RLock()
1714 if oFsm.pLastTxMeInstance != nil {
1715 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1716 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1717 switch oFsm.pLastTxMeInstance.GetName() {
1718 case "VlanTaggingFilterData", "ExtendedVlanTaggingOperationConfigurationData":
1719 { // let the MultiEntity config proceed by stopping the wait function
1720 oFsm.mutexPLastTxMeInstance.RUnlock()
1721 oFsm.omciMIdsResponseReceived <- true
1722 return nil
1723 }
1724 default:
1725 {
1726 logger.Warnw(ctx, "Unsupported ME name received!",
1727 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1728 }
mpagenko01e726e2020-10-23 09:45:29 +00001729 }
1730 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001731 } else {
1732 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00001733 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001734 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00001735 return nil
1736}
1737
dbainbri4d3a0dc2020-12-02 00:33:42 +00001738func (oFsm *UniVlanConfigFsm) performConfigEvtocdEntries(ctx context.Context, aFlowEntryNo uint8) error {
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001739 if aFlowEntryNo == 0 {
1740 // EthType set only at first flow element
mpagenkodff5dda2020-08-28 11:52:01 +00001741 // EVTOCD ME is expected to exist at this point already from MIB-Download (with AssociationType/Pointer)
1742 // we need to extend the configuration by EthType definition and, to be sure, downstream 'inverse' mode
dbainbri4d3a0dc2020-12-02 00:33:42 +00001743 logger.Debugw(ctx, "UniVlanConfigFsm Tx Create::EVTOCD", log.Fields{
mpagenkodff5dda2020-08-28 11:52:01 +00001744 "EntitytId": strconv.FormatInt(int64(oFsm.evtocdID), 16),
1745 "i/oEthType": strconv.FormatInt(int64(cDefaultTpid), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001746 "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001747 associationType := 2 // default to uniPPTP
1748 if oFsm.pOnuUniPort.portType == uniVEIP {
1749 associationType = 10
1750 }
1751 // Create the EVTOCD ME
mpagenkodff5dda2020-08-28 11:52:01 +00001752 meParams := me.ParamData{
1753 EntityID: oFsm.evtocdID,
1754 Attributes: me.AttributeValueMap{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001755 "AssociationType": uint8(associationType),
1756 "AssociatedMePointer": oFsm.pOnuUniPort.entityID,
mpagenkodff5dda2020-08-28 11:52:01 +00001757 },
1758 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001759 oFsm.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001760 meInstance, err := oFsm.pOmciCC.sendCreateEvtocdVar(context.TODO(), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout,
1761 true, oFsm.pAdaptFsm.commChan, meParams)
1762 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001763 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001764 logger.Errorw(ctx, "CreateEvtocdVar create failed, aborting UniVlanConfigFsm!",
1765 log.Fields{"device-id": oFsm.deviceID})
1766 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1767 return fmt.Errorf("evtocd instance create failed %s, error %s", oFsm.deviceID, err)
1768 }
mpagenkodff5dda2020-08-28 11:52:01 +00001769 //accept also nil as (error) return value for writing to LastTx
1770 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001771 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001772 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001773
1774 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001775 err = oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00001776 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001777 logger.Errorw(ctx, "Evtocd create failed, aborting VlanConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001778 log.Fields{"device-id": oFsm.deviceID})
1779 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1780 return fmt.Errorf("evtocd create failed %s, error %s", oFsm.deviceID, err)
1781 }
1782
1783 // Set the EVTOCD ME default params
1784 meParams = me.ParamData{
1785 EntityID: oFsm.evtocdID,
1786 Attributes: me.AttributeValueMap{
1787 "InputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base
1788 "OutputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base
1789 "DownstreamMode": uint8(cDefaultDownstreamMode),
1790 },
1791 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001792 oFsm.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001793 meInstance, err = oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
1794 oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001795 oFsm.pAdaptFsm.commChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001796 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001797 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001798 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
1799 log.Fields{"device-id": oFsm.deviceID})
1800 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1801 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
1802 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001803 //accept also nil as (error) return value for writing to LastTx
1804 // - this avoids misinterpretation of new received OMCI messages
1805 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001806 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001807
1808 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001809 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001810 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001811 logger.Errorw(ctx, "Evtocd set TPID failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001812 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301813 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001814 return fmt.Errorf("evtocd set TPID failed %s, error %s", oFsm.deviceID, err)
mpagenkodff5dda2020-08-28 11:52:01 +00001815 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001816 } //first flow element
mpagenkodff5dda2020-08-28 11:52:01 +00001817
mpagenko551a4d42020-12-08 18:09:20 +00001818 oFsm.mutexFlowParams.RLock()
mpagenko9a304ea2020-12-16 15:54:01 +00001819 if oFsm.actualUniVlanConfigRule.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
mpagenkodff5dda2020-08-28 11:52:01 +00001820 //transparent transmission required
mpagenko551a4d42020-12-08 18:09:20 +00001821 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001822 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD single tagged transparent rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001823 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001824 sliceEvtocdRule := make([]uint8, 16)
1825 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
1826 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
1827 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
1828 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
1829 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
1830
1831 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
1832 cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule
1833 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
1834 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
1835 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
1836
1837 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
1838 0<<cTreatTTROffset| // Do not pop any tags
1839 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
1840 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
1841 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
1842
1843 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
1844 cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag
1845 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
1846 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
1847
1848 meParams := me.ParamData{
1849 EntityID: oFsm.evtocdID,
1850 Attributes: me.AttributeValueMap{
1851 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
1852 },
1853 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001854 oFsm.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001855 meInstance, err := oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
1856 oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true,
mpagenkodff5dda2020-08-28 11:52:01 +00001857 oFsm.pAdaptFsm.commChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001858 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001859 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001860 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
1861 log.Fields{"device-id": oFsm.deviceID})
1862 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1863 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
1864 }
mpagenkodff5dda2020-08-28 11:52:01 +00001865 //accept also nil as (error) return value for writing to LastTx
1866 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001867 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001868 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001869
1870 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001871 err = oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00001872 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001873 logger.Errorw(ctx, "Evtocd set transparent singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001874 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301875 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001876 return fmt.Errorf("evtocd set transparent singletagged rule failed %s, error %s", oFsm.deviceID, err)
1877
mpagenkodff5dda2020-08-28 11:52:01 +00001878 }
1879 } else {
1880 // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario
1881 if oFsm.acceptIncrementalEvtoOption {
mpagenko9a304ea2020-12-16 15:54:01 +00001882 matchPcp := oFsm.actualUniVlanConfigRule.MatchPcp
1883 matchVid := oFsm.actualUniVlanConfigRule.MatchVid
1884 setPcp := oFsm.actualUniVlanConfigRule.SetPcp
1885 setVid := oFsm.actualUniVlanConfigRule.SetVid
mpagenkodff5dda2020-08-28 11:52:01 +00001886 // this defines VID translation scenario: singletagged->singletagged (if not transparent)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001887 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD single tagged translation rule", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001888 "match-pcp": matchPcp, "match-vid": matchVid, "set-pcp": setPcp, "set-vid:": setVid, "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001889 sliceEvtocdRule := make([]uint8, 16)
1890 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
1891 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
1892 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
1893 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
1894 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
1895
1896 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
mpagenko9a304ea2020-12-16 15:54:01 +00001897 oFsm.actualUniVlanConfigRule.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN
1898 oFsm.actualUniVlanConfigRule.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID
mpagenkodff5dda2020-08-28 11:52:01 +00001899 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
1900 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
1901
1902 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
mpagenko9a304ea2020-12-16 15:54:01 +00001903 oFsm.actualUniVlanConfigRule.TagsToRemove<<cTreatTTROffset| // either 1 or 0
mpagenkodff5dda2020-08-28 11:52:01 +00001904 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
1905 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
1906 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
1907
1908 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
mpagenko9a304ea2020-12-16 15:54:01 +00001909 oFsm.actualUniVlanConfigRule.SetPcp<<cTreatPrioOffset| // as configured in flow
1910 oFsm.actualUniVlanConfigRule.SetVid<<cTreatVidOffset| //as configured in flow
mpagenkodff5dda2020-08-28 11:52:01 +00001911 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
mpagenko551a4d42020-12-08 18:09:20 +00001912 oFsm.mutexFlowParams.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001913
1914 meParams := me.ParamData{
1915 EntityID: oFsm.evtocdID,
1916 Attributes: me.AttributeValueMap{
1917 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
1918 },
1919 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001920 oFsm.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001921 meInstance, err := oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx),
1922 oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true,
mpagenkodff5dda2020-08-28 11:52:01 +00001923 oFsm.pAdaptFsm.commChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001924 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001925 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +03001926 logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
1927 log.Fields{"device-id": oFsm.deviceID})
1928 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1929 return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err)
1930 }
mpagenkodff5dda2020-08-28 11:52:01 +00001931 //accept also nil as (error) return value for writing to LastTx
1932 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001933 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000