blob: 86316cce8dfe169fd2ec9bd83f6a558b5e989549 [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 (
46 // bit mask offsets for EVTOCD VlanTaggingOperationTable related to 32 bits (4 bytes)
47 cFilterPrioOffset = 28
48 cFilterVidOffset = 15
49 cFilterTpidOffset = 12
50 cFilterEtherTypeOffset = 0
51 cTreatTTROffset = 30
52 cTreatPrioOffset = 16
53 cTreatVidOffset = 3
54 cTreatTpidOffset = 0
55)
56const (
57 // byte offsets for EVTOCD VlanTaggingOperationTable related to overall 16 byte size with slice byte 0 as first Byte (MSB)
58 cFilterOuterOffset = 0
59 cFilterInnerOffset = 4
60 cTreatOuterOffset = 8
61 cTreatInnerOffset = 12
62)
63const (
64 // basic values used within EVTOCD VlanTaggingOperationTable in respect to their bitfields
65 cPrioIgnoreTag uint32 = 15
66 cPrioDefaultFilter uint32 = 14
67 cPrioDoNotFilter uint32 = 8
68 cDoNotFilterVid uint32 = 4096
69 cDoNotFilterTPID uint32 = 0
70 cDoNotFilterEtherType uint32 = 0
71 cDoNotAddPrio uint32 = 15
72 cCopyPrioFromInner uint32 = 8
Himani Chawla4d908332020-08-31 12:30:20 +053073 //cDontCarePrio uint32 = 0
mpagenkodff5dda2020-08-28 11:52:01 +000074 cDontCareVid uint32 = 0
75 cDontCareTpid uint32 = 0
76 cSetOutputTpidCopyDei uint32 = 4
77)
78
79const (
80 // events of config PON ANI port FSM
mpagenko01e726e2020-10-23 09:45:29 +000081 vlanEvStart = "vlanEvStart"
82 vlanEvWaitTechProf = "vlanEvWaitTechProf"
83 vlanEvContinueConfig = "vlanEvContinueConfig"
84 vlanEvStartConfig = "vlanEvStartConfig"
85 vlanEvRxConfigVtfd = "vlanEvRxConfigVtfd"
86 vlanEvRxConfigEvtocd = "vlanEvRxConfigEvtocd"
mpagenko551a4d42020-12-08 18:09:20 +000087 vlanEvWaitTPIncr = "vlanEvWaitTPIncr"
mpagenko01e726e2020-10-23 09:45:29 +000088 vlanEvIncrFlowConfig = "vlanEvIncrFlowConfig"
mpagenkofc4f56e2020-11-04 17:17:49 +000089 vlanEvRenew = "vlanEvRenew"
mpagenko01e726e2020-10-23 09:45:29 +000090 vlanEvRemFlowConfig = "vlanEvRemFlowConfig"
91 vlanEvRemFlowDone = "vlanEvRemFlowDone"
92 vlanEvFlowDataRemoved = "vlanEvFlowDataRemoved"
Holger Hildebrandt394c5522020-09-11 11:23:01 +000093 //vlanEvTimeoutSimple = "vlanEvTimeoutSimple"
94 //vlanEvTimeoutMids = "vlanEvTimeoutMids"
Himani Chawla4d908332020-08-31 12:30:20 +053095 vlanEvReset = "vlanEvReset"
96 vlanEvRestart = "vlanEvRestart"
mpagenkodff5dda2020-08-28 11:52:01 +000097)
mpagenko01e726e2020-10-23 09:45:29 +000098
mpagenkodff5dda2020-08-28 11:52:01 +000099const (
100 // states of config PON ANI port FSM
101 vlanStDisabled = "vlanStDisabled"
102 vlanStStarting = "vlanStStarting"
103 vlanStWaitingTechProf = "vlanStWaitingTechProf"
104 vlanStConfigVtfd = "vlanStConfigVtfd"
105 vlanStConfigEvtocd = "vlanStConfigEvtocd"
106 vlanStConfigDone = "vlanStConfigDone"
mpagenko551a4d42020-12-08 18:09:20 +0000107 vlanStIncrFlowWaitTP = "vlanStIncrFlowWaitTP"
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000108 vlanStConfigIncrFlow = "vlanStConfigIncrFlow"
mpagenko01e726e2020-10-23 09:45:29 +0000109 vlanStRemoveFlow = "vlanStRemoveFlow"
mpagenkodff5dda2020-08-28 11:52:01 +0000110 vlanStCleanupDone = "vlanStCleanupDone"
111 vlanStResetting = "vlanStResetting"
112)
113
mpagenko01e726e2020-10-23 09:45:29 +0000114type uniVlanRuleParams struct {
mpagenko551a4d42020-12-08 18:09:20 +0000115 TpID uint8 `json:"tp_id"`
mpagenko01e726e2020-10-23 09:45:29 +0000116 MatchVid uint32 `json:"match_vid"` //use uint32 types for allowing immediate bitshifting
117 MatchPcp uint32 `json:"match_pcp"`
118 TagsToRemove uint32 `json:"tags_to_remove"`
119 SetVid uint32 `json:"set_vid"`
120 SetPcp uint32 `json:"set_pcp"`
121}
122
123type uniVlanFlowParams struct {
124 CookieSlice []uint64 `json:"cookie_slice"`
125 VlanRuleParams uniVlanRuleParams `json:"vlan_rule_params"`
126}
127
128type uniRemoveVlanFlowParams struct {
129 cookie uint64 //just the last cookie valid for removal
130 vlanRuleParams uniVlanRuleParams
131}
132
mpagenkodff5dda2020-08-28 11:52:01 +0000133//UniVlanConfigFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI
134type UniVlanConfigFsm struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530135 pDeviceHandler *deviceHandler
mpagenko01e726e2020-10-23 09:45:29 +0000136 deviceID string
Himani Chawla6d2ae152020-09-02 13:11:20 +0530137 pOmciCC *omciCC
138 pOnuUniPort *onuUniPort
139 pUniTechProf *onuUniTechProf
140 pOnuDB *onuDeviceDB
mpagenkodff5dda2020-08-28 11:52:01 +0000141 requestEvent OnuDeviceEvent
142 omciMIdsResponseReceived chan bool //seperate channel needed for checking multiInstance OMCI message responses
143 pAdaptFsm *AdapterFsm
144 acceptIncrementalEvtoOption bool
mpagenko2418ab02020-11-12 12:58:06 +0000145 clearPersistency bool
mpagenko551a4d42020-12-08 18:09:20 +0000146 mutexFlowParams sync.RWMutex
mpagenko9a304ea2020-12-16 15:54:01 +0000147 actualUniVlanConfigRule uniVlanRuleParams
mpagenko01e726e2020-10-23 09:45:29 +0000148 uniVlanFlowParamsSlice []uniVlanFlowParams
149 uniRemoveFlowsSlice []uniRemoveVlanFlowParams
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000150 numUniFlows uint8 // expected number of flows should be less than 12
151 configuredUniFlow uint8
mpagenko01e726e2020-10-23 09:45:29 +0000152 numRemoveFlows uint8
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000153 numVlanFilterEntries uint8
mpagenko01e726e2020-10-23 09:45:29 +0000154 vlanFilterList [cVtfdTableSize]uint16
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000155 evtocdID uint16
mpagenko01e726e2020-10-23 09:45:29 +0000156 pLastTxMeInstance *me.ManagedEntity
mpagenkofc4f56e2020-11-04 17:17:49 +0000157 requestEventOffset uint8
mpagenko551a4d42020-12-08 18:09:20 +0000158 TpIDWaitingFor uint8
mpagenkodff5dda2020-08-28 11:52:01 +0000159}
160
mpagenko01e726e2020-10-23 09:45:29 +0000161//NewUniVlanConfigFsm is the 'constructor' for the state machine to config the PON ANI ports
162// of ONU UNI ports via OMCI
dbainbri4d3a0dc2020-12-02 00:33:42 +0000163func NewUniVlanConfigFsm(ctx context.Context, apDeviceHandler *deviceHandler, apDevOmciCC *omciCC, apUniPort *onuUniPort,
mpagenko551a4d42020-12-08 18:09:20 +0000164 apUniTechProf *onuUniTechProf, apOnuDB *onuDeviceDB, aTechProfileID uint8,
mpagenko01e726e2020-10-23 09:45:29 +0000165 aRequestEvent OnuDeviceEvent, aName string, aCommChannel chan Message, aAcceptIncrementalEvto bool,
166 aCookieSlice []uint64, aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) *UniVlanConfigFsm {
mpagenkodff5dda2020-08-28 11:52:01 +0000167 instFsm := &UniVlanConfigFsm{
168 pDeviceHandler: apDeviceHandler,
mpagenko01e726e2020-10-23 09:45:29 +0000169 deviceID: apDeviceHandler.deviceID,
mpagenkodff5dda2020-08-28 11:52:01 +0000170 pOmciCC: apDevOmciCC,
171 pOnuUniPort: apUniPort,
172 pUniTechProf: apUniTechProf,
173 pOnuDB: apOnuDB,
mpagenkodff5dda2020-08-28 11:52:01 +0000174 requestEvent: aRequestEvent,
175 acceptIncrementalEvtoOption: aAcceptIncrementalEvto,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000176 numUniFlows: 0,
177 configuredUniFlow: 0,
mpagenko01e726e2020-10-23 09:45:29 +0000178 numRemoveFlows: 0,
mpagenko2418ab02020-11-12 12:58:06 +0000179 clearPersistency: true,
mpagenkodff5dda2020-08-28 11:52:01 +0000180 }
181
mpagenko01e726e2020-10-23 09:45:29 +0000182 instFsm.pAdaptFsm = NewAdapterFsm(aName, instFsm.deviceID, aCommChannel)
mpagenkodff5dda2020-08-28 11:52:01 +0000183 if instFsm.pAdaptFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000184 logger.Errorw(ctx, "UniVlanConfigFsm's AdapterFsm could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000185 "device-id": instFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000186 return nil
187 }
mpagenkodff5dda2020-08-28 11:52:01 +0000188 instFsm.pAdaptFsm.pFsm = fsm.NewFSM(
189 vlanStDisabled,
190 fsm.Events{
191 {Name: vlanEvStart, Src: []string{vlanStDisabled}, Dst: vlanStStarting},
192 {Name: vlanEvWaitTechProf, Src: []string{vlanStStarting}, Dst: vlanStWaitingTechProf},
193 {Name: vlanEvContinueConfig, Src: []string{vlanStWaitingTechProf}, Dst: vlanStConfigVtfd},
194 {Name: vlanEvStartConfig, Src: []string{vlanStStarting}, Dst: vlanStConfigVtfd},
195 {Name: vlanEvRxConfigVtfd, Src: []string{vlanStConfigVtfd}, Dst: vlanStConfigEvtocd},
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000196 {Name: vlanEvRxConfigEvtocd, Src: []string{vlanStConfigEvtocd, vlanStConfigIncrFlow},
197 Dst: vlanStConfigDone},
mpagenko551a4d42020-12-08 18:09:20 +0000198 {Name: vlanEvRenew, Src: []string{vlanStConfigDone}, Dst: vlanStStarting},
199 {Name: vlanEvWaitTPIncr, Src: []string{vlanStConfigDone}, Dst: vlanStIncrFlowWaitTP},
200 {Name: vlanEvIncrFlowConfig, Src: []string{vlanStConfigDone, vlanStIncrFlowWaitTP},
201 Dst: vlanStConfigIncrFlow},
mpagenko01e726e2020-10-23 09:45:29 +0000202 {Name: vlanEvRemFlowConfig, Src: []string{vlanStConfigDone}, Dst: vlanStRemoveFlow},
203 {Name: vlanEvRemFlowDone, Src: []string{vlanStRemoveFlow}, Dst: vlanStCleanupDone},
204 {Name: vlanEvFlowDataRemoved, Src: []string{vlanStCleanupDone}, Dst: vlanStConfigDone},
mpagenkodff5dda2020-08-28 11:52:01 +0000205 /*
206 {Name: vlanEvTimeoutSimple, Src: []string{
207 vlanStCreatingDot1PMapper, vlanStCreatingMBPCD, vlanStSettingTconts, vlanStSettingDot1PMapper}, Dst: vlanStStarting},
208 {Name: vlanEvTimeoutMids, Src: []string{
209 vlanStCreatingGemNCTPs, vlanStCreatingGemIWs, vlanStSettingPQs}, Dst: vlanStStarting},
210 */
211 // exceptional treatment for all states except vlanStResetting
212 {Name: vlanEvReset, Src: []string{vlanStStarting, vlanStWaitingTechProf,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000213 vlanStConfigVtfd, vlanStConfigEvtocd, vlanStConfigDone, vlanStConfigIncrFlow,
mpagenko01e726e2020-10-23 09:45:29 +0000214 vlanStRemoveFlow, vlanStCleanupDone},
mpagenkodff5dda2020-08-28 11:52:01 +0000215 Dst: vlanStResetting},
216 // the only way to get to resource-cleared disabled state again is via "resseting"
217 {Name: vlanEvRestart, Src: []string{vlanStResetting}, Dst: vlanStDisabled},
218 },
mpagenkodff5dda2020-08-28 11:52:01 +0000219 fsm.Callbacks{
dbainbri4d3a0dc2020-12-02 00:33:42 +0000220 "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(ctx, e) },
221 "enter_" + vlanStStarting: func(e *fsm.Event) { instFsm.enterConfigStarting(ctx, e) },
222 "enter_" + vlanStConfigVtfd: func(e *fsm.Event) { instFsm.enterConfigVtfd(ctx, e) },
223 "enter_" + vlanStConfigEvtocd: func(e *fsm.Event) { instFsm.enterConfigEvtocd(ctx, e) },
224 "enter_" + vlanStConfigDone: func(e *fsm.Event) { instFsm.enterVlanConfigDone(ctx, e) },
225 "enter_" + vlanStConfigIncrFlow: func(e *fsm.Event) { instFsm.enterConfigIncrFlow(ctx, e) },
226 "enter_" + vlanStRemoveFlow: func(e *fsm.Event) { instFsm.enterRemoveFlow(ctx, e) },
227 "enter_" + vlanStCleanupDone: func(e *fsm.Event) { instFsm.enterVlanCleanupDone(ctx, e) },
228 "enter_" + vlanStResetting: func(e *fsm.Event) { instFsm.enterResetting(ctx, e) },
229 "enter_" + vlanStDisabled: func(e *fsm.Event) { instFsm.enterDisabled(ctx, e) },
mpagenkodff5dda2020-08-28 11:52:01 +0000230 },
231 )
232 if instFsm.pAdaptFsm.pFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000233 logger.Errorw(ctx, "UniVlanConfigFsm's Base FSM could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000234 "device-id": instFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000235 return nil
236 }
237
dbainbri4d3a0dc2020-12-02 00:33:42 +0000238 _ = instFsm.initUniFlowParams(ctx, aTechProfileID, aCookieSlice, aMatchVlan, aSetVlan, aSetPcp)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000239
dbainbri4d3a0dc2020-12-02 00:33:42 +0000240 logger.Debugw(ctx, "UniVlanConfigFsm created", log.Fields{"device-id": instFsm.deviceID,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000241 "accIncrEvto": instFsm.acceptIncrementalEvtoOption})
mpagenkodff5dda2020-08-28 11:52:01 +0000242 return instFsm
243}
244
mpagenko01e726e2020-10-23 09:45:29 +0000245//initUniFlowParams is a simplified form of SetUniFlowParams() used for first flow parameters configuration
mpagenko551a4d42020-12-08 18:09:20 +0000246func (oFsm *UniVlanConfigFsm) initUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64,
mpagenko01e726e2020-10-23 09:45:29 +0000247 aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) error {
248 loRuleParams := uniVlanRuleParams{
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000249 TpID: aTpID,
250 MatchVid: uint32(aMatchVlan),
251 SetVid: uint32(aSetVlan),
252 SetPcp: uint32(aSetPcp),
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000253 }
254 // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters
mpagenko01e726e2020-10-23 09:45:29 +0000255 loRuleParams.TagsToRemove = 1 //one tag to remove as default setting
256 loRuleParams.MatchPcp = cPrioDoNotFilter // do not Filter on prio as default
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000257
mpagenko01e726e2020-10-23 09:45:29 +0000258 if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000259 //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 +0000260 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000261 //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther)
262 } else {
263 if !oFsm.acceptIncrementalEvtoOption {
264 //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 +0000265 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000266 }
267 }
268
mpagenko01e726e2020-10-23 09:45:29 +0000269 if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000270 // no prio/vid filtering requested
mpagenko01e726e2020-10-23 09:45:29 +0000271 loRuleParams.TagsToRemove = 0 //no tag pop action
272 loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering
273 if loRuleParams.SetPcp == cCopyPrioFromInner {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000274 //in case of no filtering and configured PrioCopy ensure default prio setting to 0
275 // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged
276 // might collide with NoMatchVid/CopyPrio(/setVid) setting
277 // this was some precondition setting taken over from py adapter ..
mpagenko01e726e2020-10-23 09:45:29 +0000278 loRuleParams.SetPcp = 0
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000279 }
280 }
mpagenko01e726e2020-10-23 09:45:29 +0000281
282 loFlowParams := uniVlanFlowParams{VlanRuleParams: loRuleParams}
283 loFlowParams.CookieSlice = make([]uint64, 0)
284 loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...)
285
286 //no mutex protection is required for initial access and adding the first flow is always possible
287 oFsm.uniVlanFlowParamsSlice = make([]uniVlanFlowParams, 0)
288 oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000289 logger.Debugw(ctx, "first UniVlanConfigFsm flow added", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000290 "Cookies": oFsm.uniVlanFlowParamsSlice[0].CookieSlice,
291 "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16),
292 "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
293 "SetPcp": loRuleParams.SetPcp,
294 "device-id": oFsm.deviceID})
295 oFsm.numUniFlows = 1
296 oFsm.uniRemoveFlowsSlice = make([]uniRemoveVlanFlowParams, 0) //initially nothing to remove
297
298 //permanently store flow config for reconcile case
dbainbri4d3a0dc2020-12-02 00:33:42 +0000299 if err := oFsm.pDeviceHandler.storePersUniFlowConfig(ctx, oFsm.pOnuUniPort.uniID,
mpagenko01e726e2020-10-23 09:45:29 +0000300 &oFsm.uniVlanFlowParamsSlice); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000301 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +0000302 return err
303 }
304
305 return nil
306}
307
mpagenko551a4d42020-12-08 18:09:20 +0000308//GetWaitingTpID returns the TpId that the FSM might be waiting for continuation (0 if none)
309func (oFsm *UniVlanConfigFsm) GetWaitingTpID() uint8 {
310 //mutex protection is required for possible concurrent access to FSM members
311 oFsm.mutexFlowParams.RLock()
312 defer oFsm.mutexFlowParams.RUnlock()
313 return oFsm.TpIDWaitingFor
314}
315
mpagenko2418ab02020-11-12 12:58:06 +0000316//RequestClearPersistency sets the internal flag to not clear persistency data (false=NoClear)
317func (oFsm *UniVlanConfigFsm) RequestClearPersistency(aClear bool) {
318 //mutex protection is required for possible concurrent access to FSM members
mpagenko551a4d42020-12-08 18:09:20 +0000319 oFsm.mutexFlowParams.RLock()
320 defer oFsm.mutexFlowParams.RUnlock()
mpagenko2418ab02020-11-12 12:58:06 +0000321 oFsm.clearPersistency = aClear
322}
323
mpagenko01e726e2020-10-23 09:45:29 +0000324//SetUniFlowParams verifies on existence of flow parameters to be configured,
325// optionally udates the cookie list or appends a new flow if there is space
326// if possible the FSM is trigggerd to start with the processing
mpagenko551a4d42020-12-08 18:09:20 +0000327// ignore complexity by now
328// nolint: gocyclo
329func (oFsm *UniVlanConfigFsm) SetUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64,
mpagenko01e726e2020-10-23 09:45:29 +0000330 aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) error {
331 loRuleParams := uniVlanRuleParams{
332 TpID: aTpID,
333 MatchVid: uint32(aMatchVlan),
334 SetVid: uint32(aSetVlan),
335 SetPcp: uint32(aSetPcp),
336 }
337 // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters
338 loRuleParams.TagsToRemove = 1 //one tag to remove as default setting
339 loRuleParams.MatchPcp = cPrioDoNotFilter // do not Filter on prio as default
340
341 if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
342 //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries
343 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
344 //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther)
345 } else {
346 if !oFsm.acceptIncrementalEvtoOption {
347 //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries
348 loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT)
349 }
350 }
351
352 if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
353 // no prio/vid filtering requested
354 loRuleParams.TagsToRemove = 0 //no tag pop action
355 loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering
356 if loRuleParams.SetPcp == cCopyPrioFromInner {
357 //in case of no filtering and configured PrioCopy ensure default prio setting to 0
358 // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged
359 // might collide with NoMatchVid/CopyPrio(/setVid) setting
360 // this was some precondition setting taken over from py adapter ..
361 loRuleParams.SetPcp = 0
362 }
363 }
364
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000365 flowEntryMatch := false
mpagenko01e726e2020-10-23 09:45:29 +0000366 flowCookieModify := false
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000367 //mutex protection is required for possible concurrent access to FSM members
368 oFsm.mutexFlowParams.Lock()
369 defer oFsm.mutexFlowParams.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +0000370 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
371 //TODO: Verify if using e.g. hashes for the structures here for comparison may generate
372 // countable run time optimization (perhaps with including the hash in kvStore storage?)
373 if storedUniFlowParams.VlanRuleParams == loRuleParams {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000374 flowEntryMatch = true
dbainbri4d3a0dc2020-12-02 00:33:42 +0000375 logger.Debugw(ctx, "UniVlanConfigFsm flow setting - rule already exists", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000376 "device-id": oFsm.deviceID})
377 var cookieMatch bool
378 for _, newCookie := range aCookieSlice { // for all cookies available in the arguments
379 cookieMatch = false
380 for _, cookie := range storedUniFlowParams.CookieSlice {
381 if cookie == newCookie {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000382 logger.Debugw(ctx, "UniVlanConfigFsm flow setting - and cookie already exists", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000383 "device-id": oFsm.deviceID, "cookie": cookie})
384 cookieMatch = true
385 break //found new cookie - no further search for this requested cookie
386 }
387 }
388 if !cookieMatch {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000389 logger.Debugw(ctx, "UniVlanConfigFsm flow setting -adding new cookie", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000390 "device-id": oFsm.deviceID, "cookie": newCookie})
391 //as range works with copies of the slice we have to write to the original slice!!
392 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(oFsm.uniVlanFlowParamsSlice[flow].CookieSlice,
393 newCookie)
394 flowCookieModify = true
395 }
396 } //for all new cookies
397 break // found rule - no further rule search
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000398 }
399 }
mpagenko01e726e2020-10-23 09:45:29 +0000400 if !flowEntryMatch { //it is a new rule
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000401 if oFsm.numUniFlows < cMaxAllowedFlows {
mpagenko01e726e2020-10-23 09:45:29 +0000402 loFlowParams := uniVlanFlowParams{VlanRuleParams: loRuleParams}
403 loFlowParams.CookieSlice = make([]uint64, 0)
404 loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...)
405 oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000406 logger.Debugw(ctx, "UniVlanConfigFsm flow add", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000407 "Cookies": oFsm.uniVlanFlowParamsSlice[oFsm.numUniFlows].CookieSlice,
408 "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16),
409 "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
Girish Gowdra041dcb32020-11-16 16:54:30 -0800410 "SetPcp": loRuleParams.SetPcp, "numberofFlows": oFsm.numUniFlows + 1,
mpagenko01e726e2020-10-23 09:45:29 +0000411 "device-id": oFsm.deviceID})
412
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000413 oFsm.numUniFlows++
mpagenko01e726e2020-10-23 09:45:29 +0000414 // note: theoretical it would be possible to clear the same rule from the remove slice
415 // (for entries that have not yet been started with removal)
416 // but that is getting quite complicated - maybe a future optimization in case it should prove reasonable
417 // 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 +0000418
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000419 pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm
420 if pConfigVlanStateBaseFsm.Is(vlanStConfigDone) {
421 //have to re-trigger the FSM to proceed with outstanding incremental flow configuration
mpagenko551a4d42020-12-08 18:09:20 +0000422 if oFsm.configuredUniFlow == 0 {
423 // this is a restart with a complete new flow, we can re-use the initial flow config control
424 // including the check, if the related techProfile is (still) available (probably also removed in between)
mpagenko9a304ea2020-12-16 15:54:01 +0000425 // Can't call FSM Event directly, decoupling it
mpagenko551a4d42020-12-08 18:09:20 +0000426 go func(a_pBaseFsm *fsm.FSM) {
427 _ = a_pBaseFsm.Event(vlanEvRenew)
428 }(pConfigVlanStateBaseFsm)
429 } else {
430 //some further flows are to be configured
mpagenko9a304ea2020-12-16 15:54:01 +0000431 //store the actual rule that shall be worked upon in the following transient states
432 oFsm.actualUniVlanConfigRule = oFsm.uniVlanFlowParamsSlice[oFsm.configuredUniFlow].VlanRuleParams
mpagenko551a4d42020-12-08 18:09:20 +0000433 //tpId of the next rule to be configured
mpagenko9a304ea2020-12-16 15:54:01 +0000434 tpID := oFsm.actualUniVlanConfigRule.TpID
mpagenko551a4d42020-12-08 18:09:20 +0000435 loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.uniID, tpID)
436 oFsm.TpIDWaitingFor = tpID
mpagenko9a304ea2020-12-16 15:54:01 +0000437 logger.Debugw(ctx, "UniVlanConfigFsm - incremental config request (on setConfig)", log.Fields{
438 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID,
439 "set-Vlan": oFsm.actualUniVlanConfigRule.SetVid, "tp-id": tpID, "ProfDone": loTechProfDone})
440
mpagenko551a4d42020-12-08 18:09:20 +0000441 go func(aPBaseFsm *fsm.FSM, aTechProfDone bool) {
442 if aTechProfDone {
443 // let the vlan processing continue with next rule
444 _ = aPBaseFsm.Event(vlanEvIncrFlowConfig)
445 } else {
446 // set to waiting for Techprofile
447 _ = aPBaseFsm.Event(vlanEvWaitTPIncr)
448 }
449 }(pConfigVlanStateBaseFsm, loTechProfDone)
450 }
mpagenko01e726e2020-10-23 09:45:29 +0000451 } // if not in the appropriate state a new entry will be automatically considered later
452 // when the configDone state is reached
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000453 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000454 logger.Errorw(ctx, "UniVlanConfigFsm flow limit exceeded", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000455 "device-id": oFsm.deviceID, "flow-number": oFsm.numUniFlows})
456 return fmt.Errorf(" UniVlanConfigFsm flow limit exceeded %s", oFsm.deviceID)
457 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000458 } else {
459 // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately
460 if oFsm.numUniFlows == oFsm.configuredUniFlow {
461 //all requested rules really have been configured
462 // state transition notification is checked in deviceHandler
463 if oFsm.pDeviceHandler != nil {
464 //also the related TechProfile was already configured
dbainbri4d3a0dc2020-12-02 00:33:42 +0000465 logger.Debugw(ctx, "UniVlanConfigFsm rule already set - send immediate add-success event for reason update", log.Fields{
mpagenkofc4f56e2020-11-04 17:17:49 +0000466 "device-id": oFsm.deviceID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000467 go oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, oFsm.requestEvent)
mpagenkofc4f56e2020-11-04 17:17:49 +0000468 }
469 } else {
470 // avoid device reason update as the rule config connected to this flow may still be in progress
471 // and the device reason should only be updated on success of rule config
dbainbri4d3a0dc2020-12-02 00:33:42 +0000472 logger.Debugw(ctx, "UniVlanConfigFsm rule already set but configuration ongoing, suppress early add-success event for reason update",
mpagenkofc4f56e2020-11-04 17:17:49 +0000473 log.Fields{"device-id": oFsm.deviceID,
474 "NumberofRules": oFsm.numUniFlows, "Configured rules": oFsm.configuredUniFlow})
475 }
476 }
mpagenko01e726e2020-10-23 09:45:29 +0000477
478 if !flowEntryMatch || flowCookieModify { // some change was done to the flow entries
479 //permanently store flow config for reconcile case
dbainbri4d3a0dc2020-12-02 00:33:42 +0000480 if err := oFsm.pDeviceHandler.storePersUniFlowConfig(ctx, oFsm.pOnuUniPort.uniID, &oFsm.uniVlanFlowParamsSlice); err != nil {
481 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +0000482 return err
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000483 }
484 }
485 return nil
486}
487
mpagenko01e726e2020-10-23 09:45:29 +0000488//RemoveUniFlowParams verifies on existence of flow cookie,
489// if found removes cookie from flow cookie list and if this is empty
490// initiates removal of the flow related configuration from the ONU (via OMCI)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000491func (oFsm *UniVlanConfigFsm) RemoveUniFlowParams(ctx context.Context, aCookie uint64) error {
mpagenko01e726e2020-10-23 09:45:29 +0000492 flowCookieMatch := false
493 //mutex protection is required for possible concurrent access to FSM members
494 oFsm.mutexFlowParams.Lock()
495 defer oFsm.mutexFlowParams.Unlock()
496 for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
497 for i, cookie := range storedUniFlowParams.CookieSlice {
498 if cookie == aCookie {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000499 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - cookie found", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000500 "device-id": oFsm.deviceID, "cookie": cookie})
501 flowCookieMatch = true
502
503 //remove the cookie from the cookie slice and verify it is getting empty
504 if len(storedUniFlowParams.CookieSlice) == 1 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000505 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - full flow removal", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000506 "device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +0000507
508 //create a new element for the removeVlanFlow slice
509 loRemoveParams := uniRemoveVlanFlowParams{
510 vlanRuleParams: storedUniFlowParams.VlanRuleParams,
511 cookie: storedUniFlowParams.CookieSlice[0],
512 }
513 oFsm.uniRemoveFlowsSlice = append(oFsm.uniRemoveFlowsSlice, loRemoveParams)
514
515 //and remove the actual element from the addVlanFlow slice
516 // oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = nil //automatically done by garbage collector
517 if len(oFsm.uniVlanFlowParamsSlice) <= 1 {
518 oFsm.numUniFlows = 0 //no more flows
519 oFsm.configuredUniFlow = 0 //no more flows configured
520 oFsm.uniVlanFlowParamsSlice = nil //reset the slice
mpagenko2418ab02020-11-12 12:58:06 +0000521 //at this point it is evident that no flow anymore refers to a still possibly active Techprofile
522 //request that this profile gets deleted before a new flow add is allowed
mpagenko551a4d42020-12-08 18:09:20 +0000523 oFsm.pUniTechProf.setProfileToDelete(oFsm.pOnuUniPort.uniID, loRemoveParams.vlanRuleParams.TpID, true)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000524 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - no more flows", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000525 "device-id": oFsm.deviceID})
526 } else {
527 oFsm.numUniFlows--
528 if oFsm.configuredUniFlow > 0 {
529 oFsm.configuredUniFlow--
530 //TODO!! might be needed to consider still outstanding configure requests ..
531 // so a flow at removal might still not be configured !?!
532 }
mpagenko2418ab02020-11-12 12:58:06 +0000533 usedTpID := storedUniFlowParams.VlanRuleParams.TpID
mpagenko01e726e2020-10-23 09:45:29 +0000534 //cut off the requested flow by slicing out this element
535 oFsm.uniVlanFlowParamsSlice = append(
536 oFsm.uniVlanFlowParamsSlice[:flow], oFsm.uniVlanFlowParamsSlice[flow+1:]...)
mpagenko2418ab02020-11-12 12:58:06 +0000537 //here we have to check, if there are still other flows referencing to the actual ProfileId
538 // before we can request that this profile gets deleted before a new flow add is allowed
539 tpIDInOtherFlows := false
540 for _, tpUniFlowParams := range oFsm.uniVlanFlowParamsSlice {
541 if tpUniFlowParams.VlanRuleParams.TpID == usedTpID {
542 tpIDInOtherFlows = true
543 break // search loop can be left
544 }
545 }
546 if tpIDInOtherFlows {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000547 logger.Debugw(ctx, "UniVlanConfigFsm tp-id used in deleted flow is still used in other flows", log.Fields{
mpagenko2418ab02020-11-12 12:58:06 +0000548 "device-id": oFsm.deviceID, "tp-id": usedTpID})
549 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000550 logger.Debugw(ctx, "UniVlanConfigFsm tp-id used in deleted flow is not used anymore", log.Fields{
mpagenko2418ab02020-11-12 12:58:06 +0000551 "device-id": oFsm.deviceID, "tp-id": usedTpID})
552 //request that this profile gets deleted before a new flow add is allowed
mpagenko551a4d42020-12-08 18:09:20 +0000553 oFsm.pUniTechProf.setProfileToDelete(oFsm.pOnuUniPort.uniID, usedTpID, true)
mpagenko2418ab02020-11-12 12:58:06 +0000554 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000555 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - specific flow removed from data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000556 "device-id": oFsm.deviceID})
557 }
558 //trigger the FSM to remove the relevant rule
559 pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm
560 if pConfigVlanStateBaseFsm.Is(vlanStConfigDone) {
mpagenko9a304ea2020-12-16 15:54:01 +0000561 logger.Debugw(ctx, "UniVlanConfigFsm rule removal request", log.Fields{
562 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID,
563 "tp-id": loRemoveParams.vlanRuleParams.TpID,
564 "set-Vlan": loRemoveParams.vlanRuleParams.SetVid})
mpagenko01e726e2020-10-23 09:45:29 +0000565 //have to re-trigger the FSM to proceed with outstanding incremental flow configuration
mpagenko9a304ea2020-12-16 15:54:01 +0000566 // Can't call FSM Event directly, decoupling it
mpagenko01e726e2020-10-23 09:45:29 +0000567 go func(a_pBaseFsm *fsm.FSM) {
568 _ = a_pBaseFsm.Event(vlanEvRemFlowConfig)
569 }(pConfigVlanStateBaseFsm)
570 } // if not in the appropriate state a new entry will be automatically considered later
571 // when the configDone state is reached
572 } else {
mpagenko01e726e2020-10-23 09:45:29 +0000573 //cut off the requested cookie by slicing out this element
574 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(
575 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[:i],
576 oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[i+1:]...)
mpagenkofc4f56e2020-11-04 17:17:49 +0000577 // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately
578 // state transition notification is checked in deviceHandler
579 if oFsm.pDeviceHandler != nil {
580 //making use of the add->remove successor enum assumption/definition
dbainbri4d3a0dc2020-12-02 00:33:42 +0000581 go oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent(uint8(oFsm.requestEvent)+1))
mpagenkofc4f56e2020-11-04 17:17:49 +0000582 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000583 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - rule persists with still valid cookies", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000584 "device-id": oFsm.deviceID, "cookies": oFsm.uniVlanFlowParamsSlice[flow].CookieSlice})
585 }
586
587 //permanently store the modified flow config for reconcile case
mpagenkofc4f56e2020-11-04 17:17:49 +0000588 if oFsm.pDeviceHandler != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000589 if err := oFsm.pDeviceHandler.storePersUniFlowConfig(ctx, oFsm.pOnuUniPort.uniID, &oFsm.uniVlanFlowParamsSlice); err != nil {
590 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +0000591 return err
592 }
mpagenko01e726e2020-10-23 09:45:29 +0000593 }
594
595 break //found the cookie - no further search for this requested cookie
596 }
597 }
598 if flowCookieMatch { //cookie already found: no need for further search in other flows
599 break
600 }
601 } //search all flows
602 if !flowCookieMatch { //some cookie remove-request for a cookie that does not exist in the FSM data
dbainbri4d3a0dc2020-12-02 00:33:42 +0000603 logger.Warnw(ctx, "UniVlanConfigFsm flow removal - remove-cookie not found", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000604 "device-id": oFsm.deviceID, "remove-cookie": aCookie})
605 // but accept the request with success as no such cookie (flow) does exist
mpagenkofc4f56e2020-11-04 17:17:49 +0000606 // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately
607 // state transition notification is checked in deviceHandler
608 if oFsm.pDeviceHandler != nil {
609 //making use of the add->remove successor enum assumption/definition
dbainbri4d3a0dc2020-12-02 00:33:42 +0000610 go oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent(uint8(oFsm.requestEvent)+1))
mpagenkofc4f56e2020-11-04 17:17:49 +0000611 }
mpagenko01e726e2020-10-23 09:45:29 +0000612 return nil
613 } //unknown cookie
614
615 return nil
616}
617
dbainbri4d3a0dc2020-12-02 00:33:42 +0000618func (oFsm *UniVlanConfigFsm) enterConfigStarting(ctx context.Context, e *fsm.Event) {
619 logger.Debugw(ctx, "UniVlanConfigFsm start", log.Fields{"in state": e.FSM.Current(),
mpagenko01e726e2020-10-23 09:45:29 +0000620 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000621
622 // this FSM is not intended for re-start, needs always new creation for a new run
mpagenko01e726e2020-10-23 09:45:29 +0000623 // (self-destroying - compare enterDisabled())
mpagenkodff5dda2020-08-28 11:52:01 +0000624 oFsm.omciMIdsResponseReceived = make(chan bool)
625 // start go routine for processing of LockState messages
dbainbri4d3a0dc2020-12-02 00:33:42 +0000626 go oFsm.processOmciVlanMessages(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +0000627 //let the state machine run forward from here directly
628 pConfigVlanStateAFsm := oFsm.pAdaptFsm
629 if pConfigVlanStateAFsm != nil {
mpagenko551a4d42020-12-08 18:09:20 +0000630 oFsm.mutexFlowParams.Lock()
mpagenko9a304ea2020-12-16 15:54:01 +0000631
632 //possibly the entry is not valid anymore based on intermediate delete requests
633 //just a basic protection ...
634 if len(oFsm.uniVlanFlowParamsSlice) == 0 {
635 oFsm.mutexFlowParams.Unlock()
636 logger.Debugw(ctx, "UniVlanConfigFsm start: no rule entry anymore available", log.Fields{
637 "device-id": oFsm.deviceID})
638 // Can't call FSM Event directly, decoupling it
639 go func(a_pAFsm *AdapterFsm) {
640 _ = a_pAFsm.pFsm.Event(vlanEvReset)
641 }(pConfigVlanStateAFsm)
642 return
643 }
644
645 //access to uniVlanFlowParamsSlice is done on first element only here per definition
646 //store the actual rule that shall be worked upon in the following transient states
647 oFsm.actualUniVlanConfigRule = oFsm.uniVlanFlowParamsSlice[0].VlanRuleParams
mpagenko551a4d42020-12-08 18:09:20 +0000648 oFsm.mutexFlowParams.Unlock()
mpagenko9a304ea2020-12-16 15:54:01 +0000649 tpID := oFsm.actualUniVlanConfigRule.TpID
650 oFsm.TpIDWaitingFor = tpID
mpagenko551a4d42020-12-08 18:09:20 +0000651 loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.uniID, uint8(tpID))
mpagenko9a304ea2020-12-16 15:54:01 +0000652 logger.Debugw(ctx, "UniVlanConfigFsm - start with first rule", log.Fields{
653 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID,
654 "set-Vlan": oFsm.actualUniVlanConfigRule.SetVid, "tp-id": tpID, "ProfDone": loTechProfDone})
mpagenko551a4d42020-12-08 18:09:20 +0000655 //cmp also usage in EVTOCDE create in omci_cc
656 oFsm.evtocdID = macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo)
mpagenko9a304ea2020-12-16 15:54:01 +0000657 // Can't call FSM Event directly, decoupling it
mpagenko551a4d42020-12-08 18:09:20 +0000658 go func(aPAFsm *AdapterFsm, aTechProfDone bool) {
659 if aPAFsm != nil && aPAFsm.pFsm != nil {
660 if aTechProfDone {
mpagenkodff5dda2020-08-28 11:52:01 +0000661 // let the vlan processing begin
mpagenko551a4d42020-12-08 18:09:20 +0000662 _ = aPAFsm.pFsm.Event(vlanEvStartConfig)
mpagenkodff5dda2020-08-28 11:52:01 +0000663 } else {
664 // set to waiting for Techprofile
mpagenko551a4d42020-12-08 18:09:20 +0000665 _ = aPAFsm.pFsm.Event(vlanEvWaitTechProf)
mpagenkodff5dda2020-08-28 11:52:01 +0000666 }
667 }
mpagenko551a4d42020-12-08 18:09:20 +0000668 }(pConfigVlanStateAFsm, loTechProfDone)
669 } else {
670 logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{
671 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
672 //should never happen, else: recovery would be needed from outside the FSM
673 return
mpagenkodff5dda2020-08-28 11:52:01 +0000674 }
675}
676
dbainbri4d3a0dc2020-12-02 00:33:42 +0000677func (oFsm *UniVlanConfigFsm) enterConfigVtfd(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000678 //mutex protection is required for possible concurrent access to FSM members
679 oFsm.mutexFlowParams.Lock()
mpagenko551a4d42020-12-08 18:09:20 +0000680 oFsm.TpIDWaitingFor = 0 //reset indication to avoid misinterpretation
mpagenko9a304ea2020-12-16 15:54:01 +0000681 if oFsm.actualUniVlanConfigRule.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
mpagenkodff5dda2020-08-28 11:52:01 +0000682 // meaning transparent setup - no specific VTFD setting required
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000683 oFsm.mutexFlowParams.Unlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000684 logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD config required", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000685 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000686 // let the FSM proceed ... (from within this state all internal pointers may be expected to be correct)
mpagenkodff5dda2020-08-28 11:52:01 +0000687 pConfigVlanStateAFsm := oFsm.pAdaptFsm
mpagenko9a304ea2020-12-16 15:54:01 +0000688 // Can't call FSM Event directly, decoupling it
mpagenkodff5dda2020-08-28 11:52:01 +0000689 go func(a_pAFsm *AdapterFsm) {
Himani Chawla4d908332020-08-31 12:30:20 +0530690 _ = a_pAFsm.pFsm.Event(vlanEvRxConfigVtfd)
mpagenkodff5dda2020-08-28 11:52:01 +0000691 }(pConfigVlanStateAFsm)
692 } else {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300693 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
694 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
mpagenko9a304ea2020-12-16 15:54:01 +0000695 vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + uint16(oFsm.actualUniVlanConfigRule.TpID)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000696 logger.Debugw(ctx, "UniVlanConfigFsm create VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300697 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenko01e726e2020-10-23 09:45:29 +0000698 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
699 // setVid is assumed to be masked already by the caller to 12 bit
mpagenko9a304ea2020-12-16 15:54:01 +0000700 oFsm.vlanFilterList[0] = uint16(oFsm.actualUniVlanConfigRule.SetVid)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000701 oFsm.mutexFlowParams.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +0000702 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000703 vtfdFilterList[0] = oFsm.vlanFilterList[0]
704 oFsm.numVlanFilterEntries = 1
mpagenkodff5dda2020-08-28 11:52:01 +0000705 meParams := me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300706 EntityID: vtfdID,
mpagenkodff5dda2020-08-28 11:52:01 +0000707 Attributes: me.AttributeValueMap{
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000708 "VlanFilterList": vtfdFilterList, //omci lib wants a slice for serialization
709 "ForwardOperation": uint8(0x10), //VID investigation
710 "NumberOfEntries": oFsm.numVlanFilterEntries,
mpagenkodff5dda2020-08-28 11:52:01 +0000711 },
712 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000713 logger.Debugw(ctx, "UniVlanConfigFsm sendcreate VTFD", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000714 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000715 meInstance := oFsm.pOmciCC.sendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
mpagenkodff5dda2020-08-28 11:52:01 +0000716 oFsm.pAdaptFsm.commChan, meParams)
717 //accept also nil as (error) return value for writing to LastTx
718 // - this avoids misinterpretation of new received OMCI messages
719 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
720 // send shall return (dual format) error code that can be used here for immediate error treatment
721 // (relevant to all used sendXX() methods in this (and other) FSM's)
mpagenko01e726e2020-10-23 09:45:29 +0000722 oFsm.pLastTxMeInstance = meInstance
mpagenkodff5dda2020-08-28 11:52:01 +0000723 }
724}
725
dbainbri4d3a0dc2020-12-02 00:33:42 +0000726func (oFsm *UniVlanConfigFsm) enterConfigEvtocd(ctx context.Context, e *fsm.Event) {
727 logger.Debugw(ctx, "UniVlanConfigFsm - start config EVTOCD loop", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000728 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +0000729 oFsm.requestEventOffset = 0 //0 offset for last flow-add activity
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300730 go func() {
mpagenko9a304ea2020-12-16 15:54:01 +0000731 //using the first element in the slice because it's the first flow per definition here
732 errEvto := oFsm.performConfigEvtocdEntries(ctx, 0)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300733 //This is correct passing scenario
734 if errEvto == nil {
mpagenko9a304ea2020-12-16 15:54:01 +0000735 tpID := oFsm.actualUniVlanConfigRule.TpID
736 vlanID := oFsm.actualUniVlanConfigRule.SetVid
dbainbri4d3a0dc2020-12-02 00:33:42 +0000737 for _, gemPort := range oFsm.pUniTechProf.getMulticastGemPorts(ctx, oFsm.pOnuUniPort.uniID, uint8(tpID)) {
738 logger.Infow(ctx, "Setting multicast MEs, with first flow", log.Fields{"deviceID": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300739 "techProfile": tpID, "gemPort": gemPort, "vlanID": vlanID, "configuredUniFlow": oFsm.configuredUniFlow})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000740 errCreateAllMulticastME := oFsm.performSettingMulticastME(ctx, tpID, gemPort,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300741 vlanID)
742 if errCreateAllMulticastME != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000743 logger.Errorw(ctx, "Multicast ME create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300744 log.Fields{"device-id": oFsm.deviceID})
745 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
746 }
747 }
748 //TODO Possibly insert new state for multicast --> possibly another jira/later time.
749 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigEvtocd)
750 }
751 }()
mpagenkodff5dda2020-08-28 11:52:01 +0000752}
753
dbainbri4d3a0dc2020-12-02 00:33:42 +0000754func (oFsm *UniVlanConfigFsm) enterVlanConfigDone(ctx context.Context, e *fsm.Event) {
mpagenko9a304ea2020-12-16 15:54:01 +0000755 oFsm.mutexFlowParams.RLock()
756 defer oFsm.mutexFlowParams.RUnlock()
757
dbainbri4d3a0dc2020-12-02 00:33:42 +0000758 logger.Debugw(ctx, "UniVlanConfigFsm - checking on more flows", log.Fields{
mpagenko551a4d42020-12-08 18:09:20 +0000759 "in state": e.FSM.Current(), "device-id": oFsm.deviceID,
760 "overall-uni-rules": oFsm.numUniFlows, "configured-uni-rules": oFsm.configuredUniFlow})
761 pConfigVlanStateAFsm := oFsm.pAdaptFsm
762 if pConfigVlanStateAFsm == nil {
mpagenko551a4d42020-12-08 18:09:20 +0000763 logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{
764 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
765 //should never happen, else: recovery would be needed from outside the FSM
766 return
767 }
768 pConfigVlanStateBaseFsm := pConfigVlanStateAFsm.pFsm
mpagenko01e726e2020-10-23 09:45:29 +0000769 if len(oFsm.uniRemoveFlowsSlice) > 0 {
770 //some further flows are to be removed, removal always starts with the first element
mpagenko9a304ea2020-12-16 15:54:01 +0000771 logger.Debugw(ctx, "UniVlanConfigFsm rule removal from ConfigDone", log.Fields{
772 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID,
773 "tp-id": oFsm.uniRemoveFlowsSlice[0].vlanRuleParams.TpID,
774 "set-Vlan": oFsm.uniRemoveFlowsSlice[0].vlanRuleParams.SetVid})
775 // Can't call FSM Event directly, decoupling it
mpagenko01e726e2020-10-23 09:45:29 +0000776 go func(a_pBaseFsm *fsm.FSM) {
777 _ = a_pBaseFsm.Event(vlanEvRemFlowConfig)
778 }(pConfigVlanStateBaseFsm)
779 return
780 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000781 if oFsm.numUniFlows > oFsm.configuredUniFlow {
mpagenko551a4d42020-12-08 18:09:20 +0000782 if oFsm.configuredUniFlow == 0 {
mpagenko551a4d42020-12-08 18:09:20 +0000783 // this is a restart with a complete new flow, we can re-use the initial flow config control
784 // including the check, if the related techProfile is (still) available (probably also removed in between)
mpagenko9a304ea2020-12-16 15:54:01 +0000785 // Can't call FSM Event directly, decoupling it
mpagenko551a4d42020-12-08 18:09:20 +0000786 go func(a_pBaseFsm *fsm.FSM) {
787 _ = a_pBaseFsm.Event(vlanEvRenew)
788 }(pConfigVlanStateBaseFsm)
789 return
790 }
791
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000792 //some further flows are to be configured
mpagenko9a304ea2020-12-16 15:54:01 +0000793 //store the actual rule that shall be worked upon in the following transient states
794 oFsm.actualUniVlanConfigRule = oFsm.uniVlanFlowParamsSlice[oFsm.configuredUniFlow].VlanRuleParams
mpagenko551a4d42020-12-08 18:09:20 +0000795 //tpId of the next rule to be configured
mpagenko9a304ea2020-12-16 15:54:01 +0000796 tpID := oFsm.actualUniVlanConfigRule.TpID
mpagenko551a4d42020-12-08 18:09:20 +0000797 oFsm.TpIDWaitingFor = tpID
mpagenko551a4d42020-12-08 18:09:20 +0000798 loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.uniID, tpID)
mpagenko9a304ea2020-12-16 15:54:01 +0000799 logger.Debugw(ctx, "UniVlanConfigFsm - incremental config request", log.Fields{
800 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID,
801 "set-Vlan": oFsm.actualUniVlanConfigRule.SetVid, "tp-id": tpID, "ProfDone": loTechProfDone})
802 // Can't call FSM Event directly, decoupling it
mpagenko551a4d42020-12-08 18:09:20 +0000803 go func(aPBaseFsm *fsm.FSM, aTechProfDone bool) {
804 if aTechProfDone {
805 // let the vlan processing continue with next rule
806 _ = aPBaseFsm.Event(vlanEvIncrFlowConfig)
807 } else {
808 // set to waiting for Techprofile
809 _ = aPBaseFsm.Event(vlanEvWaitTPIncr)
810 }
811 }(pConfigVlanStateBaseFsm, loTechProfDone)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000812 return
813 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000814 logger.Debugw(ctx, "UniVlanConfigFsm - VLAN config done: send dh event notification", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000815 "device-id": oFsm.deviceID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000816 // it might appear that some flows are requested also after 'flowPushed' event has been generated ...
817 // state transition notification is checked in deviceHandler
mpagenko551a4d42020-12-08 18:09:20 +0000818 // note: 'flowPushed' event is only generated if all 'pending' rules are configured
mpagenkodff5dda2020-08-28 11:52:01 +0000819 if oFsm.pDeviceHandler != nil {
mpagenkofc4f56e2020-11-04 17:17:49 +0000820 //making use of the add->remove successor enum assumption/definition
dbainbri4d3a0dc2020-12-02 00:33:42 +0000821 go oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent(uint8(oFsm.requestEvent)+oFsm.requestEventOffset))
mpagenkodff5dda2020-08-28 11:52:01 +0000822 }
823}
824
dbainbri4d3a0dc2020-12-02 00:33:42 +0000825func (oFsm *UniVlanConfigFsm) enterConfigIncrFlow(ctx context.Context, e *fsm.Event) {
826 logger.Debugw(ctx, "UniVlanConfigFsm - start config further incremental flow", log.Fields{
Girish Gowdra041dcb32020-11-16 16:54:30 -0800827 "in state": e.FSM.Current(), "recent flow-number": oFsm.configuredUniFlow,
mpagenko01e726e2020-10-23 09:45:29 +0000828 "device-id": oFsm.deviceID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000829 oFsm.mutexFlowParams.Lock()
mpagenko551a4d42020-12-08 18:09:20 +0000830 oFsm.TpIDWaitingFor = 0 //reset indication to avoid misinterpretation
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000831
mpagenko9a304ea2020-12-16 15:54:01 +0000832 if oFsm.actualUniVlanConfigRule.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000833 // meaning transparent setup - no specific VTFD setting required
834 oFsm.mutexFlowParams.Unlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000835 logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD config required", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000836 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000837 } else {
838 if oFsm.numVlanFilterEntries == 0 {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300839 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
840 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
mpagenko9a304ea2020-12-16 15:54:01 +0000841 vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + uint16(oFsm.actualUniVlanConfigRule.TpID)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000842 //no VTFD yet created
dbainbri4d3a0dc2020-12-02 00:33:42 +0000843 logger.Debugw(ctx, "UniVlanConfigFsm create VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300844 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenko01e726e2020-10-23 09:45:29 +0000845 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300846 // 'SetVid' below is assumed to be masked already by the caller to 12 bit
mpagenko9a304ea2020-12-16 15:54:01 +0000847 oFsm.vlanFilterList[0] = uint16(oFsm.actualUniVlanConfigRule.SetVid)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300848
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000849 oFsm.mutexFlowParams.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +0000850 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000851 vtfdFilterList[0] = oFsm.vlanFilterList[0]
852 oFsm.numVlanFilterEntries = 1
853 meParams := me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300854 EntityID: vtfdID,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000855 Attributes: me.AttributeValueMap{
856 "VlanFilterList": vtfdFilterList,
857 "ForwardOperation": uint8(0x10), //VID investigation
858 "NumberOfEntries": oFsm.numVlanFilterEntries,
859 },
860 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000861 meInstance := oFsm.pOmciCC.sendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000862 oFsm.pAdaptFsm.commChan, meParams)
863 //accept also nil as (error) return value for writing to LastTx
864 // - this avoids misinterpretation of new received OMCI messages
865 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
866 // send shall return (dual format) error code that can be used here for immediate error treatment
867 // (relevant to all used sendXX() methods in this (and other) FSM's)
mpagenko01e726e2020-10-23 09:45:29 +0000868 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000869 } else {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300870 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
871 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
mpagenko551a4d42020-12-08 18:09:20 +0000872 vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID +
mpagenko9a304ea2020-12-16 15:54:01 +0000873 uint16(oFsm.actualUniVlanConfigRule.TpID)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300874
dbainbri4d3a0dc2020-12-02 00:33:42 +0000875 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300876 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenko01e726e2020-10-23 09:45:29 +0000877 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000878 // setVid is assumed to be masked already by the caller to 12 bit
879 oFsm.vlanFilterList[oFsm.numVlanFilterEntries] =
mpagenko9a304ea2020-12-16 15:54:01 +0000880 uint16(oFsm.actualUniVlanConfigRule.SetVid)
mpagenko01e726e2020-10-23 09:45:29 +0000881 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300882
883 // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME
884 // VTFD has to be created afresh with a new entity ID that has the same entity ID as the MBPCD ME for every
885 // new vlan associated with a different TP.
mpagenko9a304ea2020-12-16 15:54:01 +0000886 vtfdFilterList[0] = uint16(oFsm.actualUniVlanConfigRule.SetVid)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300887 oFsm.mutexFlowParams.Unlock()
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000888
889 oFsm.numVlanFilterEntries++
890 meParams := me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300891 EntityID: vtfdID,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000892 Attributes: me.AttributeValueMap{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300893 "VlanFilterList": vtfdFilterList,
894 "ForwardOperation": uint8(0x10), //VID investigation
895 "NumberOfEntries": oFsm.numVlanFilterEntries,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000896 },
897 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000898 meInstance := oFsm.pOmciCC.sendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000899 oFsm.pAdaptFsm.commChan, meParams)
900 //accept also nil as (error) return value for writing to LastTx
901 // - this avoids misinterpretation of new received OMCI messages
902 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
903 // send shall return (dual format) error code that can be used here for immediate error treatment
904 // (relevant to all used sendXX() methods in this (and other) FSM's)
mpagenko01e726e2020-10-23 09:45:29 +0000905 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000906 }
907 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +0000908 err := oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000909 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000910 logger.Errorw(ctx, "VTFD create/set failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +0000911 log.Fields{"device-id": oFsm.deviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +0000912 pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm
mpagenko9a304ea2020-12-16 15:54:01 +0000913 // Can't call FSM Event directly, decoupling it
mpagenkofc4f56e2020-11-04 17:17:49 +0000914 go func(a_pBaseFsm *fsm.FSM) {
915 _ = a_pBaseFsm.Event(vlanEvReset)
916 }(pConfigVlanStateBaseFsm)
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000917 return
918 }
919 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000920 oFsm.requestEventOffset = 0 //0 offset for last flow-add activity
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300921 go func() {
mpagenko9a304ea2020-12-16 15:54:01 +0000922 tpID := oFsm.actualUniVlanConfigRule.TpID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000923 errEvto := oFsm.performConfigEvtocdEntries(ctx, oFsm.configuredUniFlow)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300924 //This is correct passing scenario
925 if errEvto == nil {
926 //TODO Possibly insert new state for multicast --> possibly another jira/later time.
dbainbri4d3a0dc2020-12-02 00:33:42 +0000927 for _, gemPort := range oFsm.pUniTechProf.getMulticastGemPorts(ctx, oFsm.pOnuUniPort.uniID, uint8(tpID)) {
mpagenko9a304ea2020-12-16 15:54:01 +0000928 vlanID := oFsm.actualUniVlanConfigRule.SetVid
dbainbri4d3a0dc2020-12-02 00:33:42 +0000929 logger.Infow(ctx, "Setting multicast MEs for additional flows", log.Fields{"deviceID": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300930 "techProfile": tpID, "gemPort": gemPort,
931 "vlanID": vlanID, "configuredUniFlow": oFsm.configuredUniFlow})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000932 errCreateAllMulticastME := oFsm.performSettingMulticastME(ctx, tpID, gemPort, vlanID)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300933 if errCreateAllMulticastME != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000934 logger.Errorw(ctx, "Multicast ME create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300935 log.Fields{"device-id": oFsm.deviceID})
936 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
937 }
938 }
939 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigEvtocd)
940 }
941 }()
Holger Hildebrandt394c5522020-09-11 11:23:01 +0000942}
943
dbainbri4d3a0dc2020-12-02 00:33:42 +0000944func (oFsm *UniVlanConfigFsm) enterRemoveFlow(ctx context.Context, e *fsm.Event) {
mpagenko551a4d42020-12-08 18:09:20 +0000945 oFsm.mutexFlowParams.RLock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000946 logger.Debugw(ctx, "UniVlanConfigFsm - start removing the top remove-flow", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000947 "in state": e.FSM.Current(), "with last cookie": oFsm.uniRemoveFlowsSlice[0].cookie,
948 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +0000949
mpagenkofc4f56e2020-11-04 17:17:49 +0000950 pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm
951 loAllowSpecificOmciConfig := oFsm.pDeviceHandler.ReadyForSpecificOmciConfig
mpagenko01e726e2020-10-23 09:45:29 +0000952 loVlanEntryClear := uint8(0)
953 loVlanEntryRmPos := uint8(0x80) //with indication 'invalid' in bit 7
954 //shallow copy is sufficient as no reference variables are used within struct
955 loRuleParams := oFsm.uniRemoveFlowsSlice[0].vlanRuleParams
mpagenko551a4d42020-12-08 18:09:20 +0000956 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000957 logger.Debugw(ctx, "UniVlanConfigFsm - remove-flow parameters are", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000958 "match vid": loRuleParams.MatchVid, "match Pcp": loRuleParams.MatchPcp,
959 "set vid": strconv.FormatInt(int64(loRuleParams.SetVid), 16),
960 "device-id": oFsm.deviceID})
961
962 if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
963 // meaning transparent setup - no specific VTFD setting required
dbainbri4d3a0dc2020-12-02 00:33:42 +0000964 logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD removal required for transparent flow", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000965 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
966 } else {
967 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization and 're-copy'
968 if oFsm.numVlanFilterEntries == 1 {
mpagenko551a4d42020-12-08 18:09:20 +0000969 vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + uint16(loRuleParams.TpID)
mpagenko01e726e2020-10-23 09:45:29 +0000970 //only one active VLAN entry (hopefully the SetVID we want to remove - should be, but not verified ..)
971 // so we can just delete the VTFD entry
dbainbri4d3a0dc2020-12-02 00:33:42 +0000972 logger.Debugw(ctx, "UniVlanConfigFsm: VTFD delete (no more vlan filters)",
mpagenko01e726e2020-10-23 09:45:29 +0000973 log.Fields{"current vlan list": oFsm.vlanFilterList,
974 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +0000975 loVlanEntryClear = 1 //full VlanFilter clear request
976 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
dbainbri4d3a0dc2020-12-02 00:33:42 +0000977 meInstance := oFsm.pOmciCC.sendDeleteVtfd(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300978 oFsm.pAdaptFsm.commChan, vtfdID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000979 oFsm.pLastTxMeInstance = meInstance
980 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000981 logger.Debugw(ctx, "UniVlanConfigFsm delete VTFD OMCI handling skipped based on device state", log.Fields{
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000982 "device-id": oFsm.deviceID, "device-state": deviceReasonMap[oFsm.pDeviceHandler.deviceReason]})
mpagenkofc4f56e2020-11-04 17:17:49 +0000983 }
mpagenko01e726e2020-10-23 09:45:29 +0000984 } else {
985 //many VTFD already should exists - find and remove the one concerned by the actual remove rule
986 // by updating the VTFD per set command with new valid list
dbainbri4d3a0dc2020-12-02 00:33:42 +0000987 logger.Debugw(ctx, "UniVlanConfigFsm: VTFD removal of requested VLAN from the list on OMCI",
mpagenko01e726e2020-10-23 09:45:29 +0000988 log.Fields{"current vlan list": oFsm.vlanFilterList,
989 "set-vlan": loRuleParams.SetVid, "device-id": oFsm.deviceID})
990 for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ {
991 if loRuleParams.SetVid == uint32(oFsm.vlanFilterList[i]) {
992 loVlanEntryRmPos = i
993 break //abort search
994 }
995 }
996 if loVlanEntryRmPos < cVtfdTableSize {
mpagenko551a4d42020-12-08 18:09:20 +0000997 vtfdID := macBridgePortAniEID + oFsm.pOnuUniPort.entityID + uint16(loRuleParams.TpID)
mpagenko01e726e2020-10-23 09:45:29 +0000998 //valid entry was found - to be eclipsed
999 loVlanEntryClear = 2 //VlanFilter remove request for a specific entry
1000 for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ {
1001 if i < loVlanEntryRmPos {
1002 vtfdFilterList[i] = oFsm.vlanFilterList[i] //copy original
1003 } else if i < (cVtfdTableSize - 1) {
1004 vtfdFilterList[i] = oFsm.vlanFilterList[i+1] //copy successor (including 0 elements)
1005 } else {
1006 vtfdFilterList[i] = 0 //set last byte if needed
1007 }
1008 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001009 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001010 "EntitytId": strconv.FormatInt(int64(vtfdID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001011 "new vlan list": vtfdFilterList, "device-id": oFsm.deviceID})
1012
mpagenkofc4f56e2020-11-04 17:17:49 +00001013 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001014 // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME
dbainbri4d3a0dc2020-12-02 00:33:42 +00001015 meInstance := oFsm.pOmciCC.sendDeleteVtfd(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001016 oFsm.pAdaptFsm.commChan, vtfdID)
mpagenkofc4f56e2020-11-04 17:17:49 +00001017 oFsm.pLastTxMeInstance = meInstance
1018 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001019 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD OMCI handling skipped based on device state", log.Fields{
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001020 "device-id": oFsm.deviceID, "device-state": deviceReasonMap[oFsm.pDeviceHandler.deviceReason]})
mpagenko01e726e2020-10-23 09:45:29 +00001021 }
mpagenko01e726e2020-10-23 09:45:29 +00001022 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001023 logger.Warnw(ctx, "UniVlanConfigFsm: requested VLAN for removal not found in list - ignore and continue (no VTFD set)",
mpagenko01e726e2020-10-23 09:45:29 +00001024 log.Fields{"device-id": oFsm.deviceID})
1025 }
1026 }
1027 if loVlanEntryClear > 0 {
mpagenkofc4f56e2020-11-04 17:17:49 +00001028 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
1029 //waiting on response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001030 err := oFsm.waitforOmciResponse(ctx)
mpagenkofc4f56e2020-11-04 17:17:49 +00001031 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001032 logger.Errorw(ctx, "VTFD delete/reset failed, aborting VlanConfig FSM!",
mpagenkofc4f56e2020-11-04 17:17:49 +00001033 log.Fields{"device-id": oFsm.deviceID})
mpagenko9a304ea2020-12-16 15:54:01 +00001034 // Can't call FSM Event directly, decoupling it
mpagenkofc4f56e2020-11-04 17:17:49 +00001035 go func(a_pBaseFsm *fsm.FSM) {
1036 _ = a_pBaseFsm.Event(vlanEvReset)
1037 }(pConfigVlanStateBaseFsm)
1038 return
1039 }
mpagenko01e726e2020-10-23 09:45:29 +00001040 }
1041
1042 if loVlanEntryClear == 1 {
1043 oFsm.vlanFilterList[0] = 0 //first entry is the only that can contain the previous only-one element
1044 oFsm.numVlanFilterEntries = 0
1045 } else if loVlanEntryClear == 2 {
1046 // new VlanFilterList should be one entry smaller now - copy from last configured entry
1047 // this loop now includes the 0 element on previous last valid entry
1048 for i := uint8(0); i <= oFsm.numVlanFilterEntries; i++ {
1049 oFsm.vlanFilterList[i] = vtfdFilterList[i]
1050 }
1051 oFsm.numVlanFilterEntries--
1052 }
1053 }
1054 }
1055
mpagenkofc4f56e2020-11-04 17:17:49 +00001056 if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state
dbainbri4d3a0dc2020-12-02 00:33:42 +00001057 go oFsm.removeEvtocdEntries(ctx, loRuleParams)
mpagenkofc4f56e2020-11-04 17:17:49 +00001058 } else {
1059 // OMCI processing is not done, expectation is to have the ONU in some basic config state accordingly
dbainbri4d3a0dc2020-12-02 00:33:42 +00001060 logger.Debugw(ctx, "UniVlanConfigFsm remove EVTOCD OMCI handling skipped based on device state", log.Fields{
mpagenkofc4f56e2020-11-04 17:17:49 +00001061 "device-id": oFsm.deviceID})
mpagenko9a304ea2020-12-16 15:54:01 +00001062 // Can't call FSM Event directly, decoupling it
mpagenkofc4f56e2020-11-04 17:17:49 +00001063 go func(a_pBaseFsm *fsm.FSM) {
1064 _ = a_pBaseFsm.Event(vlanEvRemFlowDone)
1065 }(pConfigVlanStateBaseFsm)
1066 }
mpagenkodff5dda2020-08-28 11:52:01 +00001067}
1068
dbainbri4d3a0dc2020-12-02 00:33:42 +00001069func (oFsm *UniVlanConfigFsm) enterVlanCleanupDone(ctx context.Context, e *fsm.Event) {
1070 logger.Debugw(ctx, "UniVlanConfigFsm - removing the removal data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001071 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001072
mpagenko01e726e2020-10-23 09:45:29 +00001073 oFsm.mutexFlowParams.Lock()
1074 if len(oFsm.uniRemoveFlowsSlice) <= 1 {
1075 oFsm.uniRemoveFlowsSlice = nil //reset the slice
dbainbri4d3a0dc2020-12-02 00:33:42 +00001076 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - last remove-flow deleted", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001077 "device-id": oFsm.deviceID})
1078 } else {
1079 //cut off the actual flow by slicing out the first element
1080 oFsm.uniRemoveFlowsSlice = append(
1081 oFsm.uniRemoveFlowsSlice[:0],
1082 oFsm.uniRemoveFlowsSlice[1:]...)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001083 logger.Debugw(ctx, "UniVlanConfigFsm flow removal - specific flow deleted from data", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001084 "device-id": oFsm.deviceID})
1085 }
1086 oFsm.mutexFlowParams.Unlock()
1087
mpagenkofc4f56e2020-11-04 17:17:49 +00001088 oFsm.requestEventOffset = 1 //offset 1 for last flow-remove activity
mpagenko01e726e2020-10-23 09:45:29 +00001089 //return to the basic config verification state
mpagenkodff5dda2020-08-28 11:52:01 +00001090 pConfigVlanStateAFsm := oFsm.pAdaptFsm
1091 if pConfigVlanStateAFsm != nil {
mpagenko9a304ea2020-12-16 15:54:01 +00001092 // Can't call FSM Event directly, decoupling it
mpagenkodff5dda2020-08-28 11:52:01 +00001093 go func(a_pAFsm *AdapterFsm) {
1094 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
mpagenko01e726e2020-10-23 09:45:29 +00001095 _ = a_pAFsm.pFsm.Event(vlanEvFlowDataRemoved)
mpagenkodff5dda2020-08-28 11:52:01 +00001096 }
1097 }(pConfigVlanStateAFsm)
1098 }
1099}
1100
dbainbri4d3a0dc2020-12-02 00:33:42 +00001101func (oFsm *UniVlanConfigFsm) enterResetting(ctx context.Context, e *fsm.Event) {
1102 logger.Debugw(ctx, "UniVlanConfigFsm resetting", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001103
1104 pConfigVlanStateAFsm := oFsm.pAdaptFsm
1105 if pConfigVlanStateAFsm != nil {
1106 // abort running message processing
1107 fsmAbortMsg := Message{
1108 Type: TestMsg,
1109 Data: TestMessage{
1110 TestMessageVal: AbortMessageProcessing,
1111 },
1112 }
1113 pConfigVlanStateAFsm.commChan <- fsmAbortMsg
1114
mpagenko9a304ea2020-12-16 15:54:01 +00001115 //try to restart the FSM to 'disabled'
1116 // Can't call FSM Event directly, decoupling it
mpagenkodff5dda2020-08-28 11:52:01 +00001117 go func(a_pAFsm *AdapterFsm) {
1118 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301119 _ = a_pAFsm.pFsm.Event(vlanEvRestart)
mpagenkodff5dda2020-08-28 11:52:01 +00001120 }
1121 }(pConfigVlanStateAFsm)
1122 }
1123}
1124
dbainbri4d3a0dc2020-12-02 00:33:42 +00001125func (oFsm *UniVlanConfigFsm) enterDisabled(ctx context.Context, e *fsm.Event) {
1126 logger.Debugw(ctx, "UniVlanConfigFsm enters disabled state", log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00001127 oFsm.pLastTxMeInstance = nil
mpagenkodff5dda2020-08-28 11:52:01 +00001128 if oFsm.pDeviceHandler != nil {
mpagenko2418ab02020-11-12 12:58:06 +00001129 //TODO: to clarify with improved error treatment for VlanConfigFsm (timeout,reception) errors
1130 // current code removes the complete FSM including all flow/rule configuration done so far
1131 // this might be a bit to much, it would require fully new flow config from rwCore (at least on OnuDown/up)
1132 // maybe a more sophisticated approach is possible without clearing the data
mpagenko9a304ea2020-12-16 15:54:01 +00001133 oFsm.mutexFlowParams.RLock()
mpagenko2418ab02020-11-12 12:58:06 +00001134 if oFsm.clearPersistency {
1135 //permanently remove possibly stored persistent data
1136 if len(oFsm.uniVlanFlowParamsSlice) > 0 {
1137 var emptySlice = make([]uniVlanFlowParams, 0)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001138 _ = oFsm.pDeviceHandler.storePersUniFlowConfig(ctx, oFsm.pOnuUniPort.uniID, &emptySlice) //ignore errors
mpagenko2418ab02020-11-12 12:58:06 +00001139 }
1140 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001141 logger.Debugw(ctx, "UniVlanConfigFsm persistency data not cleared", log.Fields{"device-id": oFsm.deviceID})
mpagenko2418ab02020-11-12 12:58:06 +00001142 }
mpagenko9a304ea2020-12-16 15:54:01 +00001143 oFsm.mutexFlowParams.RUnlock()
mpagenko2418ab02020-11-12 12:58:06 +00001144 //request removal of 'reference' in the Handler (completely clear the FSM and its data)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001145 go oFsm.pDeviceHandler.RemoveVlanFilterFsm(ctx, oFsm.pOnuUniPort)
mpagenkodff5dda2020-08-28 11:52:01 +00001146 }
1147}
1148
dbainbri4d3a0dc2020-12-02 00:33:42 +00001149func (oFsm *UniVlanConfigFsm) processOmciVlanMessages(ctx context.Context) { //ctx context.Context?
1150 logger.Debugw(ctx, "Start UniVlanConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001151loop:
1152 for {
mpagenkodff5dda2020-08-28 11:52:01 +00001153 // case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +00001154 // logger.Info(ctx,"MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001155 // break loop
Himani Chawla4d908332020-08-31 12:30:20 +05301156 message, ok := <-oFsm.pAdaptFsm.commChan
1157 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001158 logger.Info(ctx, "UniVlanConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301159 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
1160 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1161 break loop
1162 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001163 logger.Debugw(ctx, "UniVlanConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301164
1165 switch message.Type {
1166 case TestMsg:
1167 msg, _ := message.Data.(TestMessage)
1168 if msg.TestMessageVal == AbortMessageProcessing {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001169 logger.Infow(ctx, "UniVlanConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001170 break loop
1171 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001172 logger.Warnw(ctx, "UniVlanConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal})
Himani Chawla4d908332020-08-31 12:30:20 +05301173 case OMCI:
1174 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001175 oFsm.handleOmciVlanConfigMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301176 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +00001177 logger.Warn(ctx, "UniVlanConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID,
Himani Chawla4d908332020-08-31 12:30:20 +05301178 "message.Type": message.Type})
mpagenkodff5dda2020-08-28 11:52:01 +00001179 }
1180 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001181 logger.Infow(ctx, "End UniVlanConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001182}
1183
dbainbri4d3a0dc2020-12-02 00:33:42 +00001184func (oFsm *UniVlanConfigFsm) handleOmciVlanConfigMessage(ctx context.Context, msg OmciMessage) {
1185 logger.Debugw(ctx, "Rx OMCI UniVlanConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00001186 "msgType": msg.OmciMsg.MessageType})
1187
1188 switch msg.OmciMsg.MessageType {
1189 case omci.CreateResponseType:
mpagenko01e726e2020-10-23 09:45:29 +00001190 { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-(
dbainbri4d3a0dc2020-12-02 00:33:42 +00001191 if err := oFsm.handleOmciCreateResponseMessage(ctx, msg.OmciPacket); err != nil {
1192 logger.Warnw(ctx, "CreateResponse handling aborted", log.Fields{"err": err})
mpagenkodff5dda2020-08-28 11:52:01 +00001193 return
1194 }
mpagenkodff5dda2020-08-28 11:52:01 +00001195 } //CreateResponseType
1196 case omci.SetResponseType:
mpagenko01e726e2020-10-23 09:45:29 +00001197 { //leave that here as direct code as most often used
mpagenkodff5dda2020-08-28 11:52:01 +00001198 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
1199 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001200 logger.Errorw(ctx, "Omci Msg layer could not be detected for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001201 log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001202 return
1203 }
1204 msgObj, msgOk := msgLayer.(*omci.SetResponse)
1205 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001206 logger.Errorw(ctx, "Omci Msg layer could not be assigned for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001207 log.Fields{"device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001208 return
1209 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001210 logger.Debugw(ctx, "UniVlanConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenkodff5dda2020-08-28 11:52:01 +00001211 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001212 logger.Errorw(ctx, "UniVlanConfigFsm Omci SetResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00001213 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
mpagenkodff5dda2020-08-28 11:52:01 +00001214 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
1215 return
1216 }
mpagenko01e726e2020-10-23 09:45:29 +00001217 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1218 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1219 switch oFsm.pLastTxMeInstance.GetName() {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001220 case "VlanTaggingFilterData", "ExtendedVlanTaggingOperationConfigurationData", "MulticastOperationsProfile":
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001221 { // let the MultiEntity config proceed by stopping the wait function
mpagenkodff5dda2020-08-28 11:52:01 +00001222 oFsm.omciMIdsResponseReceived <- true
1223 }
1224 }
1225 }
1226 } //SetResponseType
mpagenko01e726e2020-10-23 09:45:29 +00001227 case omci.DeleteResponseType:
1228 { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-(
dbainbri4d3a0dc2020-12-02 00:33:42 +00001229 if err := oFsm.handleOmciDeleteResponseMessage(ctx, msg.OmciPacket); err != nil {
1230 logger.Warnw(ctx, "DeleteResponse handling aborted", log.Fields{"err": err})
mpagenko01e726e2020-10-23 09:45:29 +00001231 return
1232 }
1233 } //DeleteResponseType
mpagenkodff5dda2020-08-28 11:52:01 +00001234 default:
1235 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001236 logger.Errorw(ctx, "Rx OMCI unhandled MsgType",
mpagenko01e726e2020-10-23 09:45:29 +00001237 log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001238 return
1239 }
1240 }
1241}
1242
dbainbri4d3a0dc2020-12-02 00:33:42 +00001243func (oFsm *UniVlanConfigFsm) handleOmciCreateResponseMessage(ctx context.Context, apOmciPacket *gp.Packet) error {
mpagenko01e726e2020-10-23 09:45:29 +00001244 msgLayer := (*apOmciPacket).Layer(omci.LayerTypeCreateResponse)
1245 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001246 logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001247 log.Fields{"device-id": oFsm.deviceID})
1248 return fmt.Errorf("omci msg layer could not be detected for CreateResponse for device-id %x",
1249 oFsm.deviceID)
1250 }
1251 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
1252 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001253 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001254 log.Fields{"device-id": oFsm.deviceID})
1255 return fmt.Errorf("omci msg layer could not be assigned for CreateResponse for device-id %x",
1256 oFsm.deviceID)
1257 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001258 logger.Debugw(ctx, "UniVlanConfigFsm CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001259 if msgObj.Result != me.Success && msgObj.Result != me.InstanceExists {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001260 logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": oFsm.deviceID,
mpagenko01e726e2020-10-23 09:45:29 +00001261 "Error": msgObj.Result})
1262 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
1263 return fmt.Errorf("omci CreateResponse Error for device-id %x",
1264 oFsm.deviceID)
1265 }
1266 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1267 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1268 // to satisfy StaticCodeAnalysis I had to move the small processing into a separate method :-(
1269 switch oFsm.pLastTxMeInstance.GetName() {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001270 case "VlanTaggingFilterData", "MulticastOperationsProfile",
1271 "MulticastSubscriberConfigInfo", "MacBridgePortConfigurationData",
1272 "ExtendedVlanTaggingOperationConfigurationData":
mpagenko01e726e2020-10-23 09:45:29 +00001273 {
1274 if oFsm.pAdaptFsm.pFsm.Current() == vlanStConfigVtfd {
1275 // Only if CreateResponse is received from first flow entry - let the FSM proceed ...
1276 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigVtfd)
1277 } else { // let the MultiEntity config proceed by stopping the wait function
1278 oFsm.omciMIdsResponseReceived <- true
1279 }
1280 }
1281 }
1282 }
1283 return nil
1284}
1285
dbainbri4d3a0dc2020-12-02 00:33:42 +00001286func (oFsm *UniVlanConfigFsm) handleOmciDeleteResponseMessage(ctx context.Context, apOmciPacket *gp.Packet) error {
mpagenko01e726e2020-10-23 09:45:29 +00001287 msgLayer := (*apOmciPacket).Layer(omci.LayerTypeDeleteResponse)
1288 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001289 logger.Errorw(ctx, "UniVlanConfigFsm - Omci Msg layer could not be detected for DeleteResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001290 log.Fields{"device-id": oFsm.deviceID})
1291 return fmt.Errorf("omci msg layer could not be detected for DeleteResponse for device-id %x",
1292 oFsm.deviceID)
1293 }
1294 msgObj, msgOk := msgLayer.(*omci.DeleteResponse)
1295 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001296 logger.Errorw(ctx, "UniVlanConfigFsm - Omci Msg layer could not be assigned for DeleteResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001297 log.Fields{"device-id": oFsm.deviceID})
1298 return fmt.Errorf("omci msg layer could not be assigned for DeleteResponse for device-id %x",
1299 oFsm.deviceID)
1300 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001301 logger.Debugw(ctx, "UniVlanConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenko01e726e2020-10-23 09:45:29 +00001302 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001303 logger.Errorw(ctx, "UniVlanConfigFsm - Omci DeleteResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00001304 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
1305 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
1306 return fmt.Errorf("omci DeleteResponse Error for device-id %x",
1307 oFsm.deviceID)
1308 }
1309 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1310 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1311 switch oFsm.pLastTxMeInstance.GetName() {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001312 case "VlanTaggingFilterData", "ExtendedVlanTaggingOperationConfigurationData":
mpagenko01e726e2020-10-23 09:45:29 +00001313 { // let the MultiEntity config proceed by stopping the wait function
1314 oFsm.omciMIdsResponseReceived <- true
1315 }
1316 }
1317 }
1318 return nil
1319}
1320
dbainbri4d3a0dc2020-12-02 00:33:42 +00001321func (oFsm *UniVlanConfigFsm) performConfigEvtocdEntries(ctx context.Context, aFlowEntryNo uint8) error {
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001322 if aFlowEntryNo == 0 {
1323 // EthType set only at first flow element
mpagenkodff5dda2020-08-28 11:52:01 +00001324 // EVTOCD ME is expected to exist at this point already from MIB-Download (with AssociationType/Pointer)
1325 // we need to extend the configuration by EthType definition and, to be sure, downstream 'inverse' mode
dbainbri4d3a0dc2020-12-02 00:33:42 +00001326 logger.Debugw(ctx, "UniVlanConfigFsm Tx Create::EVTOCD", log.Fields{
mpagenkodff5dda2020-08-28 11:52:01 +00001327 "EntitytId": strconv.FormatInt(int64(oFsm.evtocdID), 16),
1328 "i/oEthType": strconv.FormatInt(int64(cDefaultTpid), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001329 "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001330 associationType := 2 // default to uniPPTP
1331 if oFsm.pOnuUniPort.portType == uniVEIP {
1332 associationType = 10
1333 }
1334 // Create the EVTOCD ME
mpagenkodff5dda2020-08-28 11:52:01 +00001335 meParams := me.ParamData{
1336 EntityID: oFsm.evtocdID,
1337 Attributes: me.AttributeValueMap{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001338 "AssociationType": uint8(associationType),
1339 "AssociatedMePointer": oFsm.pOnuUniPort.entityID,
mpagenkodff5dda2020-08-28 11:52:01 +00001340 },
1341 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001342 meInstance := oFsm.pOmciCC.sendCreateEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true,
mpagenkodff5dda2020-08-28 11:52:01 +00001343 oFsm.pAdaptFsm.commChan, meParams)
1344 //accept also nil as (error) return value for writing to LastTx
1345 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001346 oFsm.pLastTxMeInstance = meInstance
mpagenkodff5dda2020-08-28 11:52:01 +00001347
1348 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001349 err := oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00001350 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001351 logger.Errorw(ctx, "Evtocd create failed, aborting VlanConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001352 log.Fields{"device-id": oFsm.deviceID})
1353 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1354 return fmt.Errorf("evtocd create failed %s, error %s", oFsm.deviceID, err)
1355 }
1356
1357 // Set the EVTOCD ME default params
1358 meParams = me.ParamData{
1359 EntityID: oFsm.evtocdID,
1360 Attributes: me.AttributeValueMap{
1361 "InputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base
1362 "OutputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base
1363 "DownstreamMode": uint8(cDefaultDownstreamMode),
1364 },
1365 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001366 meInstance = oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001367 oFsm.pAdaptFsm.commChan, meParams)
1368 //accept also nil as (error) return value for writing to LastTx
1369 // - this avoids misinterpretation of new received OMCI messages
1370 oFsm.pLastTxMeInstance = meInstance
1371
1372 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001373 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001374 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001375 logger.Errorw(ctx, "Evtocd set TPID failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001376 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301377 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001378 return fmt.Errorf("evtocd set TPID failed %s, error %s", oFsm.deviceID, err)
mpagenkodff5dda2020-08-28 11:52:01 +00001379 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001380 } //first flow element
mpagenkodff5dda2020-08-28 11:52:01 +00001381
mpagenko551a4d42020-12-08 18:09:20 +00001382 oFsm.mutexFlowParams.RLock()
mpagenko9a304ea2020-12-16 15:54:01 +00001383 if oFsm.actualUniVlanConfigRule.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
mpagenkodff5dda2020-08-28 11:52:01 +00001384 //transparent transmission required
mpagenko551a4d42020-12-08 18:09:20 +00001385 oFsm.mutexFlowParams.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001386 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD single tagged transparent rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001387 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001388 sliceEvtocdRule := make([]uint8, 16)
1389 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
1390 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
1391 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
1392 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
1393 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
1394
1395 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
1396 cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule
1397 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
1398 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
1399 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
1400
1401 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
1402 0<<cTreatTTROffset| // Do not pop any tags
1403 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
1404 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
1405 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
1406
1407 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
1408 cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag
1409 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
1410 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
1411
1412 meParams := me.ParamData{
1413 EntityID: oFsm.evtocdID,
1414 Attributes: me.AttributeValueMap{
1415 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
1416 },
1417 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001418 meInstance := oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
mpagenkodff5dda2020-08-28 11:52:01 +00001419 oFsm.pAdaptFsm.commChan, meParams)
1420 //accept also nil as (error) return value for writing to LastTx
1421 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001422 oFsm.pLastTxMeInstance = meInstance
mpagenkodff5dda2020-08-28 11:52:01 +00001423
1424 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001425 err := oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00001426 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001427 logger.Errorw(ctx, "Evtocd set transparent singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001428 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301429 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001430 return fmt.Errorf("evtocd set transparent singletagged rule failed %s, error %s", oFsm.deviceID, err)
1431
mpagenkodff5dda2020-08-28 11:52:01 +00001432 }
1433 } else {
1434 // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario
1435 if oFsm.acceptIncrementalEvtoOption {
mpagenko9a304ea2020-12-16 15:54:01 +00001436 matchPcp := oFsm.actualUniVlanConfigRule.MatchPcp
1437 matchVid := oFsm.actualUniVlanConfigRule.MatchVid
1438 setPcp := oFsm.actualUniVlanConfigRule.SetPcp
1439 setVid := oFsm.actualUniVlanConfigRule.SetVid
mpagenkodff5dda2020-08-28 11:52:01 +00001440 // this defines VID translation scenario: singletagged->singletagged (if not transparent)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001441 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD single tagged translation rule", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001442 "match-pcp": matchPcp, "match-vid": matchVid, "set-pcp": setPcp, "set-vid:": setVid, "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001443 sliceEvtocdRule := make([]uint8, 16)
1444 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
1445 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
1446 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
1447 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
1448 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
1449
1450 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
mpagenko9a304ea2020-12-16 15:54:01 +00001451 oFsm.actualUniVlanConfigRule.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN
1452 oFsm.actualUniVlanConfigRule.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID
mpagenkodff5dda2020-08-28 11:52:01 +00001453 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
1454 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
1455
1456 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
mpagenko9a304ea2020-12-16 15:54:01 +00001457 oFsm.actualUniVlanConfigRule.TagsToRemove<<cTreatTTROffset| // either 1 or 0
mpagenkodff5dda2020-08-28 11:52:01 +00001458 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
1459 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
1460 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
1461
1462 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
mpagenko9a304ea2020-12-16 15:54:01 +00001463 oFsm.actualUniVlanConfigRule.SetPcp<<cTreatPrioOffset| // as configured in flow
1464 oFsm.actualUniVlanConfigRule.SetVid<<cTreatVidOffset| //as configured in flow
mpagenkodff5dda2020-08-28 11:52:01 +00001465 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
mpagenko551a4d42020-12-08 18:09:20 +00001466 oFsm.mutexFlowParams.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001467
1468 meParams := me.ParamData{
1469 EntityID: oFsm.evtocdID,
1470 Attributes: me.AttributeValueMap{
1471 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
1472 },
1473 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001474 meInstance := oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
mpagenkodff5dda2020-08-28 11:52:01 +00001475 oFsm.pAdaptFsm.commChan, meParams)
1476 //accept also nil as (error) return value for writing to LastTx
1477 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001478 oFsm.pLastTxMeInstance = meInstance
mpagenkodff5dda2020-08-28 11:52:01 +00001479
1480 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001481 err := oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00001482 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001483 logger.Errorw(ctx, "Evtocd set singletagged translation rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001484 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301485 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001486 return fmt.Errorf("evtocd set singletagged translation rule failed %s, error %s", oFsm.deviceID, err)
mpagenkodff5dda2020-08-28 11:52:01 +00001487 }
1488 } else {
1489 //not transparent and not acceptIncrementalEvtoOption untagged/priotagged->singletagged
1490 { // just for local var's
1491 // this defines stacking scenario: untagged->singletagged
dbainbri4d3a0dc2020-12-02 00:33:42 +00001492 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD untagged->singletagged rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001493 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001494 sliceEvtocdRule := make([]uint8, 16)
1495 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
1496 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
1497 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
1498 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
1499 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
1500
1501 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
1502 cPrioIgnoreTag<<cFilterPrioOffset| // Not an inner-tag rule
1503 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
1504 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
1505 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
1506
1507 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
1508 0<<cTreatTTROffset| // Do not pop any tags
1509 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
1510 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
1511 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
1512
1513 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
1514 0<<cTreatPrioOffset| // vlan prio set to 0
1515 // (as done in Py code, maybe better option would be setPcp here, which still could be 0?)
mpagenko9a304ea2020-12-16 15:54:01 +00001516 oFsm.actualUniVlanConfigRule.SetVid<<cTreatVidOffset| // Outer VID don't care
mpagenkodff5dda2020-08-28 11:52:01 +00001517 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
1518
mpagenko551a4d42020-12-08 18:09:20 +00001519 oFsm.mutexFlowParams.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001520 meParams := me.ParamData{
1521 EntityID: oFsm.evtocdID,
1522 Attributes: me.AttributeValueMap{
1523 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
1524 },
1525 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001526 meInstance := oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
mpagenkodff5dda2020-08-28 11:52:01 +00001527 oFsm.pAdaptFsm.commChan, meParams)
1528 //accept also nil as (error) return value for writing to LastTx
1529 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001530 oFsm.pLastTxMeInstance = meInstance
mpagenkodff5dda2020-08-28 11:52:01 +00001531
1532 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001533 err := oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00001534 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001535 logger.Errorw(ctx, "Evtocd set untagged->singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001536 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301537 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001538 return fmt.Errorf("evtocd set untagged->singletagged rule failed %s, error %s", oFsm.deviceID, err)
1539
mpagenkodff5dda2020-08-28 11:52:01 +00001540 }
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001541 } // just for local var's
mpagenkodff5dda2020-08-28 11:52:01 +00001542 { // just for local var's
1543 // this defines 'stacking' scenario: priotagged->singletagged
dbainbri4d3a0dc2020-12-02 00:33:42 +00001544 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD priotagged->singletagged rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001545 "device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001546 sliceEvtocdRule := make([]uint8, 16)
1547 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
1548 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
1549 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
1550 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
1551 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
1552
1553 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
1554 cPrioDoNotFilter<<cFilterPrioOffset| // Do not Filter on innerprio
1555 0<<cFilterVidOffset| // filter on inner vid 0 (prioTagged)
1556 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
1557 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
1558
1559 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
1560 1<<cTreatTTROffset| // pop the prio-tag
1561 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
1562 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
1563 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
1564
mpagenko551a4d42020-12-08 18:09:20 +00001565 oFsm.mutexFlowParams.RLock()
mpagenkodff5dda2020-08-28 11:52:01 +00001566 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
1567 cCopyPrioFromInner<<cTreatPrioOffset| // vlan copy from PrioTag
1568 // (as done in Py code, maybe better option would be setPcp here, which still could be PrioCopy?)
mpagenko9a304ea2020-12-16 15:54:01 +00001569 oFsm.actualUniVlanConfigRule.SetVid<<cTreatVidOffset| // Outer VID as configured
mpagenkodff5dda2020-08-28 11:52:01 +00001570 cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100
mpagenko551a4d42020-12-08 18:09:20 +00001571 oFsm.mutexFlowParams.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00001572
1573 meParams := me.ParamData{
1574 EntityID: oFsm.evtocdID,
1575 Attributes: me.AttributeValueMap{
1576 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
1577 },
1578 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001579 meInstance := oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
mpagenkodff5dda2020-08-28 11:52:01 +00001580 oFsm.pAdaptFsm.commChan, meParams)
1581 //accept also nil as (error) return value for writing to LastTx
1582 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001583 oFsm.pLastTxMeInstance = meInstance
mpagenkodff5dda2020-08-28 11:52:01 +00001584
1585 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001586 err := oFsm.waitforOmciResponse(ctx)
mpagenkodff5dda2020-08-28 11:52:01 +00001587 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001588 logger.Errorw(ctx, "Evtocd set priotagged->singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001589 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301590 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001591 return fmt.Errorf("evtocd set priotagged->singletagged rule failed %s, error %s", oFsm.deviceID, err)
1592
mpagenkodff5dda2020-08-28 11:52:01 +00001593 }
1594 } //just for local var's
1595 }
1596 }
1597
mpagenkofc4f56e2020-11-04 17:17:49 +00001598 // if Config has been done for all EVTOCD entries let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001599 logger.Debugw(ctx, "EVTOCD set loop finished", log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00001600 oFsm.configuredUniFlow++ // one (more) flow configured
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001601 return nil
mpagenkodff5dda2020-08-28 11:52:01 +00001602}
1603
dbainbri4d3a0dc2020-12-02 00:33:42 +00001604func (oFsm *UniVlanConfigFsm) removeEvtocdEntries(ctx context.Context, aRuleParams uniVlanRuleParams) {
mpagenko01e726e2020-10-23 09:45:29 +00001605 // configured Input/Output TPID is not modified again - no influence if no filter is applied
1606 if aRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) {
1607 //transparent transmission was set
1608 //perhaps the config is not needed for removal,
1609 // but the specific InnerTpid setting is removed in favor of the real default forwarding rule
dbainbri4d3a0dc2020-12-02 00:33:42 +00001610 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD reset to default single tagged rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001611 "device-id": oFsm.deviceID})
1612 sliceEvtocdRule := make([]uint8, 16)
1613 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
1614 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
1615 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
1616 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
1617 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
1618
1619 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
1620 cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule
1621 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
1622 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
1623 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
1624
1625 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
1626 0<<cTreatTTROffset| // Do not pop any tags
1627 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
1628 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
1629 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
1630
1631 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
1632 cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag
1633 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
1634 cDontCareTpid<<cTreatTpidOffset) // copy TPID and DEI
1635
1636 meParams := me.ParamData{
1637 EntityID: oFsm.evtocdID,
1638 Attributes: me.AttributeValueMap{
1639 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
1640 },
1641 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001642 meInstance := oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
mpagenko01e726e2020-10-23 09:45:29 +00001643 oFsm.pAdaptFsm.commChan, meParams)
1644 //accept also nil as (error) return value for writing to LastTx
1645 // - this avoids misinterpretation of new received OMCI messages
1646 oFsm.pLastTxMeInstance = meInstance
1647
1648 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001649 err := oFsm.waitforOmciResponse(ctx)
mpagenko01e726e2020-10-23 09:45:29 +00001650 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001651 logger.Errorw(ctx, "Evtocd reset singletagged rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001652 log.Fields{"device-id": oFsm.deviceID})
1653 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1654 return
1655 }
1656 } else {
1657 // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario
1658 if oFsm.acceptIncrementalEvtoOption {
1659 // this defines VID translation scenario: singletagged->singletagged (if not transparent)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001660 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD clear single tagged translation rule", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +00001661 "device-id": oFsm.deviceID, "match-vlan": aRuleParams.MatchVid})
1662 sliceEvtocdRule := make([]uint8, 16)
1663 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
1664 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
1665 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
1666 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
1667 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
1668
1669 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
1670 aRuleParams.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN
1671 aRuleParams.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID
1672 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
1673 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
1674
1675 // delete indication for the indicated Filter
1676 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], 0xFFFFFFFF)
1677 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], 0xFFFFFFFF)
1678
1679 meParams := me.ParamData{
1680 EntityID: oFsm.evtocdID,
1681 Attributes: me.AttributeValueMap{
1682 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
1683 },
1684 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001685 meInstance := oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
mpagenko01e726e2020-10-23 09:45:29 +00001686 oFsm.pAdaptFsm.commChan, meParams)
1687 //accept also nil as (error) return value for writing to LastTx
1688 // - this avoids misinterpretation of new received OMCI messages
1689 oFsm.pLastTxMeInstance = meInstance
1690
1691 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001692 err := oFsm.waitforOmciResponse(ctx)
mpagenko01e726e2020-10-23 09:45:29 +00001693 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001694 logger.Errorw(ctx, "Evtocd clear singletagged translation rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001695 log.Fields{"device-id": oFsm.deviceID, "match-vlan": aRuleParams.MatchVid})
1696 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1697 return
1698 }
1699 } else {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001700 // VOL-3685
1701 // NOTE: With ALPHA ONUs it was seen that just resetting a particular entry in the EVTOCD table
1702 // and re-configuring a new entry would not work. The old entry is removed and new entry is created
1703 // indeed, but the traffic landing upstream would carry old vlan sometimes.
1704 // This is only a WORKAROUND which basically deletes the entire EVTOCD ME and re-creates it again
1705 // later when the flow is being re-installed.
1706 // Of course this is applicable to case only where single service (or single tcont) is in use and
1707 // there is only one service vlan (oFsm.acceptIncrementalEvtoOption is false in this case).
1708 // Interstingly this problem has not been observed in multi-tcont (or multi-service) scenario (in
1709 // which case the oFsm.acceptIncrementalEvtoOption is set to true).
1710 if oFsm.configuredUniFlow == 0 && !oFsm.acceptIncrementalEvtoOption {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001711 logger.Debugw(ctx, "UniVlanConfigFsm Tx Remove::EVTOCD", log.Fields{"device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001712 // When there are no more EVTOCD vlan configurations on the ONU and acceptIncrementalEvtoOption
1713 // is not enabled, delete the EVTOCD ME.
mpagenko01e726e2020-10-23 09:45:29 +00001714 meParams := me.ParamData{
1715 EntityID: oFsm.evtocdID,
mpagenko01e726e2020-10-23 09:45:29 +00001716 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001717 meInstance := oFsm.pOmciCC.sendDeleteEvtocd(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
mpagenko01e726e2020-10-23 09:45:29 +00001718 oFsm.pAdaptFsm.commChan, meParams)
1719 //accept also nil as (error) return value for writing to LastTx
1720 // - this avoids misinterpretation of new received OMCI messages
1721 oFsm.pLastTxMeInstance = meInstance
1722
1723 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001724 err := oFsm.waitforOmciResponse(ctx)
mpagenko01e726e2020-10-23 09:45:29 +00001725 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001726 logger.Errorw(ctx, "Evtocd delete rule failed, aborting VlanConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001727 log.Fields{"device-id": oFsm.deviceID})
1728 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1729 return
1730 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001731 } else {
1732 // NOTE : We should ideally never ether this section when oFsm.acceptIncrementalEvtoOption is set to false
1733 // This is true for only ATT/DT workflow
dbainbri4d3a0dc2020-12-02 00:33:42 +00001734 logger.Debugw(ctx, "UniVlanConfigFsm: Remove EVTOCD set operation",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001735 log.Fields{"configured-flow": oFsm.configuredUniFlow, "incremental-evto": oFsm.acceptIncrementalEvtoOption})
1736 //not transparent and not acceptIncrementalEvtoOption: untagged/priotagged->singletagged
1737 { // just for local var's
1738 // this defines stacking scenario: untagged->singletagged
1739 //TODO!! in theory there could be different rules running in setting different PCP/VID'S
1740 // for untagged/priotagged, last rule wins (and remains the only one), maybe that should be
1741 // checked already at flow-add (and rejected) - to be observed if such is possible in Voltha
1742 // delete now assumes there is only one such rule!
dbainbri4d3a0dc2020-12-02 00:33:42 +00001743 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD reset untagged rule to default", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001744 "device-id": oFsm.deviceID})
1745 sliceEvtocdRule := make([]uint8, 16)
1746 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
1747 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
1748 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
1749 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
1750 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
mpagenko01e726e2020-10-23 09:45:29 +00001751
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001752 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
1753 cPrioIgnoreTag<<cFilterPrioOffset| // Not an inner-tag rule
1754 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid
1755 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
1756 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
mpagenko01e726e2020-10-23 09:45:29 +00001757
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001758 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:],
1759 0<<cTreatTTROffset| // Do not pop any tags
1760 cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag
1761 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
1762 cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care
mpagenko01e726e2020-10-23 09:45:29 +00001763
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001764 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:],
1765 cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag
1766 cDontCareVid<<cTreatVidOffset| // Outer VID don't care
1767 cDontCareTpid<<cTreatTpidOffset) // copy TPID and DEI
mpagenko01e726e2020-10-23 09:45:29 +00001768
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001769 meParams := me.ParamData{
1770 EntityID: oFsm.evtocdID,
1771 Attributes: me.AttributeValueMap{
1772 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
1773 },
1774 }
1775 meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true,
1776 oFsm.pAdaptFsm.commChan, meParams)
1777 //accept also nil as (error) return value for writing to LastTx
1778 // - this avoids misinterpretation of new received OMCI messages
1779 oFsm.pLastTxMeInstance = meInstance
1780
1781 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001782 err := oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001783 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001784 logger.Errorw(ctx, "Evtocd reset untagged rule to default failed, aborting VlanConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001785 log.Fields{"device-id": oFsm.deviceID})
1786 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1787 return
1788 }
1789 } // just for local var's
1790 { // just for local var's
1791 // this defines 'stacking' scenario: priotagged->singletagged
dbainbri4d3a0dc2020-12-02 00:33:42 +00001792 logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD delete priotagged rule", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001793 "device-id": oFsm.deviceID})
1794 sliceEvtocdRule := make([]uint8, 16)
1795 // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word'
1796 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:],
1797 cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule
1798 cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid
1799 cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field
1800
1801 binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:],
1802 cPrioDoNotFilter<<cFilterPrioOffset| // Do not Filter on innerprio
1803 0<<cFilterVidOffset| // filter on inner vid 0 (prioTagged)
1804 cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field
1805 cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType
1806
1807 // delete indication for the indicated Filter
1808 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], 0xFFFFFFFF)
1809 binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], 0xFFFFFFFF)
1810
1811 meParams := me.ParamData{
1812 EntityID: oFsm.evtocdID,
1813 Attributes: me.AttributeValueMap{
1814 "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
1815 },
1816 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001817 meInstance := oFsm.pOmciCC.sendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001818 oFsm.pAdaptFsm.commChan, meParams)
1819 //accept also nil as (error) return value for writing to LastTx
1820 // - this avoids misinterpretation of new received OMCI messages
1821 oFsm.pLastTxMeInstance = meInstance
1822
1823 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001824 err := oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001825 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001826 logger.Errorw(ctx, "Evtocd delete priotagged rule failed, aborting VlanConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001827 log.Fields{"device-id": oFsm.deviceID})
1828 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
1829 return
1830 }
mpagenko01e726e2020-10-23 09:45:29 +00001831 }
1832 } //just for local var's
1833 }
1834 }
1835
mpagenkofc4f56e2020-11-04 17:17:49 +00001836 // if Config has been done for all EVTOCD entries let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001837 logger.Debugw(ctx, "EVTOCD filter remove loop finished", log.Fields{"device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00001838 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRemFlowDone)
1839}
1840
dbainbri4d3a0dc2020-12-02 00:33:42 +00001841func (oFsm *UniVlanConfigFsm) waitforOmciResponse(ctx context.Context) error {
mpagenkodff5dda2020-08-28 11:52:01 +00001842 select {
Himani Chawla26e555c2020-08-31 12:30:20 +05301843 // maybe be also some outside cancel (but no context modeled for the moment ...)
mpagenkodff5dda2020-08-28 11:52:01 +00001844 // case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +00001845 // logger.Infow(ctx,"LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00001846 case <-time.After(30 * time.Second): //AS FOR THE OTHER OMCI FSM's
dbainbri4d3a0dc2020-12-02 00:33:42 +00001847 logger.Warnw(ctx, "UniVlanConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00001848 return fmt.Errorf("uniVlanConfigFsm multi entity timeout %s", oFsm.deviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00001849 case success := <-oFsm.omciMIdsResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +05301850 if success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001851 logger.Debug(ctx, "UniVlanConfigFsm multi entity response received")
mpagenkodff5dda2020-08-28 11:52:01 +00001852 return nil
1853 }
1854 // should not happen so far
dbainbri4d3a0dc2020-12-02 00:33:42 +00001855 logger.Warnw(ctx, "UniVlanConfigFsm multi entity response error", log.Fields{"for device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +00001856 return fmt.Errorf("uniVlanConfigFsm multi entity responseError %s", oFsm.deviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00001857 }
1858}
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001859
mpagenko551a4d42020-12-08 18:09:20 +00001860func (oFsm *UniVlanConfigFsm) performSettingMulticastME(ctx context.Context, tpID uint8, multicastGemPortID uint16, vlanID uint32) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001861 logger.Debugw(ctx, "Setting Multicast MEs", log.Fields{"device-id": oFsm.deviceID, "tpID": tpID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001862 "multicastGemPortID": multicastGemPortID, "vlanID": vlanID})
dbainbri4d3a0dc2020-12-02 00:33:42 +00001863 errCreateMOP := oFsm.performCreatingMulticastOperationProfile(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001864 if errCreateMOP != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001865 logger.Errorw(ctx, "MulticastOperationProfile create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001866 log.Fields{"device-id": oFsm.deviceID})
mpagenko9a304ea2020-12-16 15:54:01 +00001867 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001868 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, errCreateMOP)
1869 }
1870
dbainbri4d3a0dc2020-12-02 00:33:42 +00001871 errSettingMOP := oFsm.performSettingMulticastOperationProfile(ctx, multicastGemPortID, vlanID)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001872 if errSettingMOP != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001873 logger.Errorw(ctx, "MulticastOperationProfile setting failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001874 log.Fields{"device-id": oFsm.deviceID})
mpagenko9a304ea2020-12-16 15:54:01 +00001875 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001876 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, errSettingMOP)
1877 }
1878
dbainbri4d3a0dc2020-12-02 00:33:42 +00001879 errCreateMSCI := oFsm.performCreatingMulticastSubscriberConfigInfo(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001880 if errCreateMSCI != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001881 logger.Errorw(ctx, "MulticastOperationProfile setting failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001882 log.Fields{"device-id": oFsm.deviceID})
mpagenko9a304ea2020-12-16 15:54:01 +00001883 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001884 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, errCreateMSCI)
1885 }
1886
1887 meParams := me.ParamData{
1888 EntityID: macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo),
1889 Attributes: me.AttributeValueMap{
1890 "BridgeIdPointer": macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo),
1891 "PortNum": 0xf0, //fixed unique ANI side indication
1892 "TpType": 6, //MCGemIWTP
1893 "TpPointer": multicastGemPortID,
1894 },
1895 }
1896 meInstance := oFsm.pOmciCC.sendCreateMBPConfigDataVar(context.TODO(), ConstDefaultOmciTimeout, true,
1897 oFsm.pAdaptFsm.commChan, meParams)
1898 //accept also nil as (error) return value for writing to LastTx
1899 // - this avoids misinterpretation of new received OMCI messages
1900 oFsm.pLastTxMeInstance = meInstance
dbainbri4d3a0dc2020-12-02 00:33:42 +00001901 err := oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001902 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001903 logger.Errorw(ctx, "CreateMBPConfigData failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001904 log.Fields{"device-id": oFsm.deviceID, "MBPConfigDataID": macBridgeServiceProfileEID})
mpagenko9a304ea2020-12-16 15:54:01 +00001905 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001906 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, err)
1907 }
1908
1909 // ==> Start creating VTFD for mcast vlan
1910
1911 // This attribute uniquely identifies each instance of this managed entity. Through an identical ID,
1912 // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME.
1913 mcastVtfdID := macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo)
1914
dbainbri4d3a0dc2020-12-02 00:33:42 +00001915 logger.Debugw(ctx, "UniVlanConfigFsm set VTFD for mcast", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001916 "EntitytId": strconv.FormatInt(int64(mcastVtfdID), 16), "mcastVlanID": vlanID,
1917 "in state": oFsm.pAdaptFsm.pFsm.Current(), "device-id": oFsm.deviceID})
1918 vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization
1919
1920 // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME
1921 // VTFD has to be created afresh with a new entity ID that has the same entity ID as the MBPCD ME for every
1922 // new vlan associated with a different TP.
1923 vtfdFilterList[0] = uint16(vlanID)
1924
1925 meParams = me.ParamData{
1926 EntityID: mcastVtfdID,
1927 Attributes: me.AttributeValueMap{
1928 "VlanFilterList": vtfdFilterList,
1929 "ForwardOperation": uint8(0x10), //VID investigation
1930 "NumberOfEntries": oFsm.numVlanFilterEntries,
1931 },
1932 }
1933 meInstance = oFsm.pOmciCC.sendCreateVtfdVar(context.TODO(), ConstDefaultOmciTimeout, true,
1934 oFsm.pAdaptFsm.commChan, meParams)
1935 oFsm.pLastTxMeInstance = meInstance
dbainbri4d3a0dc2020-12-02 00:33:42 +00001936 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001937 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001938 logger.Errorw(ctx, "CreateMcastVlanFilterData failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001939 log.Fields{"device-id": oFsm.deviceID, "mcastVtfdID": mcastVtfdID})
mpagenko9a304ea2020-12-16 15:54:01 +00001940 _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001941 return fmt.Errorf("createMcastVlanFilterData responseError %s, error %s", oFsm.deviceID, err)
1942 }
1943
1944 return nil
1945}
1946
dbainbri4d3a0dc2020-12-02 00:33:42 +00001947func (oFsm *UniVlanConfigFsm) performCreatingMulticastSubscriberConfigInfo(ctx context.Context) error {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001948 instID, err := oFsm.pDeviceHandler.getUniPortMEEntityID(oFsm.pOnuUniPort.portNo)
1949 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001950 logger.Errorw(ctx, "error fetching uni port me instance",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001951 log.Fields{"device-id": oFsm.deviceID, "portNo": oFsm.pOnuUniPort.portNo})
1952 return err
1953 }
1954 meParams := me.ParamData{
1955 EntityID: instID,
1956 Attributes: me.AttributeValueMap{
1957 "MeType": 0,
1958 //Direct reference to the Operation profile
1959 //TODO ANI side used on UNI side, not the clearest option.
1960 "MulticastOperationsProfilePointer": macBridgePortAniEID + uint16(oFsm.pOnuUniPort.macBpNo),
1961 },
1962 }
1963 meInstance := oFsm.pOmciCC.sendCreateMulticastSubConfigInfoVar(context.TODO(), ConstDefaultOmciTimeout, true,
1964 oFsm.pAdaptFsm.commChan, meParams)
1965 //accept also nil as (error) return value for writing to LastTx
1966 // - this avoids misinterpretation of new received OMCI messages
1967 oFsm.pLastTxMeInstance = meInstance
1968 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001969 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001970 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001971 logger.Errorw(ctx, "CreateMulticastSubConfigInfo create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001972 log.Fields{"device-id": oFsm.deviceID, "MulticastSubConfigInfo": instID})
1973 return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s", oFsm.deviceID)
1974 }
1975 return nil
1976}
1977
dbainbri4d3a0dc2020-12-02 00:33:42 +00001978func (oFsm *UniVlanConfigFsm) performCreatingMulticastOperationProfile(ctx context.Context) error {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001979 instID := macBridgePortAniEID + uint16(oFsm.pOnuUniPort.macBpNo)
1980 meParams := me.ParamData{
1981 EntityID: instID,
1982 Attributes: me.AttributeValueMap{
1983 "IgmpVersion": 2,
1984 "IgmpFunction": 0,
1985 //0 means false
1986 "ImmediateLeave": 0,
1987 "Robustness": 2,
1988 "QuerierIp": 0,
1989 "QueryInterval": 125,
1990 "QuerierMaxResponseTime": 100,
1991 "LastMemberResponseTime": 10,
1992 //0 means false
1993 "UnauthorizedJoinBehaviour": 0,
1994 },
1995 }
1996 meInstance := oFsm.pOmciCC.sendCreateMulticastOperationProfileVar(context.TODO(), ConstDefaultOmciTimeout, true,
1997 oFsm.pAdaptFsm.commChan, meParams)
1998 //accept also nil as (error) return value for writing to LastTx
1999 // - this avoids misinterpretation of new received OMCI messages
2000 oFsm.pLastTxMeInstance = meInstance
2001 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00002002 err := oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002003 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002004 logger.Errorw(ctx, "CreateMulticastOperationProfile create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002005 log.Fields{"device-id": oFsm.deviceID, "MulticastOperationProfileID": instID})
2006 return fmt.Errorf("createMulticastOperationProfile responseError %s", oFsm.deviceID)
2007 }
2008 return nil
2009}
2010
dbainbri4d3a0dc2020-12-02 00:33:42 +00002011func (oFsm *UniVlanConfigFsm) performSettingMulticastOperationProfile(ctx context.Context, multicastGemPortID uint16, vlanID uint32) error {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002012 instID := macBridgePortAniEID + uint16(oFsm.pOnuUniPort.macBpNo)
2013 //TODO check that this is correct
2014 // Table control
2015 //setCtrl = 1
2016 //rowPartId = 0
2017 //test = 0
2018 //rowKey = 0
2019 tableCtrlStr := "0100000000000000"
2020 tableCtrl := AsByteSlice(tableCtrlStr)
2021 //TODO Building it as a Table, even though the attribute is `StringAttributeType`
2022 // see line 56 of multicastoperationsprofileframe.go, it's an error in the conversion.
2023 // FIXED 30/12/2020 Fixed for now with a local copy of multicastoperationsprofileframe.go in vendor/omci-lib-go
2024 // provided by Chip, needs upstreaming and version change.
2025 dynamicAccessCL := make([]uint8, 24)
2026 copy(dynamicAccessCL, tableCtrl)
2027 //Multicast GemPortId
2028 binary.BigEndian.PutUint16(dynamicAccessCL[2:], multicastGemPortID)
2029 // python version waits for installation of flows, see line 723 onward of
2030 // brcm_openomci_onu_handler.py
2031 binary.BigEndian.PutUint16(dynamicAccessCL[4:], uint16(vlanID))
2032 //Source IP all to 0
2033 binary.BigEndian.PutUint32(dynamicAccessCL[6:], IPToInt32(net.IPv4(0, 0, 0, 0)))
2034 //TODO start and end are hardcoded, get from TP
2035 // Destination IP address start of range
2036 binary.BigEndian.PutUint32(dynamicAccessCL[10:], IPToInt32(net.IPv4(225, 0, 0, 0)))
2037 // Destination IP address end of range
2038 binary.BigEndian.PutUint32(dynamicAccessCL[14:], IPToInt32(net.IPv4(239, 255, 255, 255)))
2039 //imputed group bandwidth
2040 binary.BigEndian.PutUint16(dynamicAccessCL[18:], 0)
2041
2042 meParams := me.ParamData{
2043 EntityID: instID,
2044 Attributes: me.AttributeValueMap{
2045 "DynamicAccessControlListTable": dynamicAccessCL,
2046 },
2047 }
2048 meInstance := oFsm.pOmciCC.sendSetMulticastOperationProfileVar(context.TODO(), ConstDefaultOmciTimeout, true,
2049 oFsm.pAdaptFsm.commChan, meParams)
2050 //accept also nil as (error) return value for writing to LastTx
2051 // - this avoids misinterpretation of new received OMCI messages
2052 oFsm.pLastTxMeInstance = meInstance
2053 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00002054 err := oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002055 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002056 logger.Errorw(ctx, "CreateMulticastOperationProfile create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03002057 log.Fields{"device-id": oFsm.deviceID, "MulticastOperationProfileID": instID})
2058 return fmt.Errorf("createMulticastOperationProfile responseError %s", oFsm.deviceID)
2059 }
2060 return nil
2061}