mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //Package adaptercoreonu provides the utility for onu devices, flows and statistics |
| 18 | package adaptercoreonu |
| 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "encoding/binary" |
| 23 | "errors" |
| 24 | "strconv" |
| 25 | "time" |
| 26 | |
| 27 | "github.com/looplab/fsm" |
| 28 | "github.com/opencord/omci-lib-go" |
| 29 | me "github.com/opencord/omci-lib-go/generated" |
| 30 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 31 | of "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 32 | ) |
| 33 | |
| 34 | const ( |
| 35 | // internal predefined values |
| 36 | cDefaultDownstreamMode = 0 |
| 37 | cDefaultTpid = 0x8100 |
| 38 | ) |
| 39 | |
| 40 | const ( |
| 41 | // bit mask offsets for EVTOCD VlanTaggingOperationTable related to 32 bits (4 bytes) |
| 42 | cFilterPrioOffset = 28 |
| 43 | cFilterVidOffset = 15 |
| 44 | cFilterTpidOffset = 12 |
| 45 | cFilterEtherTypeOffset = 0 |
| 46 | cTreatTTROffset = 30 |
| 47 | cTreatPrioOffset = 16 |
| 48 | cTreatVidOffset = 3 |
| 49 | cTreatTpidOffset = 0 |
| 50 | ) |
| 51 | const ( |
| 52 | // byte offsets for EVTOCD VlanTaggingOperationTable related to overall 16 byte size with slice byte 0 as first Byte (MSB) |
| 53 | cFilterOuterOffset = 0 |
| 54 | cFilterInnerOffset = 4 |
| 55 | cTreatOuterOffset = 8 |
| 56 | cTreatInnerOffset = 12 |
| 57 | ) |
| 58 | const ( |
| 59 | // basic values used within EVTOCD VlanTaggingOperationTable in respect to their bitfields |
| 60 | cPrioIgnoreTag uint32 = 15 |
| 61 | cPrioDefaultFilter uint32 = 14 |
| 62 | cPrioDoNotFilter uint32 = 8 |
| 63 | cDoNotFilterVid uint32 = 4096 |
| 64 | cDoNotFilterTPID uint32 = 0 |
| 65 | cDoNotFilterEtherType uint32 = 0 |
| 66 | cDoNotAddPrio uint32 = 15 |
| 67 | cCopyPrioFromInner uint32 = 8 |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 68 | //cDontCarePrio uint32 = 0 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 69 | cDontCareVid uint32 = 0 |
| 70 | cDontCareTpid uint32 = 0 |
| 71 | cSetOutputTpidCopyDei uint32 = 4 |
| 72 | ) |
| 73 | |
| 74 | const ( |
| 75 | // events of config PON ANI port FSM |
| 76 | vlanEvStart = "vlanEvStart" |
| 77 | vlanEvWaitTechProf = "vlanEvWaitTechProf" |
| 78 | vlanEvContinueConfig = "vlanEvContinueConfig" |
| 79 | vlanEvStartConfig = "vlanEvStartConfig" |
| 80 | vlanEvRxConfigVtfd = "vlanEvRxConfigVtfd" |
| 81 | vlanEvRxConfigEvtocd = "vlanEvRxConfigEvtocd" |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 82 | //vlanEvCleanupConfig = "vlanEvCleanupConfig" |
| 83 | //vlanEvRxCleanVtfd = "vlanEvRxCleanVtfd" |
| 84 | //vlanEvRxCleanEvtocd = "vlanEvRxCleanEvtocd" |
| 85 | //vlanEvTimeoutSimple = "vlanEvTimeoutSimple" |
| 86 | //vlanEvTimeoutMids = "vlanEvTimeoutMids" |
| 87 | vlanEvReset = "vlanEvReset" |
| 88 | vlanEvRestart = "vlanEvRestart" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 89 | ) |
| 90 | const ( |
| 91 | // states of config PON ANI port FSM |
| 92 | vlanStDisabled = "vlanStDisabled" |
| 93 | vlanStStarting = "vlanStStarting" |
| 94 | vlanStWaitingTechProf = "vlanStWaitingTechProf" |
| 95 | vlanStConfigVtfd = "vlanStConfigVtfd" |
| 96 | vlanStConfigEvtocd = "vlanStConfigEvtocd" |
| 97 | vlanStConfigDone = "vlanStConfigDone" |
| 98 | vlanStCleanEvtocd = "vlanStCleanEvtocd" |
| 99 | vlanStCleanVtfd = "vlanStCleanVtfd" |
| 100 | vlanStCleanupDone = "vlanStCleanupDone" |
| 101 | vlanStResetting = "vlanStResetting" |
| 102 | ) |
| 103 | |
| 104 | //UniVlanConfigFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI |
| 105 | type UniVlanConfigFsm struct { |
| 106 | pDeviceHandler *DeviceHandler |
| 107 | pOmciCC *OmciCC |
| 108 | pOnuUniPort *OnuUniPort |
| 109 | pUniTechProf *OnuUniTechProf |
| 110 | pOnuDB *OnuDeviceDB |
| 111 | techProfileID uint16 |
| 112 | requestEvent OnuDeviceEvent |
| 113 | omciMIdsResponseReceived chan bool //seperate channel needed for checking multiInstance OMCI message responses |
| 114 | pAdaptFsm *AdapterFsm |
| 115 | acceptIncrementalEvtoOption bool |
| 116 | //use uint32 types for allowing immediate bitshifting |
| 117 | matchVid uint32 |
| 118 | matchPcp uint32 |
| 119 | tagsToRemove uint32 |
| 120 | setVid uint32 |
| 121 | setPcp uint32 |
| 122 | vtfdID uint16 |
| 123 | evtocdID uint16 |
| 124 | } |
| 125 | |
| 126 | //NewUniVlanConfigFsm is the 'constructor' for the state machine to config the PON ANI ports of ONU UNI ports via OMCI |
| 127 | func NewUniVlanConfigFsm(apDeviceHandler *DeviceHandler, apDevOmciCC *OmciCC, apUniPort *OnuUniPort, apUniTechProf *OnuUniTechProf, |
| 128 | apOnuDB *OnuDeviceDB, aTechProfileID uint16, aRequestEvent OnuDeviceEvent, aName string, |
| 129 | aDeviceID string, aCommChannel chan Message, |
| 130 | aAcceptIncrementalEvto bool, aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) *UniVlanConfigFsm { |
| 131 | instFsm := &UniVlanConfigFsm{ |
| 132 | pDeviceHandler: apDeviceHandler, |
| 133 | pOmciCC: apDevOmciCC, |
| 134 | pOnuUniPort: apUniPort, |
| 135 | pUniTechProf: apUniTechProf, |
| 136 | pOnuDB: apOnuDB, |
| 137 | techProfileID: aTechProfileID, |
| 138 | requestEvent: aRequestEvent, |
| 139 | acceptIncrementalEvtoOption: aAcceptIncrementalEvto, |
| 140 | matchVid: uint32(aMatchVlan), |
| 141 | setVid: uint32(aSetVlan), |
| 142 | setPcp: uint32(aSetPcp), |
| 143 | } |
| 144 | // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters |
| 145 | instFsm.tagsToRemove = 1 //one tag to remove as default setting |
| 146 | instFsm.matchPcp = cPrioDoNotFilter // do not Filter on prio as default |
| 147 | if instFsm.matchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 148 | // no prio/vid filtering requested |
| 149 | instFsm.tagsToRemove = 0 //no tag pop action |
| 150 | instFsm.matchPcp = cPrioIgnoreTag // no vlan tag filtering |
| 151 | if instFsm.setPcp == cCopyPrioFromInner { |
| 152 | //in case of no filtering and configured PrioCopy ensure default prio setting to 0 |
| 153 | // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged |
| 154 | // might collide with NoMatchVid/CopyPrio(/setVid) setting |
| 155 | // this was some precondition setting taken over from py adapter .. |
| 156 | instFsm.setPcp = 0 |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | instFsm.pAdaptFsm = NewAdapterFsm(aName, aDeviceID, aCommChannel) |
| 161 | if instFsm.pAdaptFsm == nil { |
| 162 | logger.Errorw("UniVlanConfigFsm's AdapterFsm could not be instantiated!!", log.Fields{ |
| 163 | "device-id": aDeviceID}) |
| 164 | return nil |
| 165 | } |
| 166 | |
| 167 | instFsm.pAdaptFsm.pFsm = fsm.NewFSM( |
| 168 | vlanStDisabled, |
| 169 | fsm.Events{ |
| 170 | {Name: vlanEvStart, Src: []string{vlanStDisabled}, Dst: vlanStStarting}, |
| 171 | {Name: vlanEvWaitTechProf, Src: []string{vlanStStarting}, Dst: vlanStWaitingTechProf}, |
| 172 | {Name: vlanEvContinueConfig, Src: []string{vlanStWaitingTechProf}, Dst: vlanStConfigVtfd}, |
| 173 | {Name: vlanEvStartConfig, Src: []string{vlanStStarting}, Dst: vlanStConfigVtfd}, |
| 174 | {Name: vlanEvRxConfigVtfd, Src: []string{vlanStConfigVtfd}, Dst: vlanStConfigEvtocd}, |
| 175 | {Name: vlanEvRxConfigEvtocd, Src: []string{vlanStConfigEvtocd}, Dst: vlanStConfigDone}, |
| 176 | //TODO:!!! Also define state transitions for cleanup states and timeouts |
| 177 | /* |
| 178 | {Name: vlanEvTimeoutSimple, Src: []string{ |
| 179 | vlanStCreatingDot1PMapper, vlanStCreatingMBPCD, vlanStSettingTconts, vlanStSettingDot1PMapper}, Dst: vlanStStarting}, |
| 180 | {Name: vlanEvTimeoutMids, Src: []string{ |
| 181 | vlanStCreatingGemNCTPs, vlanStCreatingGemIWs, vlanStSettingPQs}, Dst: vlanStStarting}, |
| 182 | */ |
| 183 | // exceptional treatment for all states except vlanStResetting |
| 184 | {Name: vlanEvReset, Src: []string{vlanStStarting, vlanStWaitingTechProf, |
| 185 | vlanStConfigVtfd, vlanStConfigEvtocd, vlanStConfigDone, |
| 186 | vlanStCleanEvtocd, vlanStCleanVtfd, vlanStCleanupDone}, |
| 187 | Dst: vlanStResetting}, |
| 188 | // the only way to get to resource-cleared disabled state again is via "resseting" |
| 189 | {Name: vlanEvRestart, Src: []string{vlanStResetting}, Dst: vlanStDisabled}, |
| 190 | }, |
| 191 | |
| 192 | fsm.Callbacks{ |
| 193 | "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) }, |
| 194 | ("enter_" + vlanStStarting): func(e *fsm.Event) { instFsm.enterConfigStarting(e) }, |
| 195 | ("enter_" + vlanStConfigVtfd): func(e *fsm.Event) { instFsm.enterConfigVtfd(e) }, |
| 196 | ("enter_" + vlanStConfigEvtocd): func(e *fsm.Event) { instFsm.enterConfigEvtocd(e) }, |
| 197 | ("enter_" + vlanStConfigDone): func(e *fsm.Event) { instFsm.enterVlanConfigDone(e) }, |
| 198 | ("enter_" + vlanStCleanVtfd): func(e *fsm.Event) { instFsm.enterCleanVtfd(e) }, |
| 199 | ("enter_" + vlanStCleanEvtocd): func(e *fsm.Event) { instFsm.enterCleanEvtocd(e) }, |
| 200 | ("enter_" + vlanStCleanupDone): func(e *fsm.Event) { instFsm.enterVlanCleanupDone(e) }, |
| 201 | ("enter_" + vlanStResetting): func(e *fsm.Event) { instFsm.enterResetting(e) }, |
| 202 | ("enter_" + vlanStDisabled): func(e *fsm.Event) { instFsm.enterDisabled(e) }, |
| 203 | }, |
| 204 | ) |
| 205 | if instFsm.pAdaptFsm.pFsm == nil { |
| 206 | logger.Errorw("UniVlanConfigFsm's Base FSM could not be instantiated!!", log.Fields{ |
| 207 | "device-id": aDeviceID}) |
| 208 | return nil |
| 209 | } |
| 210 | |
| 211 | logger.Infow("UniVlanConfigFsm created", log.Fields{"device-id": aDeviceID, |
| 212 | "accIncrEvto": instFsm.acceptIncrementalEvtoOption, |
| 213 | "matchVid": strconv.FormatInt(int64(instFsm.matchVid), 16), |
| 214 | "setVid": strconv.FormatInt(int64(instFsm.setVid), 16), |
| 215 | "setPcp": instFsm.setPcp}) |
| 216 | return instFsm |
| 217 | } |
| 218 | |
| 219 | func (oFsm *UniVlanConfigFsm) enterConfigStarting(e *fsm.Event) { |
| 220 | logger.Debugw("UniVlanConfigFsm start", log.Fields{"in state": e.FSM.Current(), |
| 221 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 222 | |
| 223 | // this FSM is not intended for re-start, needs always new creation for a new run |
| 224 | oFsm.omciMIdsResponseReceived = make(chan bool) |
| 225 | // start go routine for processing of LockState messages |
| 226 | go oFsm.processOmciVlanMessages() |
| 227 | //let the state machine run forward from here directly |
| 228 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 229 | if pConfigVlanStateAFsm != nil { |
| 230 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 231 | go func(a_pAFsm *AdapterFsm) { |
| 232 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
| 233 | //stick to pythonAdapter numbering scheme |
| 234 | oFsm.vtfdID = macBridgePortAniEID + oFsm.pOnuUniPort.entityId + oFsm.techProfileID |
| 235 | //cmp also usage in EVTOCDE create in omci_cc |
| 236 | oFsm.evtocdID = macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo) |
| 237 | |
| 238 | if oFsm.pUniTechProf.getTechProfileDone(oFsm.pOnuUniPort.uniId, oFsm.techProfileID) { |
| 239 | // let the vlan processing begin |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 240 | _ = a_pAFsm.pFsm.Event(vlanEvStartConfig) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 241 | } else { |
| 242 | // set to waiting for Techprofile |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 243 | _ = a_pAFsm.pFsm.Event(vlanEvWaitTechProf) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | }(pConfigVlanStateAFsm) |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | func (oFsm *UniVlanConfigFsm) enterConfigVtfd(e *fsm.Event) { |
| 251 | if oFsm.setVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 252 | // meaning transparent setup - no specific VTFD setting required |
| 253 | logger.Debugw("UniVlanConfigFsm: no VTFD config required", log.Fields{ |
| 254 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 255 | // let the FSM proceed ... (from within this state all internal pointers may be expected to be correct) |
| 256 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 257 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 258 | go func(a_pAFsm *AdapterFsm) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 259 | _ = a_pAFsm.pFsm.Event(vlanEvRxConfigVtfd) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 260 | }(pConfigVlanStateAFsm) |
| 261 | } else { |
| 262 | logger.Debugw("UniVlanConfigFsm create VTFD", log.Fields{ |
| 263 | "EntitytId": strconv.FormatInt(int64(oFsm.vtfdID), 16), |
| 264 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 265 | vlanFilterList := make([]uint16, 12) |
| 266 | vlanFilterList[0] = uint16(oFsm.setVid) // setVid is assumed to be masked already by the caller to 12 bit |
| 267 | meParams := me.ParamData{ |
| 268 | EntityID: oFsm.vtfdID, |
| 269 | Attributes: me.AttributeValueMap{ |
| 270 | "VlanFilterList": vlanFilterList, |
| 271 | "ForwardOperation": uint8(0x10), //VID investigation |
| 272 | "NumberOfEntries": uint8(1), |
| 273 | }, |
| 274 | } |
| 275 | meInstance := oFsm.pOmciCC.sendCreateVtfdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 276 | oFsm.pAdaptFsm.commChan, meParams) |
| 277 | //accept also nil as (error) return value for writing to LastTx |
| 278 | // - this avoids misinterpretation of new received OMCI messages |
| 279 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 280 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 281 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
| 282 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | func (oFsm *UniVlanConfigFsm) enterConfigEvtocd(e *fsm.Event) { |
| 287 | logger.Debugw("UniVlanConfigFsm - start config EVTOCD loop", log.Fields{ |
| 288 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 289 | go oFsm.performConfigEvtocdEntries() |
| 290 | } |
| 291 | |
| 292 | func (oFsm *UniVlanConfigFsm) enterVlanConfigDone(e *fsm.Event) { |
| 293 | logger.Debugw("UniVlanConfigFsm - VLAN config done: send dh event notification", log.Fields{ |
| 294 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 295 | if oFsm.pDeviceHandler != nil { |
| 296 | oFsm.pDeviceHandler.DeviceProcStatusUpdate(oFsm.requestEvent) |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | func (oFsm *UniVlanConfigFsm) enterCleanVtfd(e *fsm.Event) { |
| 301 | logger.Debugw("UniVlanConfigFsm Tx Delete::VTFD", log.Fields{ |
| 302 | /*"EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),*/ |
| 303 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 304 | } |
| 305 | |
| 306 | func (oFsm *UniVlanConfigFsm) enterCleanEvtocd(e *fsm.Event) { |
| 307 | logger.Debugw("UniVlanConfigFsm cleanup EVTOCD", log.Fields{ |
| 308 | /*"EntitytId": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16), |
| 309 | "TPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),*/ |
| 310 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 311 | } |
| 312 | |
| 313 | func (oFsm *UniVlanConfigFsm) enterVlanCleanupDone(e *fsm.Event) { |
| 314 | logger.Debugw("UniVlanConfigFsm - VLAN cleanup done", log.Fields{ |
| 315 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 316 | |
| 317 | //let's reset the state machine in order to release all resources now |
| 318 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 319 | if pConfigVlanStateAFsm != nil { |
| 320 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 321 | go func(a_pAFsm *AdapterFsm) { |
| 322 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 323 | _ = a_pAFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 324 | } |
| 325 | }(pConfigVlanStateAFsm) |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | func (oFsm *UniVlanConfigFsm) enterResetting(e *fsm.Event) { |
| 330 | logger.Debugw("UniVlanConfigFsm resetting", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 331 | |
| 332 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 333 | if pConfigVlanStateAFsm != nil { |
| 334 | // abort running message processing |
| 335 | fsmAbortMsg := Message{ |
| 336 | Type: TestMsg, |
| 337 | Data: TestMessage{ |
| 338 | TestMessageVal: AbortMessageProcessing, |
| 339 | }, |
| 340 | } |
| 341 | pConfigVlanStateAFsm.commChan <- fsmAbortMsg |
| 342 | |
| 343 | //try to restart the FSM to 'disabled', decouple event transfer |
| 344 | go func(a_pAFsm *AdapterFsm) { |
| 345 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 346 | _ = a_pAFsm.pFsm.Event(vlanEvRestart) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 347 | } |
| 348 | }(pConfigVlanStateAFsm) |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | func (oFsm *UniVlanConfigFsm) enterDisabled(e *fsm.Event) { |
| 353 | logger.Debugw("UniVlanConfigFsm enters disabled state", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 354 | if oFsm.pDeviceHandler != nil { |
| 355 | //request removal of 'reference' in the Handler (completely clear the FSM) |
| 356 | go oFsm.pDeviceHandler.RemoveVlanFilterFsm(oFsm.pOnuUniPort) |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | func (oFsm *UniVlanConfigFsm) processOmciVlanMessages() { //ctx context.Context? |
| 361 | logger.Debugw("Start UniVlanConfigFsm Msg processing", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
| 362 | loop: |
| 363 | for { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 364 | // case <-ctx.Done(): |
| 365 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.pAdaptFsm.deviceID}) |
| 366 | // break loop |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 367 | message, ok := <-oFsm.pAdaptFsm.commChan |
| 368 | if !ok { |
| 369 | logger.Info("UniVlanConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 370 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
| 371 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 372 | break loop |
| 373 | } |
| 374 | logger.Debugw("UniVlanConfigFsm Rx Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 375 | |
| 376 | switch message.Type { |
| 377 | case TestMsg: |
| 378 | msg, _ := message.Data.(TestMessage) |
| 379 | if msg.TestMessageVal == AbortMessageProcessing { |
| 380 | logger.Infow("UniVlanConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 381 | break loop |
| 382 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 383 | logger.Warnw("UniVlanConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
| 384 | case OMCI: |
| 385 | msg, _ := message.Data.(OmciMessage) |
| 386 | oFsm.handleOmciVlanConfigMessage(msg) |
| 387 | default: |
| 388 | logger.Warn("UniVlanConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, |
| 389 | "message.Type": message.Type}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | logger.Infow("End UniVlanConfigFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 393 | } |
| 394 | |
| 395 | func (oFsm *UniVlanConfigFsm) handleOmciVlanConfigMessage(msg OmciMessage) { |
| 396 | logger.Debugw("Rx OMCI UniVlanConfigFsm Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, |
| 397 | "msgType": msg.OmciMsg.MessageType}) |
| 398 | |
| 399 | switch msg.OmciMsg.MessageType { |
| 400 | case omci.CreateResponseType: |
| 401 | { |
| 402 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse) |
| 403 | if msgLayer == nil { |
| 404 | logger.Error("Omci Msg layer could not be detected for CreateResponse") |
| 405 | return |
| 406 | } |
| 407 | msgObj, msgOk := msgLayer.(*omci.CreateResponse) |
| 408 | if !msgOk { |
| 409 | logger.Error("Omci Msg layer could not be assigned for CreateResponse") |
| 410 | return |
| 411 | } |
| 412 | logger.Debugw("CreateResponse Data", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj}) |
| 413 | if msgObj.Result != me.Success { |
| 414 | logger.Errorw("Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result}) |
| 415 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 416 | return |
| 417 | } |
| 418 | if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() && |
| 419 | msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() { |
| 420 | // maybe we can use just the same eventName for different state transitions like "forward" |
| 421 | // - might be checked, but so far I go for sure and have to inspect the concrete state events ... |
| 422 | switch oFsm.pOmciCC.pLastTxMeInstance.GetName() { |
| 423 | case "VlanTaggingFilterData": |
| 424 | { // let the FSM proceed ... |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 425 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigVtfd) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | } |
| 429 | } //CreateResponseType |
| 430 | case omci.SetResponseType: |
| 431 | { |
| 432 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 433 | if msgLayer == nil { |
| 434 | logger.Error("UniVlanConfigFsm - Omci Msg layer could not be detected for SetResponse") |
| 435 | return |
| 436 | } |
| 437 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 438 | if !msgOk { |
| 439 | logger.Error("UniVlanConfigFsm - Omci Msg layer could not be assigned for SetResponse") |
| 440 | return |
| 441 | } |
| 442 | logger.Debugw("UniVlanConfigFsm SetResponse Data", log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj}) |
| 443 | if msgObj.Result != me.Success { |
| 444 | logger.Errorw("UniVlanConfigFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result}) |
| 445 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 446 | return |
| 447 | } |
| 448 | if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() && |
| 449 | msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() { |
| 450 | switch oFsm.pOmciCC.pLastTxMeInstance.GetName() { |
| 451 | case "ExtendedVlanTaggingOperationConfigurationData": |
| 452 | { // let the EVTO config proceed by stopping the wait function |
| 453 | oFsm.omciMIdsResponseReceived <- true |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | } //SetResponseType |
| 458 | default: |
| 459 | { |
| 460 | logger.Errorw("UniVlanConfigFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType}) |
| 461 | return |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | func (oFsm *UniVlanConfigFsm) performConfigEvtocdEntries() { |
| 467 | { // for local var |
| 468 | // EVTOCD ME is expected to exist at this point already from MIB-Download (with AssociationType/Pointer) |
| 469 | // we need to extend the configuration by EthType definition and, to be sure, downstream 'inverse' mode |
| 470 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD", log.Fields{ |
| 471 | "EntitytId": strconv.FormatInt(int64(oFsm.evtocdID), 16), |
| 472 | "i/oEthType": strconv.FormatInt(int64(cDefaultTpid), 16), |
| 473 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 474 | meParams := me.ParamData{ |
| 475 | EntityID: oFsm.evtocdID, |
| 476 | Attributes: me.AttributeValueMap{ |
| 477 | "InputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base |
| 478 | "OutputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base |
| 479 | "DownstreamMode": uint8(cDefaultDownstreamMode), |
| 480 | }, |
| 481 | } |
| 482 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 483 | oFsm.pAdaptFsm.commChan, meParams) |
| 484 | //accept also nil as (error) return value for writing to LastTx |
| 485 | // - this avoids misinterpretation of new received OMCI messages |
| 486 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 487 | |
| 488 | //verify response |
| 489 | err := oFsm.waitforOmciResponse() |
| 490 | if err != nil { |
| 491 | logger.Errorw("Evtocd set TPID failed, aborting VlanConfig FSM!", |
| 492 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 493 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 494 | return |
| 495 | } |
| 496 | } //for local var |
| 497 | |
| 498 | if oFsm.setVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 499 | //transparent transmission required |
| 500 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD single tagged transparent rule", log.Fields{ |
| 501 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 502 | sliceEvtocdRule := make([]uint8, 16) |
| 503 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 504 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 505 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 506 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 507 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 508 | |
| 509 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 510 | cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule |
| 511 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 512 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 513 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 514 | |
| 515 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 516 | 0<<cTreatTTROffset| // Do not pop any tags |
| 517 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 518 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 519 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 520 | |
| 521 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 522 | cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag |
| 523 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 524 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 525 | |
| 526 | meParams := me.ParamData{ |
| 527 | EntityID: oFsm.evtocdID, |
| 528 | Attributes: me.AttributeValueMap{ |
| 529 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 530 | }, |
| 531 | } |
| 532 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 533 | oFsm.pAdaptFsm.commChan, meParams) |
| 534 | //accept also nil as (error) return value for writing to LastTx |
| 535 | // - this avoids misinterpretation of new received OMCI messages |
| 536 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 537 | |
| 538 | //verify response |
| 539 | err := oFsm.waitforOmciResponse() |
| 540 | if err != nil { |
| 541 | logger.Errorw("Evtocd set transparent singletagged rule failed, aborting VlanConfig FSM!", |
| 542 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 543 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 544 | return |
| 545 | } |
| 546 | } else { |
| 547 | // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario |
| 548 | if oFsm.acceptIncrementalEvtoOption { |
| 549 | // this defines VID translation scenario: singletagged->singletagged (if not transparent) |
| 550 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD single tagged translation rule", log.Fields{ |
| 551 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 552 | sliceEvtocdRule := make([]uint8, 16) |
| 553 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 554 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 555 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 556 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 557 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 558 | |
| 559 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 560 | oFsm.matchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN |
| 561 | oFsm.matchVid<<cFilterVidOffset| // either DNFonVid or real filter VID |
| 562 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 563 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 564 | |
| 565 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 566 | oFsm.tagsToRemove<<cTreatTTROffset| // either 1 or 0 |
| 567 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 568 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 569 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 570 | |
| 571 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 572 | oFsm.setPcp<<cTreatPrioOffset| // as configured in flow |
| 573 | oFsm.setVid<<cTreatVidOffset| //as configured in flow |
| 574 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 575 | |
| 576 | meParams := me.ParamData{ |
| 577 | EntityID: oFsm.evtocdID, |
| 578 | Attributes: me.AttributeValueMap{ |
| 579 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 580 | }, |
| 581 | } |
| 582 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 583 | oFsm.pAdaptFsm.commChan, meParams) |
| 584 | //accept also nil as (error) return value for writing to LastTx |
| 585 | // - this avoids misinterpretation of new received OMCI messages |
| 586 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 587 | |
| 588 | //verify response |
| 589 | err := oFsm.waitforOmciResponse() |
| 590 | if err != nil { |
| 591 | logger.Errorw("Evtocd set singletagged translation rule failed, aborting VlanConfig FSM!", |
| 592 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 593 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 594 | return |
| 595 | } |
| 596 | } else { |
| 597 | //not transparent and not acceptIncrementalEvtoOption untagged/priotagged->singletagged |
| 598 | { // just for local var's |
| 599 | // this defines stacking scenario: untagged->singletagged |
| 600 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD untagged->singletagged rule", log.Fields{ |
| 601 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 602 | sliceEvtocdRule := make([]uint8, 16) |
| 603 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 604 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 605 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 606 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 607 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 608 | |
| 609 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 610 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an inner-tag rule |
| 611 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 612 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 613 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 614 | |
| 615 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 616 | 0<<cTreatTTROffset| // Do not pop any tags |
| 617 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 618 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 619 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 620 | |
| 621 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 622 | 0<<cTreatPrioOffset| // vlan prio set to 0 |
| 623 | // (as done in Py code, maybe better option would be setPcp here, which still could be 0?) |
| 624 | oFsm.setVid<<cTreatVidOffset| // Outer VID don't care |
| 625 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 626 | |
| 627 | meParams := me.ParamData{ |
| 628 | EntityID: oFsm.evtocdID, |
| 629 | Attributes: me.AttributeValueMap{ |
| 630 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 631 | }, |
| 632 | } |
| 633 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 634 | oFsm.pAdaptFsm.commChan, meParams) |
| 635 | //accept also nil as (error) return value for writing to LastTx |
| 636 | // - this avoids misinterpretation of new received OMCI messages |
| 637 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 638 | |
| 639 | //verify response |
| 640 | err := oFsm.waitforOmciResponse() |
| 641 | if err != nil { |
| 642 | logger.Errorw("Evtocd set untagged->singletagged rule failed, aborting VlanConfig FSM!", |
| 643 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 644 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 645 | return |
| 646 | } |
| 647 | } //just for local var's |
| 648 | { // just for local var's |
| 649 | // this defines 'stacking' scenario: priotagged->singletagged |
| 650 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD priotagged->singletagged rule", log.Fields{ |
| 651 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 652 | sliceEvtocdRule := make([]uint8, 16) |
| 653 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 654 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 655 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 656 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 657 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 658 | |
| 659 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 660 | cPrioDoNotFilter<<cFilterPrioOffset| // Do not Filter on innerprio |
| 661 | 0<<cFilterVidOffset| // filter on inner vid 0 (prioTagged) |
| 662 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 663 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 664 | |
| 665 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 666 | 1<<cTreatTTROffset| // pop the prio-tag |
| 667 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 668 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 669 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 670 | |
| 671 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 672 | cCopyPrioFromInner<<cTreatPrioOffset| // vlan copy from PrioTag |
| 673 | // (as done in Py code, maybe better option would be setPcp here, which still could be PrioCopy?) |
| 674 | oFsm.setVid<<cTreatVidOffset| // Outer VID as configured |
| 675 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 676 | |
| 677 | meParams := me.ParamData{ |
| 678 | EntityID: oFsm.evtocdID, |
| 679 | Attributes: me.AttributeValueMap{ |
| 680 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 681 | }, |
| 682 | } |
| 683 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 684 | oFsm.pAdaptFsm.commChan, meParams) |
| 685 | //accept also nil as (error) return value for writing to LastTx |
| 686 | // - this avoids misinterpretation of new received OMCI messages |
| 687 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 688 | |
| 689 | //verify response |
| 690 | err := oFsm.waitforOmciResponse() |
| 691 | if err != nil { |
| 692 | logger.Errorw("Evtocd set priotagged->singletagged rule failed, aborting VlanConfig FSM!", |
| 693 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 694 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 695 | return |
| 696 | } |
| 697 | } //just for local var's |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | // if Config has been done for all GemPort instances let the FSM proceed |
| 702 | logger.Debugw("EVTOCD set loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 703 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigEvtocd) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | func (oFsm *UniVlanConfigFsm) waitforOmciResponse() error { |
| 707 | select { |
| 708 | // maybe be also some outside cancel (but no context modelled for the moment ...) |
| 709 | // case <-ctx.Done(): |
| 710 | // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
| 711 | case <-time.After(30 * time.Second): //AS FOR THE OTHER OMCI FSM's |
| 712 | logger.Warnw("UniVlanConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
| 713 | return errors.New("UniVlanConfigFsm multi entity timeout") |
| 714 | case success := <-oFsm.omciMIdsResponseReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 715 | if success { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 716 | logger.Debug("UniVlanConfigFsm multi entity response received") |
| 717 | return nil |
| 718 | } |
| 719 | // should not happen so far |
| 720 | logger.Warnw("UniVlanConfigFsm multi entity response error", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
| 721 | return errors.New("UniVlanConfigFsm multi entity responseError") |
| 722 | } |
| 723 | } |