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