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 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 28 | gp "github.com/google/gopacket" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 29 | "github.com/looplab/fsm" |
| 30 | "github.com/opencord/omci-lib-go" |
| 31 | me "github.com/opencord/omci-lib-go/generated" |
| 32 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 33 | of "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 34 | ) |
| 35 | |
| 36 | const ( |
| 37 | // internal predefined values |
| 38 | cDefaultDownstreamMode = 0 |
| 39 | cDefaultTpid = 0x8100 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 40 | cVtfdTableSize = 12 //as per G.988 |
| 41 | cMaxAllowedFlows = cVtfdTableSize //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] | 42 | ) |
| 43 | |
| 44 | const ( |
| 45 | // bit mask offsets for EVTOCD VlanTaggingOperationTable related to 32 bits (4 bytes) |
| 46 | cFilterPrioOffset = 28 |
| 47 | cFilterVidOffset = 15 |
| 48 | cFilterTpidOffset = 12 |
| 49 | cFilterEtherTypeOffset = 0 |
| 50 | cTreatTTROffset = 30 |
| 51 | cTreatPrioOffset = 16 |
| 52 | cTreatVidOffset = 3 |
| 53 | cTreatTpidOffset = 0 |
| 54 | ) |
| 55 | const ( |
| 56 | // byte offsets for EVTOCD VlanTaggingOperationTable related to overall 16 byte size with slice byte 0 as first Byte (MSB) |
| 57 | cFilterOuterOffset = 0 |
| 58 | cFilterInnerOffset = 4 |
| 59 | cTreatOuterOffset = 8 |
| 60 | cTreatInnerOffset = 12 |
| 61 | ) |
| 62 | const ( |
| 63 | // basic values used within EVTOCD VlanTaggingOperationTable in respect to their bitfields |
| 64 | cPrioIgnoreTag uint32 = 15 |
| 65 | cPrioDefaultFilter uint32 = 14 |
| 66 | cPrioDoNotFilter uint32 = 8 |
| 67 | cDoNotFilterVid uint32 = 4096 |
| 68 | cDoNotFilterTPID uint32 = 0 |
| 69 | cDoNotFilterEtherType uint32 = 0 |
| 70 | cDoNotAddPrio uint32 = 15 |
| 71 | cCopyPrioFromInner uint32 = 8 |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 72 | //cDontCarePrio uint32 = 0 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 73 | cDontCareVid uint32 = 0 |
| 74 | cDontCareTpid uint32 = 0 |
| 75 | cSetOutputTpidCopyDei uint32 = 4 |
| 76 | ) |
| 77 | |
| 78 | const ( |
| 79 | // events of config PON ANI port FSM |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 80 | vlanEvStart = "vlanEvStart" |
| 81 | vlanEvWaitTechProf = "vlanEvWaitTechProf" |
| 82 | vlanEvContinueConfig = "vlanEvContinueConfig" |
| 83 | vlanEvStartConfig = "vlanEvStartConfig" |
| 84 | vlanEvRxConfigVtfd = "vlanEvRxConfigVtfd" |
| 85 | vlanEvRxConfigEvtocd = "vlanEvRxConfigEvtocd" |
| 86 | vlanEvIncrFlowConfig = "vlanEvIncrFlowConfig" |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 87 | vlanEvRenew = "vlanEvRenew" |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 88 | vlanEvRemFlowConfig = "vlanEvRemFlowConfig" |
| 89 | vlanEvRemFlowDone = "vlanEvRemFlowDone" |
| 90 | vlanEvFlowDataRemoved = "vlanEvFlowDataRemoved" |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 91 | //vlanEvTimeoutSimple = "vlanEvTimeoutSimple" |
| 92 | //vlanEvTimeoutMids = "vlanEvTimeoutMids" |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 93 | vlanEvReset = "vlanEvReset" |
| 94 | vlanEvRestart = "vlanEvRestart" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 95 | ) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 96 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 97 | const ( |
| 98 | // states of config PON ANI port FSM |
| 99 | vlanStDisabled = "vlanStDisabled" |
| 100 | vlanStStarting = "vlanStStarting" |
| 101 | vlanStWaitingTechProf = "vlanStWaitingTechProf" |
| 102 | vlanStConfigVtfd = "vlanStConfigVtfd" |
| 103 | vlanStConfigEvtocd = "vlanStConfigEvtocd" |
| 104 | vlanStConfigDone = "vlanStConfigDone" |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 105 | vlanStConfigIncrFlow = "vlanStConfigIncrFlow" |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 106 | vlanStRemoveFlow = "vlanStRemoveFlow" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 107 | vlanStCleanupDone = "vlanStCleanupDone" |
| 108 | vlanStResetting = "vlanStResetting" |
| 109 | ) |
| 110 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 111 | type uniVlanRuleParams struct { |
| 112 | TpID uint16 `json:"tp_id"` |
| 113 | MatchVid uint32 `json:"match_vid"` //use uint32 types for allowing immediate bitshifting |
| 114 | MatchPcp uint32 `json:"match_pcp"` |
| 115 | TagsToRemove uint32 `json:"tags_to_remove"` |
| 116 | SetVid uint32 `json:"set_vid"` |
| 117 | SetPcp uint32 `json:"set_pcp"` |
| 118 | } |
| 119 | |
| 120 | type uniVlanFlowParams struct { |
| 121 | CookieSlice []uint64 `json:"cookie_slice"` |
| 122 | VlanRuleParams uniVlanRuleParams `json:"vlan_rule_params"` |
| 123 | } |
| 124 | |
| 125 | type uniRemoveVlanFlowParams struct { |
| 126 | cookie uint64 //just the last cookie valid for removal |
| 127 | vlanRuleParams uniVlanRuleParams |
| 128 | } |
| 129 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 130 | //UniVlanConfigFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI |
| 131 | type UniVlanConfigFsm struct { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 132 | pDeviceHandler *deviceHandler |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 133 | deviceID string |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 134 | pOmciCC *omciCC |
| 135 | pOnuUniPort *onuUniPort |
| 136 | pUniTechProf *onuUniTechProf |
| 137 | pOnuDB *onuDeviceDB |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 138 | techProfileID uint16 |
| 139 | requestEvent OnuDeviceEvent |
| 140 | omciMIdsResponseReceived chan bool //seperate channel needed for checking multiInstance OMCI message responses |
| 141 | pAdaptFsm *AdapterFsm |
| 142 | acceptIncrementalEvtoOption bool |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 143 | mutexFlowParams sync.Mutex |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 144 | uniVlanFlowParamsSlice []uniVlanFlowParams |
| 145 | uniRemoveFlowsSlice []uniRemoveVlanFlowParams |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 146 | numUniFlows uint8 // expected number of flows should be less than 12 |
| 147 | configuredUniFlow uint8 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 148 | numRemoveFlows uint8 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 149 | numVlanFilterEntries uint8 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 150 | vlanFilterList [cVtfdTableSize]uint16 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 151 | vtfdID uint16 |
| 152 | evtocdID uint16 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 153 | pLastTxMeInstance *me.ManagedEntity |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 154 | requestEventOffset uint8 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 155 | } |
| 156 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 157 | //NewUniVlanConfigFsm is the 'constructor' for the state machine to config the PON ANI ports |
| 158 | // of ONU UNI ports via OMCI |
| 159 | func NewUniVlanConfigFsm(apDeviceHandler *deviceHandler, apDevOmciCC *omciCC, apUniPort *onuUniPort, |
| 160 | apUniTechProf *onuUniTechProf, apOnuDB *onuDeviceDB, aTechProfileID uint16, |
| 161 | aRequestEvent OnuDeviceEvent, aName string, aCommChannel chan Message, aAcceptIncrementalEvto bool, |
| 162 | aCookieSlice []uint64, aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) *UniVlanConfigFsm { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 163 | instFsm := &UniVlanConfigFsm{ |
| 164 | pDeviceHandler: apDeviceHandler, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 165 | deviceID: apDeviceHandler.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 166 | pOmciCC: apDevOmciCC, |
| 167 | pOnuUniPort: apUniPort, |
| 168 | pUniTechProf: apUniTechProf, |
| 169 | pOnuDB: apOnuDB, |
| 170 | techProfileID: aTechProfileID, |
| 171 | requestEvent: aRequestEvent, |
| 172 | acceptIncrementalEvtoOption: aAcceptIncrementalEvto, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 173 | numUniFlows: 0, |
| 174 | configuredUniFlow: 0, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 175 | numRemoveFlows: 0, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 176 | } |
| 177 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 178 | instFsm.pAdaptFsm = NewAdapterFsm(aName, instFsm.deviceID, aCommChannel) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 179 | if instFsm.pAdaptFsm == nil { |
| 180 | logger.Errorw("UniVlanConfigFsm's AdapterFsm could not be instantiated!!", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 181 | "device-id": instFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 182 | return nil |
| 183 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 184 | instFsm.pAdaptFsm.pFsm = fsm.NewFSM( |
| 185 | vlanStDisabled, |
| 186 | fsm.Events{ |
| 187 | {Name: vlanEvStart, Src: []string{vlanStDisabled}, Dst: vlanStStarting}, |
| 188 | {Name: vlanEvWaitTechProf, Src: []string{vlanStStarting}, Dst: vlanStWaitingTechProf}, |
| 189 | {Name: vlanEvContinueConfig, Src: []string{vlanStWaitingTechProf}, Dst: vlanStConfigVtfd}, |
| 190 | {Name: vlanEvStartConfig, Src: []string{vlanStStarting}, Dst: vlanStConfigVtfd}, |
| 191 | {Name: vlanEvRxConfigVtfd, Src: []string{vlanStConfigVtfd}, Dst: vlanStConfigEvtocd}, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 192 | {Name: vlanEvRxConfigEvtocd, Src: []string{vlanStConfigEvtocd, vlanStConfigIncrFlow}, |
| 193 | Dst: vlanStConfigDone}, |
| 194 | {Name: vlanEvIncrFlowConfig, Src: []string{vlanStConfigDone}, Dst: vlanStConfigIncrFlow}, |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 195 | {Name: vlanEvRenew, Src: []string{vlanStConfigIncrFlow}, Dst: vlanStStarting}, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 196 | {Name: vlanEvRemFlowConfig, Src: []string{vlanStConfigDone}, Dst: vlanStRemoveFlow}, |
| 197 | {Name: vlanEvRemFlowDone, Src: []string{vlanStRemoveFlow}, Dst: vlanStCleanupDone}, |
| 198 | {Name: vlanEvFlowDataRemoved, Src: []string{vlanStCleanupDone}, Dst: vlanStConfigDone}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 199 | /* |
| 200 | {Name: vlanEvTimeoutSimple, Src: []string{ |
| 201 | vlanStCreatingDot1PMapper, vlanStCreatingMBPCD, vlanStSettingTconts, vlanStSettingDot1PMapper}, Dst: vlanStStarting}, |
| 202 | {Name: vlanEvTimeoutMids, Src: []string{ |
| 203 | vlanStCreatingGemNCTPs, vlanStCreatingGemIWs, vlanStSettingPQs}, Dst: vlanStStarting}, |
| 204 | */ |
| 205 | // exceptional treatment for all states except vlanStResetting |
| 206 | {Name: vlanEvReset, Src: []string{vlanStStarting, vlanStWaitingTechProf, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 207 | vlanStConfigVtfd, vlanStConfigEvtocd, vlanStConfigDone, vlanStConfigIncrFlow, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 208 | vlanStRemoveFlow, vlanStCleanupDone}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 209 | Dst: vlanStResetting}, |
| 210 | // the only way to get to resource-cleared disabled state again is via "resseting" |
| 211 | {Name: vlanEvRestart, Src: []string{vlanStResetting}, Dst: vlanStDisabled}, |
| 212 | }, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 213 | fsm.Callbacks{ |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 214 | "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) }, |
| 215 | ("enter_" + vlanStStarting): func(e *fsm.Event) { instFsm.enterConfigStarting(e) }, |
| 216 | ("enter_" + vlanStConfigVtfd): func(e *fsm.Event) { instFsm.enterConfigVtfd(e) }, |
| 217 | ("enter_" + vlanStConfigEvtocd): func(e *fsm.Event) { instFsm.enterConfigEvtocd(e) }, |
| 218 | ("enter_" + vlanStConfigDone): func(e *fsm.Event) { instFsm.enterVlanConfigDone(e) }, |
| 219 | ("enter_" + vlanStConfigIncrFlow): func(e *fsm.Event) { instFsm.enterConfigIncrFlow(e) }, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 220 | ("enter_" + vlanStRemoveFlow): func(e *fsm.Event) { instFsm.enterRemoveFlow(e) }, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 221 | ("enter_" + vlanStCleanupDone): func(e *fsm.Event) { instFsm.enterVlanCleanupDone(e) }, |
| 222 | ("enter_" + vlanStResetting): func(e *fsm.Event) { instFsm.enterResetting(e) }, |
| 223 | ("enter_" + vlanStDisabled): func(e *fsm.Event) { instFsm.enterDisabled(e) }, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 224 | }, |
| 225 | ) |
| 226 | if instFsm.pAdaptFsm.pFsm == nil { |
| 227 | logger.Errorw("UniVlanConfigFsm's Base FSM could not be instantiated!!", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 228 | "device-id": instFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 229 | return nil |
| 230 | } |
| 231 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 232 | _ = instFsm.initUniFlowParams(aTechProfileID, aCookieSlice, aMatchVlan, aSetVlan, aSetPcp) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 233 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 234 | logger.Infow("UniVlanConfigFsm created", log.Fields{"device-id": instFsm.deviceID, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 235 | "accIncrEvto": instFsm.acceptIncrementalEvtoOption}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 236 | return instFsm |
| 237 | } |
| 238 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 239 | //initUniFlowParams is a simplified form of SetUniFlowParams() used for first flow parameters configuration |
| 240 | func (oFsm *UniVlanConfigFsm) initUniFlowParams(aTpID uint16, aCookieSlice []uint64, |
| 241 | aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) error { |
| 242 | loRuleParams := uniVlanRuleParams{ |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 243 | TpID: aTpID, |
| 244 | MatchVid: uint32(aMatchVlan), |
| 245 | SetVid: uint32(aSetVlan), |
| 246 | SetPcp: uint32(aSetPcp), |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 247 | } |
| 248 | // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 249 | loRuleParams.TagsToRemove = 1 //one tag to remove as default setting |
| 250 | loRuleParams.MatchPcp = cPrioDoNotFilter // do not Filter on prio as default |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 251 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 252 | if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 253 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 254 | loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 255 | //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther) |
| 256 | } else { |
| 257 | if !oFsm.acceptIncrementalEvtoOption { |
| 258 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 259 | loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 263 | if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 264 | // no prio/vid filtering requested |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 265 | loRuleParams.TagsToRemove = 0 //no tag pop action |
| 266 | loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering |
| 267 | if loRuleParams.SetPcp == cCopyPrioFromInner { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 268 | //in case of no filtering and configured PrioCopy ensure default prio setting to 0 |
| 269 | // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged |
| 270 | // might collide with NoMatchVid/CopyPrio(/setVid) setting |
| 271 | // this was some precondition setting taken over from py adapter .. |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 272 | loRuleParams.SetPcp = 0 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 273 | } |
| 274 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 275 | |
| 276 | loFlowParams := uniVlanFlowParams{VlanRuleParams: loRuleParams} |
| 277 | loFlowParams.CookieSlice = make([]uint64, 0) |
| 278 | loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...) |
| 279 | |
| 280 | //no mutex protection is required for initial access and adding the first flow is always possible |
| 281 | oFsm.uniVlanFlowParamsSlice = make([]uniVlanFlowParams, 0) |
| 282 | oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams) |
| 283 | logger.Debugw("first UniVlanConfigFsm flow added", log.Fields{ |
| 284 | "Cookies": oFsm.uniVlanFlowParamsSlice[0].CookieSlice, |
| 285 | "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16), |
| 286 | "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16), |
| 287 | "SetPcp": loRuleParams.SetPcp, |
| 288 | "device-id": oFsm.deviceID}) |
| 289 | oFsm.numUniFlows = 1 |
| 290 | oFsm.uniRemoveFlowsSlice = make([]uniRemoveVlanFlowParams, 0) //initially nothing to remove |
| 291 | |
| 292 | //permanently store flow config for reconcile case |
| 293 | if err := oFsm.pDeviceHandler.storePersUniFlowConfig(oFsm.pOnuUniPort.uniID, |
| 294 | &oFsm.uniVlanFlowParamsSlice); err != nil { |
| 295 | logger.Errorw(err.Error(), log.Fields{"device-id": oFsm.deviceID}) |
| 296 | return err |
| 297 | } |
| 298 | |
| 299 | return nil |
| 300 | } |
| 301 | |
| 302 | //SetUniFlowParams verifies on existence of flow parameters to be configured, |
| 303 | // optionally udates the cookie list or appends a new flow if there is space |
| 304 | // if possible the FSM is trigggerd to start with the processing |
| 305 | func (oFsm *UniVlanConfigFsm) SetUniFlowParams(aTpID uint16, aCookieSlice []uint64, |
| 306 | aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8) error { |
| 307 | loRuleParams := uniVlanRuleParams{ |
| 308 | TpID: aTpID, |
| 309 | MatchVid: uint32(aMatchVlan), |
| 310 | SetVid: uint32(aSetVlan), |
| 311 | SetPcp: uint32(aSetPcp), |
| 312 | } |
| 313 | // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters |
| 314 | loRuleParams.TagsToRemove = 1 //one tag to remove as default setting |
| 315 | loRuleParams.MatchPcp = cPrioDoNotFilter // do not Filter on prio as default |
| 316 | |
| 317 | if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 318 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
| 319 | loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
| 320 | //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther) |
| 321 | } else { |
| 322 | if !oFsm.acceptIncrementalEvtoOption { |
| 323 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
| 324 | loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 329 | // no prio/vid filtering requested |
| 330 | loRuleParams.TagsToRemove = 0 //no tag pop action |
| 331 | loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering |
| 332 | if loRuleParams.SetPcp == cCopyPrioFromInner { |
| 333 | //in case of no filtering and configured PrioCopy ensure default prio setting to 0 |
| 334 | // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged |
| 335 | // might collide with NoMatchVid/CopyPrio(/setVid) setting |
| 336 | // this was some precondition setting taken over from py adapter .. |
| 337 | loRuleParams.SetPcp = 0 |
| 338 | } |
| 339 | } |
| 340 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 341 | flowEntryMatch := false |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 342 | flowCookieModify := false |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 343 | //mutex protection is required for possible concurrent access to FSM members |
| 344 | oFsm.mutexFlowParams.Lock() |
| 345 | defer oFsm.mutexFlowParams.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 346 | for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
| 347 | //TODO: Verify if using e.g. hashes for the structures here for comparison may generate |
| 348 | // countable run time optimization (perhaps with including the hash in kvStore storage?) |
| 349 | if storedUniFlowParams.VlanRuleParams == loRuleParams { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 350 | flowEntryMatch = true |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 351 | logger.Debugw("UniVlanConfigFsm flow setting - rule already exists", log.Fields{ |
| 352 | "device-id": oFsm.deviceID}) |
| 353 | var cookieMatch bool |
| 354 | for _, newCookie := range aCookieSlice { // for all cookies available in the arguments |
| 355 | cookieMatch = false |
| 356 | for _, cookie := range storedUniFlowParams.CookieSlice { |
| 357 | if cookie == newCookie { |
| 358 | logger.Debugw("UniVlanConfigFsm flow setting - and cookie already exists", log.Fields{ |
| 359 | "device-id": oFsm.deviceID, "cookie": cookie}) |
| 360 | cookieMatch = true |
| 361 | break //found new cookie - no further search for this requested cookie |
| 362 | } |
| 363 | } |
| 364 | if !cookieMatch { |
| 365 | logger.Debugw("UniVlanConfigFsm flow setting -adding new cookie", log.Fields{ |
| 366 | "device-id": oFsm.deviceID, "cookie": newCookie}) |
| 367 | //as range works with copies of the slice we have to write to the original slice!! |
| 368 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(oFsm.uniVlanFlowParamsSlice[flow].CookieSlice, |
| 369 | newCookie) |
| 370 | flowCookieModify = true |
| 371 | } |
| 372 | } //for all new cookies |
| 373 | break // found rule - no further rule search |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 374 | } |
| 375 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 376 | if !flowEntryMatch { //it is a new rule |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 377 | if oFsm.numUniFlows < cMaxAllowedFlows { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 378 | loFlowParams := uniVlanFlowParams{VlanRuleParams: loRuleParams} |
| 379 | loFlowParams.CookieSlice = make([]uint64, 0) |
| 380 | loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...) |
| 381 | oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams) |
| 382 | logger.Debugw("UniVlanConfigFsm flow add", log.Fields{ |
| 383 | "Cookies": oFsm.uniVlanFlowParamsSlice[oFsm.numUniFlows].CookieSlice, |
| 384 | "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16), |
| 385 | "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16), |
| 386 | "SetPcp": loRuleParams.SetPcp, "numberofFlows": (oFsm.numUniFlows + 1), |
| 387 | "device-id": oFsm.deviceID}) |
| 388 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 389 | oFsm.numUniFlows++ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 390 | // note: theoretical it would be possible to clear the same rule from the remove slice |
| 391 | // (for entries that have not yet been started with removal) |
| 392 | // but that is getting quite complicated - maybe a future optimization in case it should prove reasonable |
| 393 | // anyway the precondition here is that the FSM checks for rules to delete first and adds new rules afterwards |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 394 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 395 | pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm |
| 396 | if pConfigVlanStateBaseFsm.Is(vlanStConfigDone) { |
| 397 | //have to re-trigger the FSM to proceed with outstanding incremental flow configuration |
| 398 | // calling some FSM event must be decoupled |
| 399 | go func(a_pBaseFsm *fsm.FSM) { |
| 400 | _ = a_pBaseFsm.Event(vlanEvIncrFlowConfig) |
| 401 | }(pConfigVlanStateBaseFsm) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 402 | } // if not in the appropriate state a new entry will be automatically considered later |
| 403 | // when the configDone state is reached |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 404 | } else { |
| 405 | logger.Errorw("UniVlanConfigFsm flow limit exceeded", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 406 | "device-id": oFsm.deviceID, "flow-number": oFsm.numUniFlows}) |
| 407 | return fmt.Errorf(" UniVlanConfigFsm flow limit exceeded %s", oFsm.deviceID) |
| 408 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 409 | } else { |
| 410 | // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately |
| 411 | if oFsm.numUniFlows == oFsm.configuredUniFlow { |
| 412 | //all requested rules really have been configured |
| 413 | // state transition notification is checked in deviceHandler |
| 414 | if oFsm.pDeviceHandler != nil { |
| 415 | //also the related TechProfile was already configured |
| 416 | logger.Debugw("UniVlanConfigFsm rule already set - send immediate add-success event for reason update", log.Fields{ |
| 417 | "device-id": oFsm.deviceID}) |
| 418 | go oFsm.pDeviceHandler.deviceProcStatusUpdate(oFsm.requestEvent) |
| 419 | } |
| 420 | } else { |
| 421 | // avoid device reason update as the rule config connected to this flow may still be in progress |
| 422 | // and the device reason should only be updated on success of rule config |
| 423 | logger.Debugw("UniVlanConfigFsm rule already set but configuration ongoing, suppress early add-success event for reason update", |
| 424 | log.Fields{"device-id": oFsm.deviceID, |
| 425 | "NumberofRules": oFsm.numUniFlows, "Configured rules": oFsm.configuredUniFlow}) |
| 426 | } |
| 427 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 428 | |
| 429 | if !flowEntryMatch || flowCookieModify { // some change was done to the flow entries |
| 430 | //permanently store flow config for reconcile case |
| 431 | if err := oFsm.pDeviceHandler.storePersUniFlowConfig(oFsm.pOnuUniPort.uniID, &oFsm.uniVlanFlowParamsSlice); err != nil { |
| 432 | logger.Errorw(err.Error(), log.Fields{"device-id": oFsm.deviceID}) |
| 433 | return err |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | return nil |
| 437 | } |
| 438 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 439 | //RemoveUniFlowParams verifies on existence of flow cookie, |
| 440 | // if found removes cookie from flow cookie list and if this is empty |
| 441 | // initiates removal of the flow related configuration from the ONU (via OMCI) |
| 442 | func (oFsm *UniVlanConfigFsm) RemoveUniFlowParams(aCookie uint64) error { |
| 443 | flowCookieMatch := false |
| 444 | //mutex protection is required for possible concurrent access to FSM members |
| 445 | oFsm.mutexFlowParams.Lock() |
| 446 | defer oFsm.mutexFlowParams.Unlock() |
| 447 | for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
| 448 | for i, cookie := range storedUniFlowParams.CookieSlice { |
| 449 | if cookie == aCookie { |
| 450 | logger.Debugw("UniVlanConfigFsm flow removal - cookie found", log.Fields{ |
| 451 | "device-id": oFsm.deviceID, "cookie": cookie}) |
| 452 | flowCookieMatch = true |
| 453 | |
| 454 | //remove the cookie from the cookie slice and verify it is getting empty |
| 455 | if len(storedUniFlowParams.CookieSlice) == 1 { |
| 456 | logger.Debugw("UniVlanConfigFsm flow removal - full flow removal", log.Fields{ |
| 457 | "device-id": oFsm.deviceID}) |
| 458 | oFsm.numUniFlows-- |
| 459 | |
| 460 | //create a new element for the removeVlanFlow slice |
| 461 | loRemoveParams := uniRemoveVlanFlowParams{ |
| 462 | vlanRuleParams: storedUniFlowParams.VlanRuleParams, |
| 463 | cookie: storedUniFlowParams.CookieSlice[0], |
| 464 | } |
| 465 | oFsm.uniRemoveFlowsSlice = append(oFsm.uniRemoveFlowsSlice, loRemoveParams) |
| 466 | |
| 467 | //and remove the actual element from the addVlanFlow slice |
| 468 | // oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = nil //automatically done by garbage collector |
| 469 | if len(oFsm.uniVlanFlowParamsSlice) <= 1 { |
| 470 | oFsm.numUniFlows = 0 //no more flows |
| 471 | oFsm.configuredUniFlow = 0 //no more flows configured |
| 472 | oFsm.uniVlanFlowParamsSlice = nil //reset the slice |
| 473 | logger.Debugw("UniVlanConfigFsm flow removal - no more flows", log.Fields{ |
| 474 | "device-id": oFsm.deviceID}) |
| 475 | } else { |
| 476 | oFsm.numUniFlows-- |
| 477 | if oFsm.configuredUniFlow > 0 { |
| 478 | oFsm.configuredUniFlow-- |
| 479 | //TODO!! might be needed to consider still outstanding configure requests .. |
| 480 | // so a flow at removal might still not be configured !?! |
| 481 | } |
| 482 | //cut off the requested flow by slicing out this element |
| 483 | oFsm.uniVlanFlowParamsSlice = append( |
| 484 | oFsm.uniVlanFlowParamsSlice[:flow], oFsm.uniVlanFlowParamsSlice[flow+1:]...) |
| 485 | logger.Debugw("UniVlanConfigFsm flow removal - specific flow removed from data", log.Fields{ |
| 486 | "device-id": oFsm.deviceID}) |
| 487 | } |
| 488 | //trigger the FSM to remove the relevant rule |
| 489 | pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm |
| 490 | if pConfigVlanStateBaseFsm.Is(vlanStConfigDone) { |
| 491 | //have to re-trigger the FSM to proceed with outstanding incremental flow configuration |
| 492 | // calling some FSM event must be decoupled |
| 493 | go func(a_pBaseFsm *fsm.FSM) { |
| 494 | _ = a_pBaseFsm.Event(vlanEvRemFlowConfig) |
| 495 | }(pConfigVlanStateBaseFsm) |
| 496 | } // if not in the appropriate state a new entry will be automatically considered later |
| 497 | // when the configDone state is reached |
| 498 | } else { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 499 | //cut off the requested cookie by slicing out this element |
| 500 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append( |
| 501 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[:i], |
| 502 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[i+1:]...) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 503 | // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately |
| 504 | // state transition notification is checked in deviceHandler |
| 505 | if oFsm.pDeviceHandler != nil { |
| 506 | //making use of the add->remove successor enum assumption/definition |
| 507 | go oFsm.pDeviceHandler.deviceProcStatusUpdate(OnuDeviceEvent((uint8(oFsm.requestEvent) + 1))) |
| 508 | } |
| 509 | logger.Debugw("UniVlanConfigFsm flow removal - rule persists with still valid cookies", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 510 | "device-id": oFsm.deviceID, "cookies": oFsm.uniVlanFlowParamsSlice[flow].CookieSlice}) |
| 511 | } |
| 512 | |
| 513 | //permanently store the modified flow config for reconcile case |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 514 | if oFsm.pDeviceHandler != nil { |
| 515 | if err := oFsm.pDeviceHandler.storePersUniFlowConfig(oFsm.pOnuUniPort.uniID, &oFsm.uniVlanFlowParamsSlice); err != nil { |
| 516 | logger.Errorw(err.Error(), log.Fields{"device-id": oFsm.deviceID}) |
| 517 | return err |
| 518 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | break //found the cookie - no further search for this requested cookie |
| 522 | } |
| 523 | } |
| 524 | if flowCookieMatch { //cookie already found: no need for further search in other flows |
| 525 | break |
| 526 | } |
| 527 | } //search all flows |
| 528 | if !flowCookieMatch { //some cookie remove-request for a cookie that does not exist in the FSM data |
| 529 | logger.Warnw("UniVlanConfigFsm flow removal - remove-cookie not found", log.Fields{ |
| 530 | "device-id": oFsm.deviceID, "remove-cookie": aCookie}) |
| 531 | // but accept the request with success as no such cookie (flow) does exist |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 532 | // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately |
| 533 | // state transition notification is checked in deviceHandler |
| 534 | if oFsm.pDeviceHandler != nil { |
| 535 | //making use of the add->remove successor enum assumption/definition |
| 536 | go oFsm.pDeviceHandler.deviceProcStatusUpdate(OnuDeviceEvent((uint8(oFsm.requestEvent) + 1))) |
| 537 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 538 | return nil |
| 539 | } //unknown cookie |
| 540 | |
| 541 | return nil |
| 542 | } |
| 543 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 544 | func (oFsm *UniVlanConfigFsm) enterConfigStarting(e *fsm.Event) { |
| 545 | logger.Debugw("UniVlanConfigFsm start", log.Fields{"in state": e.FSM.Current(), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 546 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 547 | |
| 548 | // this FSM is not intended for re-start, needs always new creation for a new run |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 549 | // (self-destroying - compare enterDisabled()) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 550 | oFsm.omciMIdsResponseReceived = make(chan bool) |
| 551 | // start go routine for processing of LockState messages |
| 552 | go oFsm.processOmciVlanMessages() |
| 553 | //let the state machine run forward from here directly |
| 554 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 555 | if pConfigVlanStateAFsm != nil { |
| 556 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 557 | go func(a_pAFsm *AdapterFsm) { |
| 558 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
| 559 | //stick to pythonAdapter numbering scheme |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 560 | oFsm.vtfdID = macBridgePortAniEID + oFsm.pOnuUniPort.entityID + oFsm.techProfileID |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 561 | //cmp also usage in EVTOCDE create in omci_cc |
| 562 | oFsm.evtocdID = macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo) |
| 563 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 564 | if oFsm.pUniTechProf.getTechProfileDone(oFsm.pOnuUniPort.uniID, oFsm.techProfileID) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 565 | // let the vlan processing begin |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 566 | _ = a_pAFsm.pFsm.Event(vlanEvStartConfig) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 567 | } else { |
| 568 | // set to waiting for Techprofile |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 569 | _ = a_pAFsm.pFsm.Event(vlanEvWaitTechProf) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | }(pConfigVlanStateAFsm) |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | func (oFsm *UniVlanConfigFsm) enterConfigVtfd(e *fsm.Event) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 577 | //mutex protection is required for possible concurrent access to FSM members |
| 578 | oFsm.mutexFlowParams.Lock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 579 | if oFsm.uniVlanFlowParamsSlice[0].VlanRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 580 | // meaning transparent setup - no specific VTFD setting required |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 581 | oFsm.mutexFlowParams.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 582 | logger.Debugw("UniVlanConfigFsm: no VTFD config required", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 583 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 584 | // let the FSM proceed ... (from within this state all internal pointers may be expected to be correct) |
| 585 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 586 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 587 | go func(a_pAFsm *AdapterFsm) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 588 | _ = a_pAFsm.pFsm.Event(vlanEvRxConfigVtfd) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 589 | }(pConfigVlanStateAFsm) |
| 590 | } else { |
| 591 | logger.Debugw("UniVlanConfigFsm create VTFD", log.Fields{ |
| 592 | "EntitytId": strconv.FormatInt(int64(oFsm.vtfdID), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 593 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 594 | // setVid is assumed to be masked already by the caller to 12 bit |
| 595 | oFsm.vlanFilterList[0] = uint16(oFsm.uniVlanFlowParamsSlice[0].VlanRuleParams.SetVid) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 596 | oFsm.mutexFlowParams.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 597 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 598 | vtfdFilterList[0] = oFsm.vlanFilterList[0] |
| 599 | oFsm.numVlanFilterEntries = 1 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 600 | meParams := me.ParamData{ |
| 601 | EntityID: oFsm.vtfdID, |
| 602 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 603 | "VlanFilterList": vtfdFilterList, //omci lib wants a slice for serialization |
| 604 | "ForwardOperation": uint8(0x10), //VID investigation |
| 605 | "NumberOfEntries": oFsm.numVlanFilterEntries, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 606 | }, |
| 607 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 608 | logger.Debugw("UniVlanConfigFsm sendcreate VTFD", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 609 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 610 | meInstance := oFsm.pOmciCC.sendCreateVtfdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 611 | oFsm.pAdaptFsm.commChan, meParams) |
| 612 | //accept also nil as (error) return value for writing to LastTx |
| 613 | // - this avoids misinterpretation of new received OMCI messages |
| 614 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 615 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 616 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 617 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
| 621 | func (oFsm *UniVlanConfigFsm) enterConfigEvtocd(e *fsm.Event) { |
| 622 | logger.Debugw("UniVlanConfigFsm - start config EVTOCD loop", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 623 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 624 | oFsm.requestEventOffset = 0 //0 offset for last flow-add activity |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 625 | go oFsm.performConfigEvtocdEntries(0) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | func (oFsm *UniVlanConfigFsm) enterVlanConfigDone(e *fsm.Event) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 629 | logger.Debugw("UniVlanConfigFsm - checking on more flows", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 630 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 631 | pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm |
| 632 | if len(oFsm.uniRemoveFlowsSlice) > 0 { |
| 633 | //some further flows are to be removed, removal always starts with the first element |
| 634 | // calling some FSM event must be decoupled |
| 635 | go func(a_pBaseFsm *fsm.FSM) { |
| 636 | _ = a_pBaseFsm.Event(vlanEvRemFlowConfig) |
| 637 | }(pConfigVlanStateBaseFsm) |
| 638 | return |
| 639 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 640 | if oFsm.numUniFlows > oFsm.configuredUniFlow { |
| 641 | //some further flows are to be configured |
| 642 | // calling some FSM event must be decoupled |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 643 | go func(a_pBaseFsm *fsm.FSM) { |
| 644 | _ = a_pBaseFsm.Event(vlanEvIncrFlowConfig) |
| 645 | }(pConfigVlanStateBaseFsm) |
| 646 | return |
| 647 | } |
| 648 | |
| 649 | logger.Debugw("UniVlanConfigFsm - VLAN config done: send dh event notification", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 650 | "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 651 | // it might appear that some flows are requested also after 'flowPushed' event has been generated ... |
| 652 | // state transition notification is checked in deviceHandler |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 653 | if oFsm.pDeviceHandler != nil { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 654 | //making use of the add->remove successor enum assumption/definition |
| 655 | go oFsm.pDeviceHandler.deviceProcStatusUpdate(OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset))) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 659 | func (oFsm *UniVlanConfigFsm) enterConfigIncrFlow(e *fsm.Event) { |
| 660 | logger.Debugw("UniVlanConfigFsm - start config further incremental flow", log.Fields{ |
| 661 | "in state": e.FSM.Current(), "recent flow-number": (oFsm.configuredUniFlow), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 662 | "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 663 | oFsm.mutexFlowParams.Lock() |
| 664 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 665 | if oFsm.configuredUniFlow == 0 { |
| 666 | oFsm.mutexFlowParams.Unlock() |
| 667 | // this is a restart with a complete new flow, we can re-use the initial flow config control |
| 668 | // including the check, if the related techProfile is (still) available (probably also removed in between) |
| 669 | // calling some FSM event must be decoupled |
| 670 | pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm |
| 671 | go func(a_pBaseFsm *fsm.FSM) { |
| 672 | _ = a_pBaseFsm.Event(vlanEvRenew) |
| 673 | }(pConfigVlanStateBaseFsm) |
| 674 | return |
| 675 | } |
| 676 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 677 | if oFsm.uniVlanFlowParamsSlice[oFsm.configuredUniFlow].VlanRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 678 | // meaning transparent setup - no specific VTFD setting required |
| 679 | oFsm.mutexFlowParams.Unlock() |
| 680 | logger.Debugw("UniVlanConfigFsm: no VTFD config required", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 681 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 682 | } else { |
| 683 | if oFsm.numVlanFilterEntries == 0 { |
| 684 | //no VTFD yet created |
| 685 | logger.Debugw("UniVlanConfigFsm create VTFD", log.Fields{ |
| 686 | "EntitytId": strconv.FormatInt(int64(oFsm.vtfdID), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 687 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 688 | // setVid is assumed to be masked already by the caller to 12 bit |
| 689 | oFsm.vlanFilterList[0] = uint16(oFsm.uniVlanFlowParamsSlice[oFsm.configuredUniFlow].VlanRuleParams.SetVid) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 690 | oFsm.mutexFlowParams.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 691 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 692 | vtfdFilterList[0] = oFsm.vlanFilterList[0] |
| 693 | oFsm.numVlanFilterEntries = 1 |
| 694 | meParams := me.ParamData{ |
| 695 | EntityID: oFsm.vtfdID, |
| 696 | Attributes: me.AttributeValueMap{ |
| 697 | "VlanFilterList": vtfdFilterList, |
| 698 | "ForwardOperation": uint8(0x10), //VID investigation |
| 699 | "NumberOfEntries": oFsm.numVlanFilterEntries, |
| 700 | }, |
| 701 | } |
| 702 | meInstance := oFsm.pOmciCC.sendCreateVtfdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 703 | oFsm.pAdaptFsm.commChan, meParams) |
| 704 | //accept also nil as (error) return value for writing to LastTx |
| 705 | // - this avoids misinterpretation of new received OMCI messages |
| 706 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 707 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 708 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 709 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 710 | } else { |
| 711 | //VTFD already exists - just modify by 'set' |
| 712 | //TODO!!: but only if the VID is not already present, skipped by now to test basic working |
| 713 | logger.Debugw("UniVlanConfigFsm set VTFD", log.Fields{ |
| 714 | "EntitytId": strconv.FormatInt(int64(oFsm.vtfdID), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 715 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 716 | // setVid is assumed to be masked already by the caller to 12 bit |
| 717 | oFsm.vlanFilterList[oFsm.numVlanFilterEntries] = |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 718 | uint16(oFsm.uniVlanFlowParamsSlice[oFsm.configuredUniFlow].VlanRuleParams.SetVid) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 719 | oFsm.mutexFlowParams.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 720 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 721 | for i := uint8(0); i <= oFsm.numVlanFilterEntries; i++ { |
| 722 | vtfdFilterList[i] = oFsm.vlanFilterList[i] |
| 723 | } |
| 724 | |
| 725 | oFsm.numVlanFilterEntries++ |
| 726 | meParams := me.ParamData{ |
| 727 | EntityID: oFsm.vtfdID, |
| 728 | Attributes: me.AttributeValueMap{ |
| 729 | "VlanFilterList": vtfdFilterList, |
| 730 | "NumberOfEntries": oFsm.numVlanFilterEntries, |
| 731 | }, |
| 732 | } |
| 733 | meInstance := oFsm.pOmciCC.sendSetVtfdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 734 | oFsm.pAdaptFsm.commChan, meParams) |
| 735 | //accept also nil as (error) return value for writing to LastTx |
| 736 | // - this avoids misinterpretation of new received OMCI messages |
| 737 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 738 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 739 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 740 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 741 | } |
| 742 | //verify response |
| 743 | err := oFsm.waitforOmciResponse() |
| 744 | if err != nil { |
| 745 | logger.Errorw("VTFD create/set failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 746 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 747 | pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm |
| 748 | go func(a_pBaseFsm *fsm.FSM) { |
| 749 | _ = a_pBaseFsm.Event(vlanEvReset) |
| 750 | }(pConfigVlanStateBaseFsm) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 751 | return |
| 752 | } |
| 753 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 754 | oFsm.requestEventOffset = 0 //0 offset for last flow-add activity |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 755 | go oFsm.performConfigEvtocdEntries(oFsm.configuredUniFlow) |
| 756 | } |
| 757 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 758 | func (oFsm *UniVlanConfigFsm) enterRemoveFlow(e *fsm.Event) { |
| 759 | oFsm.mutexFlowParams.Lock() |
| 760 | logger.Debugw("UniVlanConfigFsm - start removing the top remove-flow", log.Fields{ |
| 761 | "in state": e.FSM.Current(), "with last cookie": oFsm.uniRemoveFlowsSlice[0].cookie, |
| 762 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 763 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 764 | pConfigVlanStateBaseFsm := oFsm.pAdaptFsm.pFsm |
| 765 | loAllowSpecificOmciConfig := oFsm.pDeviceHandler.ReadyForSpecificOmciConfig |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 766 | loVlanEntryClear := uint8(0) |
| 767 | loVlanEntryRmPos := uint8(0x80) //with indication 'invalid' in bit 7 |
| 768 | //shallow copy is sufficient as no reference variables are used within struct |
| 769 | loRuleParams := oFsm.uniRemoveFlowsSlice[0].vlanRuleParams |
| 770 | oFsm.mutexFlowParams.Unlock() |
| 771 | logger.Debugw("UniVlanConfigFsm - remove-flow parameters are", log.Fields{ |
| 772 | "match vid": loRuleParams.MatchVid, "match Pcp": loRuleParams.MatchPcp, |
| 773 | "set vid": strconv.FormatInt(int64(loRuleParams.SetVid), 16), |
| 774 | "device-id": oFsm.deviceID}) |
| 775 | |
| 776 | if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 777 | // meaning transparent setup - no specific VTFD setting required |
| 778 | logger.Debugw("UniVlanConfigFsm: no VTFD removal required for transparent flow", log.Fields{ |
| 779 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 780 | } else { |
| 781 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization and 're-copy' |
| 782 | if oFsm.numVlanFilterEntries == 1 { |
| 783 | //only one active VLAN entry (hopefully the SetVID we want to remove - should be, but not verified ..) |
| 784 | // so we can just delete the VTFD entry |
| 785 | logger.Debugw("UniVlanConfigFsm: VTFD delete (no more vlan filters)", |
| 786 | log.Fields{"current vlan list": oFsm.vlanFilterList, |
| 787 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 788 | loVlanEntryClear = 1 //full VlanFilter clear request |
| 789 | if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state |
| 790 | meInstance := oFsm.pOmciCC.sendDeleteVtfd(context.TODO(), ConstDefaultOmciTimeout, true, |
| 791 | oFsm.pAdaptFsm.commChan, oFsm.vtfdID) |
| 792 | oFsm.pLastTxMeInstance = meInstance |
| 793 | } else { |
| 794 | logger.Debugw("UniVlanConfigFsm delete VTFD OMCI handling skipped based on device state", log.Fields{ |
| 795 | "device-id": oFsm.deviceID, "device-state": oFsm.pDeviceHandler.deviceReason}) |
| 796 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 797 | } else { |
| 798 | //many VTFD already should exists - find and remove the one concerned by the actual remove rule |
| 799 | // by updating the VTFD per set command with new valid list |
| 800 | logger.Debugw("UniVlanConfigFsm: VTFD removal of requested VLAN from the list on OMCI", |
| 801 | log.Fields{"current vlan list": oFsm.vlanFilterList, |
| 802 | "set-vlan": loRuleParams.SetVid, "device-id": oFsm.deviceID}) |
| 803 | for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ { |
| 804 | if loRuleParams.SetVid == uint32(oFsm.vlanFilterList[i]) { |
| 805 | loVlanEntryRmPos = i |
| 806 | break //abort search |
| 807 | } |
| 808 | } |
| 809 | if loVlanEntryRmPos < cVtfdTableSize { |
| 810 | //valid entry was found - to be eclipsed |
| 811 | loVlanEntryClear = 2 //VlanFilter remove request for a specific entry |
| 812 | for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ { |
| 813 | if i < loVlanEntryRmPos { |
| 814 | vtfdFilterList[i] = oFsm.vlanFilterList[i] //copy original |
| 815 | } else if i < (cVtfdTableSize - 1) { |
| 816 | vtfdFilterList[i] = oFsm.vlanFilterList[i+1] //copy successor (including 0 elements) |
| 817 | } else { |
| 818 | vtfdFilterList[i] = 0 //set last byte if needed |
| 819 | } |
| 820 | } |
| 821 | logger.Debugw("UniVlanConfigFsm set VTFD", log.Fields{ |
| 822 | "EntitytId": strconv.FormatInt(int64(oFsm.vtfdID), 16), |
| 823 | "new vlan list": vtfdFilterList, "device-id": oFsm.deviceID}) |
| 824 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 825 | if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state |
| 826 | meParams := me.ParamData{ |
| 827 | EntityID: oFsm.vtfdID, |
| 828 | Attributes: me.AttributeValueMap{ |
| 829 | "VlanFilterList": vtfdFilterList, |
| 830 | "NumberOfEntries": (oFsm.numVlanFilterEntries - 1), //one element less |
| 831 | }, |
| 832 | } |
| 833 | meInstance := oFsm.pOmciCC.sendSetVtfdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 834 | oFsm.pAdaptFsm.commChan, meParams) |
| 835 | oFsm.pLastTxMeInstance = meInstance |
| 836 | } else { |
| 837 | logger.Debugw("UniVlanConfigFsm set VTFD OMCI handling skipped based on device state", log.Fields{ |
| 838 | "device-id": oFsm.deviceID, "device-state": oFsm.pDeviceHandler.deviceReason}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 839 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 840 | } else { |
| 841 | logger.Warnw("UniVlanConfigFsm: requested VLAN for removal not found in list - ignore and continue (no VTFD set)", |
| 842 | log.Fields{"device-id": oFsm.deviceID}) |
| 843 | } |
| 844 | } |
| 845 | if loVlanEntryClear > 0 { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 846 | if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state |
| 847 | //waiting on response |
| 848 | err := oFsm.waitforOmciResponse() |
| 849 | if err != nil { |
| 850 | logger.Errorw("VTFD delete/reset failed, aborting VlanConfig FSM!", |
| 851 | log.Fields{"device-id": oFsm.deviceID}) |
| 852 | // calling some FSM event must be decoupled |
| 853 | go func(a_pBaseFsm *fsm.FSM) { |
| 854 | _ = a_pBaseFsm.Event(vlanEvReset) |
| 855 | }(pConfigVlanStateBaseFsm) |
| 856 | return |
| 857 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | if loVlanEntryClear == 1 { |
| 861 | oFsm.vlanFilterList[0] = 0 //first entry is the only that can contain the previous only-one element |
| 862 | oFsm.numVlanFilterEntries = 0 |
| 863 | } else if loVlanEntryClear == 2 { |
| 864 | // new VlanFilterList should be one entry smaller now - copy from last configured entry |
| 865 | // this loop now includes the 0 element on previous last valid entry |
| 866 | for i := uint8(0); i <= oFsm.numVlanFilterEntries; i++ { |
| 867 | oFsm.vlanFilterList[i] = vtfdFilterList[i] |
| 868 | } |
| 869 | oFsm.numVlanFilterEntries-- |
| 870 | } |
| 871 | } |
| 872 | } |
| 873 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 874 | if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state |
| 875 | go oFsm.removeEvtocdEntries(loRuleParams) |
| 876 | } else { |
| 877 | // OMCI processing is not done, expectation is to have the ONU in some basic config state accordingly |
| 878 | logger.Debugw("UniVlanConfigFsm remove EVTOCD OMCI handling skipped based on device state", log.Fields{ |
| 879 | "device-id": oFsm.deviceID}) |
| 880 | // calling some FSM event must be decoupled |
| 881 | go func(a_pBaseFsm *fsm.FSM) { |
| 882 | _ = a_pBaseFsm.Event(vlanEvRemFlowDone) |
| 883 | }(pConfigVlanStateBaseFsm) |
| 884 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | func (oFsm *UniVlanConfigFsm) enterVlanCleanupDone(e *fsm.Event) { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 888 | logger.Debugw("UniVlanConfigFsm - removing the removal data", log.Fields{ |
| 889 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 890 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 891 | oFsm.mutexFlowParams.Lock() |
| 892 | if len(oFsm.uniRemoveFlowsSlice) <= 1 { |
| 893 | oFsm.uniRemoveFlowsSlice = nil //reset the slice |
| 894 | logger.Debugw("UniVlanConfigFsm flow removal - last remove-flow deleted", log.Fields{ |
| 895 | "device-id": oFsm.deviceID}) |
| 896 | } else { |
| 897 | //cut off the actual flow by slicing out the first element |
| 898 | oFsm.uniRemoveFlowsSlice = append( |
| 899 | oFsm.uniRemoveFlowsSlice[:0], |
| 900 | oFsm.uniRemoveFlowsSlice[1:]...) |
| 901 | logger.Debugw("UniVlanConfigFsm flow removal - specific flow deleted from data", log.Fields{ |
| 902 | "device-id": oFsm.deviceID}) |
| 903 | } |
| 904 | oFsm.mutexFlowParams.Unlock() |
| 905 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 906 | oFsm.requestEventOffset = 1 //offset 1 for last flow-remove activity |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 907 | //return to the basic config verification state |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 908 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 909 | if pConfigVlanStateAFsm != nil { |
| 910 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 911 | go func(a_pAFsm *AdapterFsm) { |
| 912 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 913 | _ = a_pAFsm.pFsm.Event(vlanEvFlowDataRemoved) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 914 | } |
| 915 | }(pConfigVlanStateAFsm) |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | func (oFsm *UniVlanConfigFsm) enterResetting(e *fsm.Event) { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 920 | logger.Debugw("UniVlanConfigFsm resetting", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 921 | |
| 922 | pConfigVlanStateAFsm := oFsm.pAdaptFsm |
| 923 | if pConfigVlanStateAFsm != nil { |
| 924 | // abort running message processing |
| 925 | fsmAbortMsg := Message{ |
| 926 | Type: TestMsg, |
| 927 | Data: TestMessage{ |
| 928 | TestMessageVal: AbortMessageProcessing, |
| 929 | }, |
| 930 | } |
| 931 | pConfigVlanStateAFsm.commChan <- fsmAbortMsg |
| 932 | |
| 933 | //try to restart the FSM to 'disabled', decouple event transfer |
| 934 | go func(a_pAFsm *AdapterFsm) { |
| 935 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 936 | _ = a_pAFsm.pFsm.Event(vlanEvRestart) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 937 | } |
| 938 | }(pConfigVlanStateAFsm) |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | func (oFsm *UniVlanConfigFsm) enterDisabled(e *fsm.Event) { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 943 | logger.Debugw("UniVlanConfigFsm enters disabled state", log.Fields{"device-id": oFsm.deviceID}) |
| 944 | oFsm.pLastTxMeInstance = nil |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 945 | if oFsm.pDeviceHandler != nil { |
| 946 | //request removal of 'reference' in the Handler (completely clear the FSM) |
| 947 | go oFsm.pDeviceHandler.RemoveVlanFilterFsm(oFsm.pOnuUniPort) |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | func (oFsm *UniVlanConfigFsm) processOmciVlanMessages() { //ctx context.Context? |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 952 | logger.Debugw("Start UniVlanConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 953 | loop: |
| 954 | for { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 955 | // case <-ctx.Done(): |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 956 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 957 | // break loop |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 958 | message, ok := <-oFsm.pAdaptFsm.commChan |
| 959 | if !ok { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 960 | logger.Info("UniVlanConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 961 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
| 962 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 963 | break loop |
| 964 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 965 | logger.Debugw("UniVlanConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 966 | |
| 967 | switch message.Type { |
| 968 | case TestMsg: |
| 969 | msg, _ := message.Data.(TestMessage) |
| 970 | if msg.TestMessageVal == AbortMessageProcessing { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 971 | logger.Infow("UniVlanConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 972 | break loop |
| 973 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 974 | logger.Warnw("UniVlanConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 975 | case OMCI: |
| 976 | msg, _ := message.Data.(OmciMessage) |
| 977 | oFsm.handleOmciVlanConfigMessage(msg) |
| 978 | default: |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 979 | logger.Warn("UniVlanConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 980 | "message.Type": message.Type}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 981 | } |
| 982 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 983 | logger.Infow("End UniVlanConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | func (oFsm *UniVlanConfigFsm) handleOmciVlanConfigMessage(msg OmciMessage) { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 987 | logger.Debugw("Rx OMCI UniVlanConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 988 | "msgType": msg.OmciMsg.MessageType}) |
| 989 | |
| 990 | switch msg.OmciMsg.MessageType { |
| 991 | case omci.CreateResponseType: |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 992 | { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-( |
| 993 | if err := oFsm.handleOmciCreateResponseMessage(msg.OmciPacket); err != nil { |
| 994 | logger.Warnw("CreateResponse handling aborted", log.Fields{"err": err}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 995 | return |
| 996 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 997 | } //CreateResponseType |
| 998 | case omci.SetResponseType: |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 999 | { //leave that here as direct code as most often used |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1000 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 1001 | if msgLayer == nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1002 | logger.Errorw("Omci Msg layer could not be detected for SetResponse", |
| 1003 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1004 | return |
| 1005 | } |
| 1006 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 1007 | if !msgOk { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1008 | logger.Errorw("Omci Msg layer could not be assigned for SetResponse", |
| 1009 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1010 | return |
| 1011 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1012 | logger.Debugw("UniVlanConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1013 | if msgObj.Result != me.Success { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1014 | logger.Errorw("UniVlanConfigFsm Omci SetResponse Error - later: drive FSM to abort state ?", |
| 1015 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1016 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 1017 | return |
| 1018 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1019 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 1020 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 1021 | switch oFsm.pLastTxMeInstance.GetName() { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1022 | case "VlanTaggingFilterData", |
| 1023 | "ExtendedVlanTaggingOperationConfigurationData": |
| 1024 | { // let the MultiEntity config proceed by stopping the wait function |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1025 | oFsm.omciMIdsResponseReceived <- true |
| 1026 | } |
| 1027 | } |
| 1028 | } |
| 1029 | } //SetResponseType |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1030 | case omci.DeleteResponseType: |
| 1031 | { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-( |
| 1032 | if err := oFsm.handleOmciDeleteResponseMessage(msg.OmciPacket); err != nil { |
| 1033 | logger.Warnw("DeleteResponse handling aborted", log.Fields{"err": err}) |
| 1034 | return |
| 1035 | } |
| 1036 | } //DeleteResponseType |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1037 | default: |
| 1038 | { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1039 | logger.Errorw("Rx OMCI unhandled MsgType", |
| 1040 | log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1041 | return |
| 1042 | } |
| 1043 | } |
| 1044 | } |
| 1045 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1046 | func (oFsm *UniVlanConfigFsm) handleOmciCreateResponseMessage(apOmciPacket *gp.Packet) error { |
| 1047 | msgLayer := (*apOmciPacket).Layer(omci.LayerTypeCreateResponse) |
| 1048 | if msgLayer == nil { |
| 1049 | logger.Errorw("Omci Msg layer could not be detected for CreateResponse", |
| 1050 | log.Fields{"device-id": oFsm.deviceID}) |
| 1051 | return fmt.Errorf("omci msg layer could not be detected for CreateResponse for device-id %x", |
| 1052 | oFsm.deviceID) |
| 1053 | } |
| 1054 | msgObj, msgOk := msgLayer.(*omci.CreateResponse) |
| 1055 | if !msgOk { |
| 1056 | logger.Errorw("Omci Msg layer could not be assigned for CreateResponse", |
| 1057 | log.Fields{"device-id": oFsm.deviceID}) |
| 1058 | return fmt.Errorf("omci msg layer could not be assigned for CreateResponse for device-id %x", |
| 1059 | oFsm.deviceID) |
| 1060 | } |
| 1061 | logger.Debugw("UniVlanConfigFsm CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
| 1062 | if msgObj.Result != me.Success { |
| 1063 | logger.Errorw("Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": oFsm.deviceID, |
| 1064 | "Error": msgObj.Result}) |
| 1065 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 1066 | return fmt.Errorf("omci CreateResponse Error for device-id %x", |
| 1067 | oFsm.deviceID) |
| 1068 | } |
| 1069 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 1070 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 1071 | // to satisfy StaticCodeAnalysis I had to move the small processing into a separate method :-( |
| 1072 | switch oFsm.pLastTxMeInstance.GetName() { |
| 1073 | case "VlanTaggingFilterData": |
| 1074 | { |
| 1075 | if oFsm.pAdaptFsm.pFsm.Current() == vlanStConfigVtfd { |
| 1076 | // Only if CreateResponse is received from first flow entry - let the FSM proceed ... |
| 1077 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigVtfd) |
| 1078 | } else { // let the MultiEntity config proceed by stopping the wait function |
| 1079 | oFsm.omciMIdsResponseReceived <- true |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | } |
| 1084 | return nil |
| 1085 | } |
| 1086 | |
| 1087 | func (oFsm *UniVlanConfigFsm) handleOmciDeleteResponseMessage(apOmciPacket *gp.Packet) error { |
| 1088 | msgLayer := (*apOmciPacket).Layer(omci.LayerTypeDeleteResponse) |
| 1089 | if msgLayer == nil { |
| 1090 | logger.Errorw("UniVlanConfigFsm - Omci Msg layer could not be detected for DeleteResponse", |
| 1091 | log.Fields{"device-id": oFsm.deviceID}) |
| 1092 | return fmt.Errorf("omci msg layer could not be detected for DeleteResponse for device-id %x", |
| 1093 | oFsm.deviceID) |
| 1094 | } |
| 1095 | msgObj, msgOk := msgLayer.(*omci.DeleteResponse) |
| 1096 | if !msgOk { |
| 1097 | logger.Errorw("UniVlanConfigFsm - Omci Msg layer could not be assigned for DeleteResponse", |
| 1098 | log.Fields{"device-id": oFsm.deviceID}) |
| 1099 | return fmt.Errorf("omci msg layer could not be assigned for DeleteResponse for device-id %x", |
| 1100 | oFsm.deviceID) |
| 1101 | } |
| 1102 | logger.Debugw("UniVlanConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
| 1103 | if msgObj.Result != me.Success { |
| 1104 | logger.Errorw("UniVlanConfigFsm - Omci DeleteResponse Error - later: drive FSM to abort state ?", |
| 1105 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 1106 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 1107 | return fmt.Errorf("omci DeleteResponse Error for device-id %x", |
| 1108 | oFsm.deviceID) |
| 1109 | } |
| 1110 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 1111 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 1112 | switch oFsm.pLastTxMeInstance.GetName() { |
| 1113 | case "VlanTaggingFilterData": |
| 1114 | { // let the MultiEntity config proceed by stopping the wait function |
| 1115 | oFsm.omciMIdsResponseReceived <- true |
| 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | return nil |
| 1120 | } |
| 1121 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1122 | func (oFsm *UniVlanConfigFsm) performConfigEvtocdEntries(aFlowEntryNo uint8) { |
| 1123 | if aFlowEntryNo == 0 { |
| 1124 | // EthType set only at first flow element |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1125 | // EVTOCD ME is expected to exist at this point already from MIB-Download (with AssociationType/Pointer) |
| 1126 | // we need to extend the configuration by EthType definition and, to be sure, downstream 'inverse' mode |
| 1127 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD", log.Fields{ |
| 1128 | "EntitytId": strconv.FormatInt(int64(oFsm.evtocdID), 16), |
| 1129 | "i/oEthType": strconv.FormatInt(int64(cDefaultTpid), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1130 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1131 | meParams := me.ParamData{ |
| 1132 | EntityID: oFsm.evtocdID, |
| 1133 | Attributes: me.AttributeValueMap{ |
| 1134 | "InputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base |
| 1135 | "OutputTpid": uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base |
| 1136 | "DownstreamMode": uint8(cDefaultDownstreamMode), |
| 1137 | }, |
| 1138 | } |
| 1139 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 1140 | oFsm.pAdaptFsm.commChan, meParams) |
| 1141 | //accept also nil as (error) return value for writing to LastTx |
| 1142 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1143 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1144 | |
| 1145 | //verify response |
| 1146 | err := oFsm.waitforOmciResponse() |
| 1147 | if err != nil { |
| 1148 | logger.Errorw("Evtocd set TPID failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1149 | log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1150 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1151 | return |
| 1152 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1153 | } //first flow element |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1154 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1155 | oFsm.mutexFlowParams.Lock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1156 | if oFsm.uniVlanFlowParamsSlice[aFlowEntryNo].VlanRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1157 | //transparent transmission required |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1158 | oFsm.mutexFlowParams.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1159 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD single tagged transparent rule", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1160 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1161 | sliceEvtocdRule := make([]uint8, 16) |
| 1162 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 1163 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 1164 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 1165 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 1166 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 1167 | |
| 1168 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 1169 | cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule |
| 1170 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 1171 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 1172 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 1173 | |
| 1174 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 1175 | 0<<cTreatTTROffset| // Do not pop any tags |
| 1176 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 1177 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 1178 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 1179 | |
| 1180 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 1181 | cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag |
| 1182 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 1183 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 1184 | |
| 1185 | meParams := me.ParamData{ |
| 1186 | EntityID: oFsm.evtocdID, |
| 1187 | Attributes: me.AttributeValueMap{ |
| 1188 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 1189 | }, |
| 1190 | } |
| 1191 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 1192 | oFsm.pAdaptFsm.commChan, meParams) |
| 1193 | //accept also nil as (error) return value for writing to LastTx |
| 1194 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1195 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1196 | |
| 1197 | //verify response |
| 1198 | err := oFsm.waitforOmciResponse() |
| 1199 | if err != nil { |
| 1200 | logger.Errorw("Evtocd set transparent singletagged rule failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1201 | log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1202 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1203 | return |
| 1204 | } |
| 1205 | } else { |
| 1206 | // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario |
| 1207 | if oFsm.acceptIncrementalEvtoOption { |
| 1208 | // this defines VID translation scenario: singletagged->singletagged (if not transparent) |
| 1209 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD single tagged translation rule", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1210 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1211 | sliceEvtocdRule := make([]uint8, 16) |
| 1212 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 1213 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 1214 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 1215 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 1216 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 1217 | |
| 1218 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1219 | oFsm.uniVlanFlowParamsSlice[aFlowEntryNo].VlanRuleParams.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN |
| 1220 | oFsm.uniVlanFlowParamsSlice[aFlowEntryNo].VlanRuleParams.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1221 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 1222 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 1223 | |
| 1224 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1225 | oFsm.uniVlanFlowParamsSlice[aFlowEntryNo].VlanRuleParams.TagsToRemove<<cTreatTTROffset| // either 1 or 0 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1226 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 1227 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 1228 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 1229 | |
| 1230 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1231 | oFsm.uniVlanFlowParamsSlice[aFlowEntryNo].VlanRuleParams.SetPcp<<cTreatPrioOffset| // as configured in flow |
| 1232 | oFsm.uniVlanFlowParamsSlice[aFlowEntryNo].VlanRuleParams.SetVid<<cTreatVidOffset| //as configured in flow |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1233 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1234 | oFsm.mutexFlowParams.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1235 | |
| 1236 | meParams := me.ParamData{ |
| 1237 | EntityID: oFsm.evtocdID, |
| 1238 | Attributes: me.AttributeValueMap{ |
| 1239 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 1240 | }, |
| 1241 | } |
| 1242 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 1243 | oFsm.pAdaptFsm.commChan, meParams) |
| 1244 | //accept also nil as (error) return value for writing to LastTx |
| 1245 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1246 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1247 | |
| 1248 | //verify response |
| 1249 | err := oFsm.waitforOmciResponse() |
| 1250 | if err != nil { |
| 1251 | logger.Errorw("Evtocd set singletagged translation rule failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1252 | log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1253 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1254 | return |
| 1255 | } |
| 1256 | } else { |
| 1257 | //not transparent and not acceptIncrementalEvtoOption untagged/priotagged->singletagged |
| 1258 | { // just for local var's |
| 1259 | // this defines stacking scenario: untagged->singletagged |
| 1260 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD untagged->singletagged rule", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1261 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1262 | sliceEvtocdRule := make([]uint8, 16) |
| 1263 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 1264 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 1265 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 1266 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 1267 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 1268 | |
| 1269 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 1270 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an inner-tag rule |
| 1271 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 1272 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 1273 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 1274 | |
| 1275 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 1276 | 0<<cTreatTTROffset| // Do not pop any tags |
| 1277 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 1278 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 1279 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 1280 | |
| 1281 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 1282 | 0<<cTreatPrioOffset| // vlan prio set to 0 |
| 1283 | // (as done in Py code, maybe better option would be setPcp here, which still could be 0?) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1284 | oFsm.uniVlanFlowParamsSlice[aFlowEntryNo].VlanRuleParams.SetVid<<cTreatVidOffset| // Outer VID don't care |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1285 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 1286 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1287 | oFsm.mutexFlowParams.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1288 | meParams := me.ParamData{ |
| 1289 | EntityID: oFsm.evtocdID, |
| 1290 | Attributes: me.AttributeValueMap{ |
| 1291 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 1292 | }, |
| 1293 | } |
| 1294 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 1295 | oFsm.pAdaptFsm.commChan, meParams) |
| 1296 | //accept also nil as (error) return value for writing to LastTx |
| 1297 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1298 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1299 | |
| 1300 | //verify response |
| 1301 | err := oFsm.waitforOmciResponse() |
| 1302 | if err != nil { |
| 1303 | logger.Errorw("Evtocd set untagged->singletagged rule failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1304 | log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1305 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1306 | return |
| 1307 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1308 | } // just for local var's |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1309 | { // just for local var's |
| 1310 | // this defines 'stacking' scenario: priotagged->singletagged |
| 1311 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD priotagged->singletagged rule", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1312 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1313 | sliceEvtocdRule := make([]uint8, 16) |
| 1314 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 1315 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 1316 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 1317 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 1318 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 1319 | |
| 1320 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 1321 | cPrioDoNotFilter<<cFilterPrioOffset| // Do not Filter on innerprio |
| 1322 | 0<<cFilterVidOffset| // filter on inner vid 0 (prioTagged) |
| 1323 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 1324 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 1325 | |
| 1326 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 1327 | 1<<cTreatTTROffset| // pop the prio-tag |
| 1328 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 1329 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 1330 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 1331 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1332 | oFsm.mutexFlowParams.Lock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1333 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 1334 | cCopyPrioFromInner<<cTreatPrioOffset| // vlan copy from PrioTag |
| 1335 | // (as done in Py code, maybe better option would be setPcp here, which still could be PrioCopy?) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1336 | oFsm.uniVlanFlowParamsSlice[aFlowEntryNo].VlanRuleParams.SetVid<<cTreatVidOffset| // Outer VID as configured |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1337 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1338 | oFsm.mutexFlowParams.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1339 | |
| 1340 | meParams := me.ParamData{ |
| 1341 | EntityID: oFsm.evtocdID, |
| 1342 | Attributes: me.AttributeValueMap{ |
| 1343 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 1344 | }, |
| 1345 | } |
| 1346 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 1347 | oFsm.pAdaptFsm.commChan, meParams) |
| 1348 | //accept also nil as (error) return value for writing to LastTx |
| 1349 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1350 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1351 | |
| 1352 | //verify response |
| 1353 | err := oFsm.waitforOmciResponse() |
| 1354 | if err != nil { |
| 1355 | logger.Errorw("Evtocd set priotagged->singletagged rule failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1356 | log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1357 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1358 | return |
| 1359 | } |
| 1360 | } //just for local var's |
| 1361 | } |
| 1362 | } |
| 1363 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 1364 | // if Config has been done for all EVTOCD entries let the FSM proceed |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1365 | logger.Debugw("EVTOCD set loop finished", log.Fields{"device-id": oFsm.deviceID}) |
| 1366 | oFsm.configuredUniFlow++ // one (more) flow configured |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1367 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRxConfigEvtocd) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1370 | func (oFsm *UniVlanConfigFsm) removeEvtocdEntries(aRuleParams uniVlanRuleParams) { |
| 1371 | // configured Input/Output TPID is not modified again - no influence if no filter is applied |
| 1372 | if aRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 1373 | //transparent transmission was set |
| 1374 | //perhaps the config is not needed for removal, |
| 1375 | // but the specific InnerTpid setting is removed in favor of the real default forwarding rule |
| 1376 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD reset to default single tagged rule", log.Fields{ |
| 1377 | "device-id": oFsm.deviceID}) |
| 1378 | sliceEvtocdRule := make([]uint8, 16) |
| 1379 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 1380 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 1381 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 1382 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 1383 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 1384 | |
| 1385 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 1386 | cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule |
| 1387 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 1388 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 1389 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 1390 | |
| 1391 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 1392 | 0<<cTreatTTROffset| // Do not pop any tags |
| 1393 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 1394 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 1395 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 1396 | |
| 1397 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 1398 | cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag |
| 1399 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 1400 | cDontCareTpid<<cTreatTpidOffset) // copy TPID and DEI |
| 1401 | |
| 1402 | meParams := me.ParamData{ |
| 1403 | EntityID: oFsm.evtocdID, |
| 1404 | Attributes: me.AttributeValueMap{ |
| 1405 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 1406 | }, |
| 1407 | } |
| 1408 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 1409 | oFsm.pAdaptFsm.commChan, meParams) |
| 1410 | //accept also nil as (error) return value for writing to LastTx |
| 1411 | // - this avoids misinterpretation of new received OMCI messages |
| 1412 | oFsm.pLastTxMeInstance = meInstance |
| 1413 | |
| 1414 | //verify response |
| 1415 | err := oFsm.waitforOmciResponse() |
| 1416 | if err != nil { |
| 1417 | logger.Errorw("Evtocd reset singletagged rule failed, aborting VlanConfig FSM!", |
| 1418 | log.Fields{"device-id": oFsm.deviceID}) |
| 1419 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1420 | return |
| 1421 | } |
| 1422 | } else { |
| 1423 | // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario |
| 1424 | if oFsm.acceptIncrementalEvtoOption { |
| 1425 | // this defines VID translation scenario: singletagged->singletagged (if not transparent) |
| 1426 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD clear single tagged translation rule", log.Fields{ |
| 1427 | "device-id": oFsm.deviceID, "match-vlan": aRuleParams.MatchVid}) |
| 1428 | sliceEvtocdRule := make([]uint8, 16) |
| 1429 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 1430 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 1431 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 1432 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 1433 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 1434 | |
| 1435 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 1436 | aRuleParams.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN |
| 1437 | aRuleParams.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID |
| 1438 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 1439 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 1440 | |
| 1441 | // delete indication for the indicated Filter |
| 1442 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], 0xFFFFFFFF) |
| 1443 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], 0xFFFFFFFF) |
| 1444 | |
| 1445 | meParams := me.ParamData{ |
| 1446 | EntityID: oFsm.evtocdID, |
| 1447 | Attributes: me.AttributeValueMap{ |
| 1448 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 1449 | }, |
| 1450 | } |
| 1451 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 1452 | oFsm.pAdaptFsm.commChan, meParams) |
| 1453 | //accept also nil as (error) return value for writing to LastTx |
| 1454 | // - this avoids misinterpretation of new received OMCI messages |
| 1455 | oFsm.pLastTxMeInstance = meInstance |
| 1456 | |
| 1457 | //verify response |
| 1458 | err := oFsm.waitforOmciResponse() |
| 1459 | if err != nil { |
| 1460 | logger.Errorw("Evtocd clear singletagged translation rule failed, aborting VlanConfig FSM!", |
| 1461 | log.Fields{"device-id": oFsm.deviceID, "match-vlan": aRuleParams.MatchVid}) |
| 1462 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1463 | return |
| 1464 | } |
| 1465 | } else { |
| 1466 | //not transparent and not acceptIncrementalEvtoOption: untagged/priotagged->singletagged |
| 1467 | { // just for local var's |
| 1468 | // this defines stacking scenario: untagged->singletagged |
| 1469 | //TODO!! in theory there could be different rules running in setting different PCP/VID'S |
| 1470 | // for untagged/priotagged, last rule wins (and remains the only one), maybe that should be |
| 1471 | // checked already at flow-add (and rejected) - to be observed if such is possible in Voltha |
| 1472 | // delete now assumes there is only one such rule! |
| 1473 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD reset untagged rule to default", log.Fields{ |
| 1474 | "device-id": oFsm.deviceID}) |
| 1475 | sliceEvtocdRule := make([]uint8, 16) |
| 1476 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 1477 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 1478 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 1479 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 1480 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 1481 | |
| 1482 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 1483 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an inner-tag rule |
| 1484 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 1485 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 1486 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 1487 | |
| 1488 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 1489 | 0<<cTreatTTROffset| // Do not pop any tags |
| 1490 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 1491 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 1492 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 1493 | |
| 1494 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 1495 | cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag |
| 1496 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 1497 | cDontCareTpid<<cTreatTpidOffset) // copy TPID and DEI |
| 1498 | |
| 1499 | meParams := me.ParamData{ |
| 1500 | EntityID: oFsm.evtocdID, |
| 1501 | Attributes: me.AttributeValueMap{ |
| 1502 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 1503 | }, |
| 1504 | } |
| 1505 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 1506 | oFsm.pAdaptFsm.commChan, meParams) |
| 1507 | //accept also nil as (error) return value for writing to LastTx |
| 1508 | // - this avoids misinterpretation of new received OMCI messages |
| 1509 | oFsm.pLastTxMeInstance = meInstance |
| 1510 | |
| 1511 | //verify response |
| 1512 | err := oFsm.waitforOmciResponse() |
| 1513 | if err != nil { |
| 1514 | logger.Errorw("Evtocd reset untagged rule to default failed, aborting VlanConfig FSM!", |
| 1515 | log.Fields{"device-id": oFsm.deviceID}) |
| 1516 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1517 | return |
| 1518 | } |
| 1519 | } // just for local var's |
| 1520 | { // just for local var's |
| 1521 | // this defines 'stacking' scenario: priotagged->singletagged |
| 1522 | logger.Debugw("UniVlanConfigFsm Tx Set::EVTOCD delete priotagged rule", log.Fields{ |
| 1523 | "device-id": oFsm.deviceID}) |
| 1524 | sliceEvtocdRule := make([]uint8, 16) |
| 1525 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 1526 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 1527 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 1528 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 1529 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 1530 | |
| 1531 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 1532 | cPrioDoNotFilter<<cFilterPrioOffset| // Do not Filter on innerprio |
| 1533 | 0<<cFilterVidOffset| // filter on inner vid 0 (prioTagged) |
| 1534 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 1535 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 1536 | |
| 1537 | // delete indication for the indicated Filter |
| 1538 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], 0xFFFFFFFF) |
| 1539 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], 0xFFFFFFFF) |
| 1540 | |
| 1541 | meParams := me.ParamData{ |
| 1542 | EntityID: oFsm.evtocdID, |
| 1543 | Attributes: me.AttributeValueMap{ |
| 1544 | "ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule, |
| 1545 | }, |
| 1546 | } |
| 1547 | meInstance := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(), ConstDefaultOmciTimeout, true, |
| 1548 | oFsm.pAdaptFsm.commChan, meParams) |
| 1549 | //accept also nil as (error) return value for writing to LastTx |
| 1550 | // - this avoids misinterpretation of new received OMCI messages |
| 1551 | oFsm.pLastTxMeInstance = meInstance |
| 1552 | |
| 1553 | //verify response |
| 1554 | err := oFsm.waitforOmciResponse() |
| 1555 | if err != nil { |
| 1556 | logger.Errorw("Evtocd delete priotagged rule failed, aborting VlanConfig FSM!", |
| 1557 | log.Fields{"device-id": oFsm.deviceID}) |
| 1558 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset) |
| 1559 | return |
| 1560 | } |
| 1561 | } //just for local var's |
| 1562 | } |
| 1563 | } |
| 1564 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame^] | 1565 | // if Config has been done for all EVTOCD entries let the FSM proceed |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1566 | logger.Debugw("EVTOCD filter remove loop finished", log.Fields{"device-id": oFsm.deviceID}) |
| 1567 | _ = oFsm.pAdaptFsm.pFsm.Event(vlanEvRemFlowDone) |
| 1568 | } |
| 1569 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1570 | func (oFsm *UniVlanConfigFsm) waitforOmciResponse() error { |
| 1571 | select { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1572 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1573 | // case <-ctx.Done(): |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1574 | // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1575 | case <-time.After(30 * time.Second): //AS FOR THE OTHER OMCI FSM's |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1576 | logger.Warnw("UniVlanConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.deviceID}) |
| 1577 | return fmt.Errorf("uniVlanConfigFsm multi entity timeout %s", oFsm.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1578 | case success := <-oFsm.omciMIdsResponseReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1579 | if success { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1580 | logger.Debug("UniVlanConfigFsm multi entity response received") |
| 1581 | return nil |
| 1582 | } |
| 1583 | // should not happen so far |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1584 | logger.Warnw("UniVlanConfigFsm multi entity response error", log.Fields{"for device-id": oFsm.deviceID}) |
| 1585 | return fmt.Errorf("uniVlanConfigFsm multi entity responseError %s", oFsm.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1586 | } |
| 1587 | } |