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