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" |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 23 | "fmt" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 24 | "strconv" |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 25 | "sync" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 26 | "time" |
| 27 | |
| 28 | "github.com/looplab/fsm" |
| 29 | "github.com/opencord/omci-lib-go" |
| 30 | me "github.com/opencord/omci-lib-go/generated" |
| 31 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 32 | of "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 33 | ) |
| 34 | |
| 35 | const ( |
| 36 | // internal predefined values |
| 37 | cDefaultDownstreamMode = 0 |
| 38 | cDefaultTpid = 0x8100 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 39 | cMaxAllowedFlows = 12 //which might be under discussion, for the moment connected to limit of VLAN's within VTFD |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 40 | ) |
| 41 | |
| 42 | const ( |
| 43 | // bit mask offsets for EVTOCD VlanTaggingOperationTable related to 32 bits (4 bytes) |
| 44 | cFilterPrioOffset = 28 |
| 45 | cFilterVidOffset = 15 |
| 46 | cFilterTpidOffset = 12 |
| 47 | cFilterEtherTypeOffset = 0 |
| 48 | cTreatTTROffset = 30 |
| 49 | cTreatPrioOffset = 16 |
| 50 | cTreatVidOffset = 3 |
| 51 | cTreatTpidOffset = 0 |
| 52 | ) |
| 53 | const ( |
| 54 | // byte offsets for EVTOCD VlanTaggingOperationTable related to overall 16 byte size with slice byte 0 as first Byte (MSB) |
| 55 | cFilterOuterOffset = 0 |
| 56 | cFilterInnerOffset = 4 |
| 57 | cTreatOuterOffset = 8 |
| 58 | cTreatInnerOffset = 12 |
| 59 | ) |
| 60 | const ( |
| 61 | // basic values used within EVTOCD VlanTaggingOperationTable in respect to their bitfields |
| 62 | cPrioIgnoreTag uint32 = 15 |
| 63 | cPrioDefaultFilter uint32 = 14 |
| 64 | cPrioDoNotFilter uint32 = 8 |
| 65 | cDoNotFilterVid uint32 = 4096 |
| 66 | cDoNotFilterTPID uint32 = 0 |
| 67 | cDoNotFilterEtherType uint32 = 0 |
| 68 | cDoNotAddPrio uint32 = 15 |
| 69 | cCopyPrioFromInner uint32 = 8 |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 70 | //cDontCarePrio uint32 = 0 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 71 | cDontCareVid uint32 = 0 |
| 72 | cDontCareTpid uint32 = 0 |
| 73 | cSetOutputTpidCopyDei uint32 = 4 |
| 74 | ) |
| 75 | |
| 76 | const ( |
| 77 | // events of config PON ANI port FSM |
| 78 | vlanEvStart = "vlanEvStart" |
| 79 | vlanEvWaitTechProf = "vlanEvWaitTechProf" |
| 80 | vlanEvContinueConfig = "vlanEvContinueConfig" |
| 81 | vlanEvStartConfig = "vlanEvStartConfig" |
| 82 | vlanEvRxConfigVtfd = "vlanEvRxConfigVtfd" |
| 83 | vlanEvRxConfigEvtocd = "vlanEvRxConfigEvtocd" |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 84 | vlanEvIncrFlowConfig = "vlanEvIncrFlowConfig" |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 85 | //vlanEvCleanupConfig = "vlanEvCleanupConfig" |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 86 | //vlanEvRxCleanVtfd = "vlanEvRxCleanVtfd" |
| 87 | //vlanEvRxCleanEvtocd = "vlanEvRxCleanEvtocd" |
| 88 | //vlanEvTimeoutSimple = "vlanEvTimeoutSimple" |
| 89 | //vlanEvTimeoutMids = "vlanEvTimeoutMids" |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 90 | vlanEvReset = "vlanEvReset" |
| 91 | vlanEvRestart = "vlanEvRestart" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 92 | ) |
| 93 | const ( |
| 94 | // states of config PON ANI port FSM |
| 95 | vlanStDisabled = "vlanStDisabled" |
| 96 | vlanStStarting = "vlanStStarting" |
| 97 | vlanStWaitingTechProf = "vlanStWaitingTechProf" |
| 98 | vlanStConfigVtfd = "vlanStConfigVtfd" |
| 99 | vlanStConfigEvtocd = "vlanStConfigEvtocd" |
| 100 | vlanStConfigDone = "vlanStConfigDone" |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 101 | vlanStConfigIncrFlow = "vlanStConfigIncrFlow" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 102 | vlanStCleanEvtocd = "vlanStCleanEvtocd" |
| 103 | vlanStCleanVtfd = "vlanStCleanVtfd" |
| 104 | vlanStCleanupDone = "vlanStCleanupDone" |
| 105 | vlanStResetting = "vlanStResetting" |
| 106 | ) |
| 107 | |
| 108 | //UniVlanConfigFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI |
| 109 | type UniVlanConfigFsm struct { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 110 | pDeviceHandler *deviceHandler |
| 111 | pOmciCC *omciCC |
| 112 | pOnuUniPort *onuUniPort |
| 113 | pUniTechProf *onuUniTechProf |
| 114 | pOnuDB *onuDeviceDB |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 115 | techProfileID uint16 |
| 116 | requestEvent OnuDeviceEvent |
| 117 | omciMIdsResponseReceived chan bool //seperate channel needed for checking multiInstance OMCI message responses |
| 118 | pAdaptFsm *AdapterFsm |
| 119 | acceptIncrementalEvtoOption bool |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 120 | mutexFlowParams sync.Mutex |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 121 | uniFlowParamsSlice []uniVlanFlowParams |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 122 | numUniFlows uint8 // expected number of flows should be less than 12 |
| 123 | configuredUniFlow uint8 |
| 124 | numVlanFilterEntries uint8 |
| 125 | vlanFilterList [12]uint16 |
| 126 | vtfdID uint16 |
| 127 | evtocdID uint16 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | //NewUniVlanConfigFsm is the 'constructor' for the state machine to config the PON ANI ports of ONU UNI ports via OMCI |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 131 | func NewUniVlanConfigFsm(apDeviceHandler *deviceHandler, apDevOmciCC *omciCC, apUniPort *onuUniPort, apUniTechProf *onuUniTechProf, |
| 132 | apOnuDB *onuDeviceDB, aTechProfileID uint16, aRequestEvent OnuDeviceEvent, aName string, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 133 | aDeviceID string, aCommChannel chan Message, |
| 134 | aAcceptIncrementalEvto bool, aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) *UniVlanConfigFsm { |
| 135 | instFsm := &UniVlanConfigFsm{ |
| 136 | pDeviceHandler: apDeviceHandler, |
| 137 | pOmciCC: apDevOmciCC, |
| 138 | pOnuUniPort: apUniPort, |
| 139 | pUniTechProf: apUniTechProf, |
| 140 | pOnuDB: apOnuDB, |
| 141 | techProfileID: aTechProfileID, |
| 142 | requestEvent: aRequestEvent, |
| 143 | acceptIncrementalEvtoOption: aAcceptIncrementalEvto, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 144 | numUniFlows: 0, |
| 145 | configuredUniFlow: 0, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | instFsm.pAdaptFsm = NewAdapterFsm(aName, aDeviceID, aCommChannel) |
| 149 | if instFsm.pAdaptFsm == nil { |
| 150 | logger.Errorw("UniVlanConfigFsm's AdapterFsm could not be instantiated!!", log.Fields{ |
| 151 | "device-id": aDeviceID}) |
| 152 | return nil |
| 153 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 154 | instFsm.pAdaptFsm.pFsm = fsm.NewFSM( |
| 155 | vlanStDisabled, |
| 156 | fsm.Events{ |
| 157 | {Name: vlanEvStart, Src: []string{vlanStDisabled}, Dst: vlanStStarting}, |
| 158 | {Name: vlanEvWaitTechProf, Src: []string{vlanStStarting}, Dst: vlanStWaitingTechProf}, |
| 159 | {Name: vlanEvContinueConfig, Src: []string{vlanStWaitingTechProf}, Dst: vlanStConfigVtfd}, |
| 160 | {Name: vlanEvStartConfig, Src: []string{vlanStStarting}, Dst: vlanStConfigVtfd}, |
| 161 | {Name: vlanEvRxConfigVtfd, Src: []string{vlanStConfigVtfd}, Dst: vlanStConfigEvtocd}, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 162 | {Name: vlanEvRxConfigEvtocd, Src: []string{vlanStConfigEvtocd, vlanStConfigIncrFlow}, |
| 163 | Dst: vlanStConfigDone}, |
| 164 | {Name: vlanEvIncrFlowConfig, Src: []string{vlanStConfigDone}, Dst: vlanStConfigIncrFlow}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 165 | /* |
| 166 | {Name: vlanEvTimeoutSimple, Src: []string{ |
| 167 | vlanStCreatingDot1PMapper, vlanStCreatingMBPCD, vlanStSettingTconts, vlanStSettingDot1PMapper}, Dst: vlanStStarting}, |
| 168 | {Name: vlanEvTimeoutMids, Src: []string{ |
| 169 | vlanStCreatingGemNCTPs, vlanStCreatingGemIWs, vlanStSettingPQs}, Dst: vlanStStarting}, |
| 170 | */ |
| 171 | // exceptional treatment for all states except vlanStResetting |
| 172 | {Name: vlanEvReset, Src: []string{vlanStStarting, vlanStWaitingTechProf, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 173 | vlanStConfigVtfd, vlanStConfigEvtocd, vlanStConfigDone, vlanStConfigIncrFlow, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 174 | vlanStCleanEvtocd, vlanStCleanVtfd, vlanStCleanupDone}, |
| 175 | Dst: vlanStResetting}, |
| 176 | // the only way to get to resource-cleared disabled state again is via "resseting" |
| 177 | {Name: vlanEvRestart, Src: []string{vlanStResetting}, Dst: vlanStDisabled}, |
| 178 | }, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 179 | fsm.Callbacks{ |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 180 | "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) }, |
| 181 | ("enter_" + vlanStStarting): func(e *fsm.Event) { instFsm.enterConfigStarting(e) }, |
| 182 | ("enter_" + vlanStConfigVtfd): func(e *fsm.Event) { instFsm.enterConfigVtfd(e) }, |
| 183 | ("enter_" + vlanStConfigEvtocd): func(e *fsm.Event) { instFsm.enterConfigEvtocd(e) }, |
| 184 | ("enter_" + vlanStConfigDone): func(e *fsm.Event) { instFsm.enterVlanConfigDone(e) }, |
| 185 | ("enter_" + vlanStConfigIncrFlow): func(e *fsm.Event) { instFsm.enterConfigIncrFlow(e) }, |
| 186 | ("enter_" + vlanStCleanVtfd): func(e *fsm.Event) { instFsm.enterCleanVtfd(e) }, |
| 187 | ("enter_" + vlanStCleanEvtocd): func(e *fsm.Event) { instFsm.enterCleanEvtocd(e) }, |
| 188 | ("enter_" + vlanStCleanupDone): func(e *fsm.Event) { instFsm.enterVlanCleanupDone(e) }, |
| 189 | ("enter_" + vlanStResetting): func(e *fsm.Event) { instFsm.enterResetting(e) }, |
| 190 | ("enter_" + vlanStDisabled): func(e *fsm.Event) { instFsm.enterDisabled(e) }, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 191 | }, |
| 192 | ) |
| 193 | if instFsm.pAdaptFsm.pFsm == nil { |
| 194 | logger.Errorw("UniVlanConfigFsm's Base FSM could not be instantiated!!", log.Fields{ |
| 195 | "device-id": aDeviceID}) |
| 196 | return nil |
| 197 | } |
| 198 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 199 | _ = instFsm.SetUniFlowParams(aTechProfileID, aMatchVlan, aSetVlan, aSetPcp) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 200 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 201 | logger.Infow("UniVlanConfigFsm created", log.Fields{"device-id": aDeviceID, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 202 | "accIncrEvto": instFsm.acceptIncrementalEvtoOption}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 203 | return instFsm |
| 204 | } |
| 205 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 206 | //SetUniFlowParams verifies on existence of flow parameters to be configured |
| 207 | // and appends a new flow if there is space |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 208 | func (oFsm *UniVlanConfigFsm) SetUniFlowParams(aTpID uint16, aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) error { |
| 209 | loFlowParams := uniVlanFlowParams{ |
| 210 | TpID: aTpID, |
| 211 | MatchVid: uint32(aMatchVlan), |
| 212 | SetVid: uint32(aSetVlan), |
| 213 | SetPcp: uint32(aSetPcp), |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 214 | } |
| 215 | // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 216 | loFlowParams.TagsToRemove = 1 //one tag to remove as default setting |
| 217 | loFlowParams.MatchPcp = cPrioDoNotFilter // do not Filter on prio as default |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 218 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 219 | if loFlowParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 220 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 221 | loFlowParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 222 | //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther) |
| 223 | } else { |
| 224 | if !oFsm.acceptIncrementalEvtoOption { |
| 225 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 226 | loFlowParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 230 | if loFlowParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 231 | // no prio/vid filtering requested |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 232 | loFlowParams.TagsToRemove = 0 //no tag pop action |
| 233 | loFlowParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering |
| 234 | if loFlowParams.SetPcp == cCopyPrioFromInner { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 235 | //in case of no filtering and configured PrioCopy ensure default prio setting to 0 |
| 236 | // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged |
| 237 | // might collide with NoMatchVid/CopyPrio(/setVid) setting |
| 238 | // this was some precondition setting taken over from py adapter .. |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 239 | loFlowParams.SetPcp = 0 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | flowEntryMatch := false |
| 243 | //mutex protection is required for possible concurrent access to FSM members |
| 244 | oFsm.mutexFlowParams.Lock() |
| 245 | defer oFsm.mutexFlowParams.Unlock() |
| 246 | for _, storedUniFlowParams := range oFsm.uniFlowParamsSlice { |
| 247 | if storedUniFlowParams == loFlowParams { |
| 248 | flowEntryMatch = true |
| 249 | break |
| 250 | } |
| 251 | } |
| 252 | if flowEntryMatch { |
| 253 | logger.Debugw("UniVlanConfigFsm flow setting - flow already exists (ignore)", log.Fields{ |
| 254 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 255 | } else { |
| 256 | if oFsm.numUniFlows < cMaxAllowedFlows { |
| 257 | oFsm.uniFlowParamsSlice = append(oFsm.uniFlowParamsSlice, loFlowParams) |
| 258 | oFsm.numUniFlows++ |
| 259 | logger.Debugw("UniVlanConfigFsm flow added", log.Fields{ |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 260 | "MatchVid": strconv.FormatInt(int64(loFlowParams.MatchVid), 16), |
| 261 | "SetVid": strconv.FormatInt(int64(loFlowParams.SetVid), 16), |
| 262 | "SetPcp": loFlowParams.SetPcp, "numberofFlows": oFsm.numUniFlows, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 263 | "device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 264 | |
| 265 | //permanently store flow config for reconcile case |
| 266 | |
| 267 | if err := oFsm.pDeviceHandler.storePersUniFlowConfig(oFsm.pOnuUniPort.uniID, &oFsm.uniFlowParamsSlice); err != nil { |
| 268 | logger.Errorw(err.Error(), log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 269 | return err |
| 270 | } |
| 271 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 272 | pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm |
| 273 | if pConfigVlanStateBaseFsm.Is(vlanStConfigDone) { |
| 274 | //have to re-trigger the FSM to proceed with outstanding incremental flow configuration |
| 275 | // calling some FSM event must be decoupled |
| 276 | go func(a_pBaseFsm *fsm.FSM) { |
| 277 | _ = a_pBaseFsm.Event(vlanEvIncrFlowConfig) |
| 278 | }(pConfigVlanStateBaseFsm) |
| 279 | } // in all other states a new entry will be automatically considered later in that state or |
| 280 | // ignored as not anymore relevant |
| 281 | } else { |
| 282 | logger.Errorw("UniVlanConfigFsm flow limit exceeded", log.Fields{ |
| 283 | "device-id": oFsm.pAdaptFsm.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 284 | return fmt.Errorf(" UniVlanConfigFsm flow limit exceeded %s", oFsm.pAdaptFsm.deviceID) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | return nil |
| 288 | } |
| 289 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 290 | func (oFsm *UniVlanConfigFsm) enterConfigStarting(e *fsm.Event) { |
| 291 | logger.Debugw("UniVlanConfigFsm start", log.Fields{"in state": e.FSM.Current(), |
| 292 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 293 | |
| 294 | // this FSM is not intended for re-start, needs always new creation for a new run |
| 295 | oFsm.omciMIdsResponseReceived = make(chan bool) |
| 296 | // start go routine for processing of LockState messages |
| 297 | go oFsm.processOmciVlanMessages() |
| 298 | //let the state machine run forward from here directly |
| 299 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 300 | if pConfigVlanStateAFsm != nil { |
| 301 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 302 | go func(a_pAFsm *AdapterFsm) { |
| 303 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
| 304 | //stick to pythonAdapter numbering scheme |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 305 | oFsm.vtfdID = macBridgePortAniEID + oFsm.pOnuUniPort.entityID + oFsm.techProfileID |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 306 | //cmp also usage in EVTOCDE create in omci_cc |
| 307 | oFsm.evtocdID = macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo) |
| 308 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 309 | if oFsm.pUniTechProf.getTechProfileDone(oFsm.pOnuUniPort.uniID, oFsm.techProfileID) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 310 | // let the vlan processing begin |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 311 | _ = a_pAFsm.pFsm.Event(vlanEvStartConfig) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 312 | } else { |
| 313 | // set to waiting for Techprofile |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 314 | _ = a_pAFsm.pFsm.Event(vlanEvWaitTechProf) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | }(pConfigVlanStateAFsm) |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | func (oFsm *UniVlanConfigFsm) enterConfigVtfd(e *fsm.Event) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 322 | //mutex protection is required for possible concurrent access to FSM members |
| 323 | oFsm.mutexFlowParams.Lock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 324 | if oFsm.uniFlowParamsSlice[0].SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 325 | // meaning transparent setup - no specific VTFD setting required |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 326 | oFsm.mutexFlowParams.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 327 | logger.Debugw("UniVlanConfigFsm: no VTFD config required", log.Fields{ |
| 328 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 329 | // let the FSM proceed ... (from within this state all internal pointers may be expected to be correct) |
| 330 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 331 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 332 | go func(a_pAFsm *AdapterFsm) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 333 | _ = a_pAFsm.pFsm.Event(vlanEvRxConfigVtfd) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 334 | }(pConfigVlanStateAFsm) |
| 335 | } else { |
| 336 | logger.Debugw("UniVlanConfigFsm create VTFD", log.Fields{ |
| 337 | "EntitytId": strconv.FormatInt(int64(oFsm.vtfdID), 16), |
| 338 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 339 | oFsm.vlanFilterList[0] = uint16(oFsm.uniFlowParamsSlice[0].SetVid) // setVid is assumed to be masked already by the caller to 12 bit |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 340 | oFsm.mutexFlowParams.Unlock() |
| 341 | vtfdFilterList := make([]uint16, 12) //needed for parameter serialization |
| 342 | vtfdFilterList[0] = oFsm.vlanFilterList[0] |
| 343 | oFsm.numVlanFilterEntries = 1 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 344 | meParams := me.ParamData{ |
| 345 | EntityID: oFsm.vtfdID, |
| 346 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 347 | "VlanFilterList": vtfdFilterList, //omci lib wants a slice for serialization |
| 348 | "ForwardOperation": uint8(0x10), //VID investigation |
| 349 | "NumberOfEntries": oFsm.numVlanFilterEntries, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 350 | }, |
| 351 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 352 | logger.Debugw("UniVlanConfigFsm sendcreate VTFD", log.Fields{ |
| 353 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 354 | meInstance := oFsm.pOmciCC.sendCreateVtfdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 355 | oFsm.pAdaptFsm.commChan, meParams) |
| 356 | //accept also nil as (error) return value for writing to LastTx |
| 357 | // - this avoids misinterpretation of new received OMCI messages |
| 358 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 359 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 360 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
| 361 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | func (oFsm *UniVlanConfigFsm) enterConfigEvtocd(e *fsm.Event) { |
| 366 | logger.Debugw("UniVlanConfigFsm - start config EVTOCD loop", log.Fields{ |
| 367 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 368 | go oFsm.performConfigEvtocdEntries(0) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | func (oFsm *UniVlanConfigFsm) enterVlanConfigDone(e *fsm.Event) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 372 | logger.Debugw("UniVlanConfigFsm - checking on more flows", log.Fields{ |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 373 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 374 | oFsm.configuredUniFlow++ // one (more) flow configured |
| 375 | if oFsm.numUniFlows > oFsm.configuredUniFlow { |
| 376 | //some further flows are to be configured |
| 377 | // calling some FSM event must be decoupled |
| 378 | pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm |
| 379 | go func(a_pBaseFsm *fsm.FSM) { |
| 380 | _ = a_pBaseFsm.Event(vlanEvIncrFlowConfig) |
| 381 | }(pConfigVlanStateBaseFsm) |
| 382 | return |
| 383 | } |
| 384 | |
| 385 | logger.Debugw("UniVlanConfigFsm - VLAN config done: send dh event notification", log.Fields{ |
| 386 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 387 | // it might appear that some flows are requested also after 'flowPushed' event has been generated ... |
| 388 | // state transition notification is checked in deviceHandler |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 389 | if oFsm.pDeviceHandler != nil { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 390 | oFsm.pDeviceHandler.deviceProcStatusUpdate(oFsm.requestEvent) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 394 | func (oFsm *UniVlanConfigFsm) enterConfigIncrFlow(e *fsm.Event) { |
| 395 | logger.Debugw("UniVlanConfigFsm - start config further incremental flow", log.Fields{ |
| 396 | "in state": e.FSM.Current(), "recent flow-number": (oFsm.configuredUniFlow), |
| 397 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 398 | oFsm.mutexFlowParams.Lock() |
| 399 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 400 | if oFsm.uniFlowParamsSlice[oFsm.configuredUniFlow].SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 401 | // meaning transparent setup - no specific VTFD setting required |
| 402 | oFsm.mutexFlowParams.Unlock() |
| 403 | logger.Debugw("UniVlanConfigFsm: no VTFD config required", log.Fields{ |
| 404 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 405 | } else { |
| 406 | if oFsm.numVlanFilterEntries == 0 { |
| 407 | //no VTFD yet created |
| 408 | logger.Debugw("UniVlanConfigFsm create VTFD", log.Fields{ |
| 409 | "EntitytId": strconv.FormatInt(int64(oFsm.vtfdID), 16), |
| 410 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 411 | oFsm.vlanFilterList[0] = uint16(oFsm.uniFlowParamsSlice[oFsm.configuredUniFlow].SetVid) // setVid is assumed to be masked already by the caller to 12 bit |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 412 | oFsm.mutexFlowParams.Unlock() |
| 413 | vtfdFilterList := make([]uint16, 12) //needed for parameter serialization |
| 414 | vtfdFilterList[0] = oFsm.vlanFilterList[0] |
| 415 | oFsm.numVlanFilterEntries = 1 |
| 416 | meParams := me.ParamData{ |
| 417 | EntityID: oFsm.vtfdID, |
| 418 | Attributes: me.AttributeValueMap{ |
| 419 | "VlanFilterList": vtfdFilterList, |
| 420 | "ForwardOperation": uint8(0x10), //VID investigation |
| 421 | "NumberOfEntries": oFsm.numVlanFilterEntries, |
| 422 | }, |
| 423 | } |
| 424 | meInstance := oFsm.pOmciCC.sendCreateVtfdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 425 | oFsm.pAdaptFsm.commChan, meParams) |
| 426 | //accept also nil as (error) return value for writing to LastTx |
| 427 | // - this avoids misinterpretation of new received OMCI messages |
| 428 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 429 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 430 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
| 431 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 432 | } else { |
| 433 | //VTFD already exists - just modify by 'set' |
| 434 | //TODO!!: but only if the VID is not already present, skipped by now to test basic working |
| 435 | logger.Debugw("UniVlanConfigFsm set VTFD", log.Fields{ |
| 436 | "EntitytId": strconv.FormatInt(int64(oFsm.vtfdID), 16), |
| 437 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 438 | // setVid is assumed to be masked already by the caller to 12 bit |
| 439 | oFsm.vlanFilterList[oFsm.numVlanFilterEntries] = |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 440 | uint16(oFsm.uniFlowParamsSlice[oFsm.configuredUniFlow].SetVid) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 441 | oFsm.mutexFlowParams.Unlock() |
| 442 | vtfdFilterList := make([]uint16, 12) //needed for parameter serialization |
| 443 | for i := uint8(0); i <= oFsm.numVlanFilterEntries; i++ { |
| 444 | vtfdFilterList[i] = oFsm.vlanFilterList[i] |
| 445 | } |
| 446 | |
| 447 | oFsm.numVlanFilterEntries++ |
| 448 | meParams := me.ParamData{ |
| 449 | EntityID: oFsm.vtfdID, |
| 450 | Attributes: me.AttributeValueMap{ |
| 451 | "VlanFilterList": vtfdFilterList, |
| 452 | "NumberOfEntries": oFsm.numVlanFilterEntries, |
| 453 | }, |
| 454 | } |
| 455 | meInstance := oFsm.pOmciCC.sendSetVtfdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 456 | oFsm.pAdaptFsm.commChan, meParams) |
| 457 | //accept also nil as (error) return value for writing to LastTx |
| 458 | // - this avoids misinterpretation of new received OMCI messages |
| 459 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 460 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 461 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
| 462 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 463 | } |
| 464 | //verify response |
| 465 | err := oFsm.waitforOmciResponse() |
| 466 | if err != nil { |
| 467 | logger.Errorw("VTFD create/set failed, aborting VlanConfig FSM!", |
| 468 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 469 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 470 | return |
| 471 | } |
| 472 | } |
| 473 | go oFsm.performConfigEvtocdEntries(oFsm.configuredUniFlow) |
| 474 | } |
| 475 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 476 | func (oFsm *UniVlanConfigFsm) enterCleanVtfd(e *fsm.Event) { |
| 477 | logger.Debugw("UniVlanConfigFsm Tx Delete::VTFD", log.Fields{ |
| 478 | /*"EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),*/ |
| 479 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 480 | } |
| 481 | |
| 482 | func (oFsm *UniVlanConfigFsm) enterCleanEvtocd(e *fsm.Event) { |
| 483 | logger.Debugw("UniVlanConfigFsm cleanup EVTOCD", log.Fields{ |
| 484 | /*"EntitytId": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16), |
| 485 | "TPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),*/ |
| 486 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 487 | } |
| 488 | |
| 489 | func (oFsm *UniVlanConfigFsm) enterVlanCleanupDone(e *fsm.Event) { |
| 490 | logger.Debugw("UniVlanConfigFsm - VLAN cleanup done", log.Fields{ |
| 491 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 492 | |
| 493 | //let's reset the state machine in order to release all resources now |
| 494 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 495 | if pConfigVlanStateAFsm != nil { |
| 496 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 497 | go func(a_pAFsm *AdapterFsm) { |
| 498 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 499 | _ = a_pAFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 500 | } |
| 501 | }(pConfigVlanStateAFsm) |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | func (oFsm *UniVlanConfigFsm) enterResetting(e *fsm.Event) { |
| 506 | logger.Debugw("UniVlanConfigFsm resetting", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 507 | |
| 508 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 509 | if pConfigVlanStateAFsm != nil { |
| 510 | // abort running message processing |
| 511 | fsmAbortMsg := Message{ |
| 512 | Type: TestMsg, |
| 513 | Data: TestMessage{ |
| 514 | TestMessageVal: AbortMessageProcessing, |
| 515 | }, |
| 516 | } |
| 517 | pConfigVlanStateAFsm.commChan <- fsmAbortMsg |
| 518 | |
| 519 | //try to restart the FSM to 'disabled', decouple event transfer |
| 520 | go func(a_pAFsm *AdapterFsm) { |
| 521 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 522 | _ = a_pAFsm.pFsm.Event(vlanEvRestart) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 523 | } |
| 524 | }(pConfigVlanStateAFsm) |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | func (oFsm *UniVlanConfigFsm) enterDisabled(e *fsm.Event) { |
| 529 | logger.Debugw("UniVlanConfigFsm enters disabled state", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 530 | if oFsm.pDeviceHandler != nil { |
| 531 | //request removal of 'reference' in the Handler (completely clear the FSM) |
| 532 | go oFsm.pDeviceHandler.RemoveVlanFilterFsm(oFsm.pOnuUniPort) |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | func (oFsm *UniVlanConfigFsm) processOmciVlanMessages() { //ctx context.Context? |
| 537 | logger.Debugw("Start UniVlanConfigFsm Msg processing", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
| 538 | loop: |
| 539 | for { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 540 | // case <-ctx.Done(): |
| 541 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.pAdaptFsm.deviceID}) |
| 542 | // break loop |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 543 | message, ok := <-oFsm.pAdaptFsm.commChan |
| 544 | if !ok { |
| 545 | logger.Info("UniVlanConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 546 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
| 547 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 548 | break loop |
| 549 | } |
| 550 | logger.Debugw("UniVlanConfigFsm Rx Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 551 | |
| 552 | switch message.Type { |
| 553 | case TestMsg: |
| 554 | msg, _ := message.Data.(TestMessage) |
| 555 | if msg.TestMessageVal == AbortMessageProcessing { |
| 556 | logger.Infow("UniVlanConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 557 | break loop |
| 558 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 559 | logger.Warnw("UniVlanConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
| 560 | case OMCI: |
| 561 | msg, _ := message.Data.(OmciMessage) |
| 562 | oFsm.handleOmciVlanConfigMessage(msg) |
| 563 | default: |
| 564 | logger.Warn("UniVlanConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, |
| 565 | "message.Type": message.Type}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 566 | } |
| 567 | } |
| 568 | logger.Infow("End UniVlanConfigFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 569 | } |
| 570 | |
| 571 | func (oFsm *UniVlanConfigFsm) handleOmciVlanConfigMessage(msg OmciMessage) { |
| 572 | logger.Debugw("Rx OMCI UniVlanConfigFsm Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, |
| 573 | "msgType": msg.OmciMsg.MessageType}) |
| 574 | |
| 575 | switch msg.OmciMsg.MessageType { |
| 576 | case omci.CreateResponseType: |
| 577 | { |
| 578 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse) |
| 579 | if msgLayer == nil { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 580 | logger.Errorw("Omci Msg layer could not be detected for CreateResponse", |
| 581 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 582 | return |
| 583 | } |
| 584 | msgObj, msgOk := msgLayer.(*omci.CreateResponse) |
| 585 | if !msgOk { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 586 | logger.Errorw("Omci Msg layer could not be assigned for CreateResponse", |
| 587 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 588 | return |
| 589 | } |
| 590 | logger.Debugw("CreateResponse Data", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj}) |
| 591 | if msgObj.Result != me.Success { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 592 | logger.Errorw("Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, |
| 593 | "Error": msgObj.Result}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 594 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 595 | return |
| 596 | } |
| 597 | if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() && |
| 598 | msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() { |
| 599 | // maybe we can use just the same eventName for different state transitions like "forward" |
| 600 | // - might be checked, but so far I go for sure and have to inspect the concrete state events ... |
| 601 | switch oFsm.pOmciCC.pLastTxMeInstance.GetName() { |
| 602 | case "VlanTaggingFilterData": |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 603 | { |
| 604 | if oFsm.configuredUniFlow == 0 { |
| 605 | // Only if CreateResponse is received from first flow entry - let the FSM proceed ... |
| 606 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigVtfd) |
| 607 | } else { // let the MultiEntity config proceed by stopping the wait function |
| 608 | oFsm.omciMIdsResponseReceived <- true |
| 609 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | } |
| 613 | } //CreateResponseType |
| 614 | case omci.SetResponseType: |
| 615 | { |
| 616 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 617 | if msgLayer == nil { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 618 | logger.Errorw("UniVlanConfigFsm - Omci Msg layer could not be detected for SetResponse", |
| 619 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 620 | return |
| 621 | } |
| 622 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 623 | if !msgOk { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 624 | logger.Errorw("UniVlanConfigFsm - Omci Msg layer could not be assigned for SetResponse", |
| 625 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 626 | return |
| 627 | } |
| 628 | logger.Debugw("UniVlanConfigFsm SetResponse Data", log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj}) |
| 629 | if msgObj.Result != me.Success { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 630 | logger.Errorw("UniVlanConfigFsm - Omci SetResponse Error - later: drive FSM to abort state ?", |
| 631 | log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID, "Error": msgObj.Result}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 632 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 633 | return |
| 634 | } |
| 635 | if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() && |
| 636 | msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() { |
| 637 | switch oFsm.pOmciCC.pLastTxMeInstance.GetName() { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 638 | case "VlanTaggingFilterData", |
| 639 | "ExtendedVlanTaggingOperationConfigurationData": |
| 640 | { // let the MultiEntity config proceed by stopping the wait function |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 641 | oFsm.omciMIdsResponseReceived <- true |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | } //SetResponseType |
| 646 | default: |
| 647 | { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 648 | logger.Errorw("UniVlanConfigFsm - Rx OMCI unhandled MsgType", |
| 649 | log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "deviceId": oFsm.pAdaptFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 650 | return |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 655 | func (oFsm *UniVlanConfigFsm) performConfigEvtocdEntries(aFlowEntryNo uint8) { |
| 656 | if aFlowEntryNo == 0 { |
| 657 | // EthType set only at first flow element |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 658 | // EVTOCD ME is expected to exist at this point already from MIB-Download (with AssociationType/Pointer) |
| 659 | // we need to extend the configuration by EthType definition and, to be sure, downstream 'inverse' mode |
| 660 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD", log.Fields{ |
| 661 | "EntitytId": strconv.FormatInt(int64(oFsm.evtocdID), 16), |
| 662 | "i/oEthType": strconv.FormatInt(int64(cDefaultTpid), 16), |
| 663 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 664 | meParams := me.ParamData{ |
| 665 | EntityID: oFsm.evtocdID, |
| 666 | Attributes: me.AttributeValueMap{ |
| 667 | "InputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base |
| 668 | "OutputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base |
| 669 | "DownstreamMode": uint8(cDefaultDownstreamMode), |
| 670 | }, |
| 671 | } |
| 672 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 673 | oFsm.pAdaptFsm.commChan, meParams) |
| 674 | //accept also nil as (error) return value for writing to LastTx |
| 675 | // - this avoids misinterpretation of new received OMCI messages |
| 676 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 677 | |
| 678 | //verify response |
| 679 | err := oFsm.waitforOmciResponse() |
| 680 | if err != nil { |
| 681 | logger.Errorw("Evtocd set TPID failed, aborting VlanConfig FSM!", |
| 682 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 683 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 684 | return |
| 685 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 686 | } //first flow element |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 687 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 688 | oFsm.mutexFlowParams.Lock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 689 | if oFsm.uniFlowParamsSlice[aFlowEntryNo].SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 690 | //transparent transmission required |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 691 | oFsm.mutexFlowParams.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 692 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD single tagged transparent rule", log.Fields{ |
| 693 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 694 | sliceEvtocdRule := make([]uint8, 16) |
| 695 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 696 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 697 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 698 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 699 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 700 | |
| 701 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 702 | cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule |
| 703 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 704 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 705 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 706 | |
| 707 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 708 | 0<<cTreatTTROffset| // Do not pop any tags |
| 709 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 710 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 711 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 712 | |
| 713 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 714 | cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag |
| 715 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 716 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 717 | |
| 718 | meParams := me.ParamData{ |
| 719 | EntityID: oFsm.evtocdID, |
| 720 | Attributes: me.AttributeValueMap{ |
| 721 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 722 | }, |
| 723 | } |
| 724 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 725 | oFsm.pAdaptFsm.commChan, meParams) |
| 726 | //accept also nil as (error) return value for writing to LastTx |
| 727 | // - this avoids misinterpretation of new received OMCI messages |
| 728 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 729 | |
| 730 | //verify response |
| 731 | err := oFsm.waitforOmciResponse() |
| 732 | if err != nil { |
| 733 | logger.Errorw("Evtocd set transparent singletagged rule failed, aborting VlanConfig FSM!", |
| 734 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 735 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 736 | return |
| 737 | } |
| 738 | } else { |
| 739 | // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario |
| 740 | if oFsm.acceptIncrementalEvtoOption { |
| 741 | // this defines VID translation scenario: singletagged->singletagged (if not transparent) |
| 742 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD single tagged translation rule", log.Fields{ |
| 743 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 744 | sliceEvtocdRule := make([]uint8, 16) |
| 745 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 746 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 747 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 748 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 749 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 750 | |
| 751 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 752 | oFsm.uniFlowParamsSlice[aFlowEntryNo].MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN |
| 753 | oFsm.uniFlowParamsSlice[aFlowEntryNo].MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 754 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 755 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 756 | |
| 757 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 758 | oFsm.uniFlowParamsSlice[aFlowEntryNo].TagsToRemove<<cTreatTTROffset| // either 1 or 0 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 759 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 760 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 761 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 762 | |
| 763 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 764 | oFsm.uniFlowParamsSlice[aFlowEntryNo].SetPcp<<cTreatPrioOffset| // as configured in flow |
| 765 | oFsm.uniFlowParamsSlice[aFlowEntryNo].SetVid<<cTreatVidOffset| //as configured in flow |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 766 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 767 | oFsm.mutexFlowParams.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 768 | |
| 769 | meParams := me.ParamData{ |
| 770 | EntityID: oFsm.evtocdID, |
| 771 | Attributes: me.AttributeValueMap{ |
| 772 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 773 | }, |
| 774 | } |
| 775 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 776 | oFsm.pAdaptFsm.commChan, meParams) |
| 777 | //accept also nil as (error) return value for writing to LastTx |
| 778 | // - this avoids misinterpretation of new received OMCI messages |
| 779 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 780 | |
| 781 | //verify response |
| 782 | err := oFsm.waitforOmciResponse() |
| 783 | if err != nil { |
| 784 | logger.Errorw("Evtocd set singletagged translation rule failed, aborting VlanConfig FSM!", |
| 785 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 786 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 787 | return |
| 788 | } |
| 789 | } else { |
| 790 | //not transparent and not acceptIncrementalEvtoOption untagged/priotagged->singletagged |
| 791 | { // just for local var's |
| 792 | // this defines stacking scenario: untagged->singletagged |
| 793 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD untagged->singletagged rule", log.Fields{ |
| 794 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 795 | sliceEvtocdRule := make([]uint8, 16) |
| 796 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 797 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 798 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 799 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 800 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 801 | |
| 802 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 803 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an inner-tag rule |
| 804 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 805 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 806 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 807 | |
| 808 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 809 | 0<<cTreatTTROffset| // Do not pop any tags |
| 810 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 811 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 812 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 813 | |
| 814 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 815 | 0<<cTreatPrioOffset| // vlan prio set to 0 |
| 816 | // (as done in Py code, maybe better option would be setPcp here, which still could be 0?) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 817 | oFsm.uniFlowParamsSlice[aFlowEntryNo].SetVid<<cTreatVidOffset| // Outer VID don't care |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 818 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 819 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 820 | oFsm.mutexFlowParams.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 821 | meParams := me.ParamData{ |
| 822 | EntityID: oFsm.evtocdID, |
| 823 | Attributes: me.AttributeValueMap{ |
| 824 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 825 | }, |
| 826 | } |
| 827 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 828 | oFsm.pAdaptFsm.commChan, meParams) |
| 829 | //accept also nil as (error) return value for writing to LastTx |
| 830 | // - this avoids misinterpretation of new received OMCI messages |
| 831 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 832 | |
| 833 | //verify response |
| 834 | err := oFsm.waitforOmciResponse() |
| 835 | if err != nil { |
| 836 | logger.Errorw("Evtocd set untagged->singletagged rule failed, aborting VlanConfig FSM!", |
| 837 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 838 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 839 | return |
| 840 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 841 | } // just for local var's |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 842 | { // just for local var's |
| 843 | // this defines 'stacking' scenario: priotagged->singletagged |
| 844 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD priotagged->singletagged rule", log.Fields{ |
| 845 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 846 | sliceEvtocdRule := make([]uint8, 16) |
| 847 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 848 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 849 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 850 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 851 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 852 | |
| 853 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 854 | cPrioDoNotFilter<<cFilterPrioOffset| // Do not Filter on innerprio |
| 855 | 0<<cFilterVidOffset| // filter on inner vid 0 (prioTagged) |
| 856 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 857 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 858 | |
| 859 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 860 | 1<<cTreatTTROffset| // pop the prio-tag |
| 861 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 862 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 863 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 864 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 865 | oFsm.mutexFlowParams.Lock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 866 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 867 | cCopyPrioFromInner<<cTreatPrioOffset| // vlan copy from PrioTag |
| 868 | // (as done in Py code, maybe better option would be setPcp here, which still could be PrioCopy?) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 869 | oFsm.uniFlowParamsSlice[aFlowEntryNo].SetVid<<cTreatVidOffset| // Outer VID as configured |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 870 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 871 | oFsm.mutexFlowParams.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 872 | |
| 873 | meParams := me.ParamData{ |
| 874 | EntityID: oFsm.evtocdID, |
| 875 | Attributes: me.AttributeValueMap{ |
| 876 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 877 | }, |
| 878 | } |
| 879 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 880 | oFsm.pAdaptFsm.commChan, meParams) |
| 881 | //accept also nil as (error) return value for writing to LastTx |
| 882 | // - this avoids misinterpretation of new received OMCI messages |
| 883 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 884 | |
| 885 | //verify response |
| 886 | err := oFsm.waitforOmciResponse() |
| 887 | if err != nil { |
| 888 | logger.Errorw("Evtocd set priotagged->singletagged rule failed, aborting VlanConfig FSM!", |
| 889 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 890 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 891 | return |
| 892 | } |
| 893 | } //just for local var's |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | // if Config has been done for all GemPort instances let the FSM proceed |
| 898 | 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] | 899 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigEvtocd) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | func (oFsm *UniVlanConfigFsm) waitforOmciResponse() error { |
| 903 | select { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 904 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 905 | // case <-ctx.Done(): |
| 906 | // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
| 907 | case <-time.After(30 * time.Second): //AS FOR THE OTHER OMCI FSM's |
| 908 | logger.Warnw("UniVlanConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 909 | return fmt.Errorf("uniVlanConfigFsm multi entity timeout %s", oFsm.pAdaptFsm.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 910 | case success := <-oFsm.omciMIdsResponseReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 911 | if success { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 912 | logger.Debug("UniVlanConfigFsm multi entity response received") |
| 913 | return nil |
| 914 | } |
| 915 | // should not happen so far |
| 916 | logger.Warnw("UniVlanConfigFsm multi entity response error", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 917 | return fmt.Errorf("uniVlanConfigFsm multi entity responseError %s", oFsm.pAdaptFsm.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 918 | } |
| 919 | } |