mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +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" |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 22 | "encoding/binary" |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 23 | "fmt" |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 24 | "net" |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 25 | "strconv" |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 26 | "sync" |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 27 | "time" |
| 28 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 29 | "github.com/cevaris/ordered_map" |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 30 | "github.com/looplab/fsm" |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 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 | //ic "github.com/opencord/voltha-protos/v4/go/inter_container" |
| 35 | //"github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 36 | //"github.com/opencord/voltha-protos/v4/go/voltha" |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 37 | ) |
| 38 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 39 | const ( |
| 40 | // events of config PON ANI port FSM |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 41 | aniEvStart = "aniEvStart" |
| 42 | aniEvStartConfig = "aniEvStartConfig" |
| 43 | aniEvRxDot1pmapCResp = "aniEvRxDot1pmapCResp" |
| 44 | aniEvRxMbpcdResp = "aniEvRxMbpcdResp" |
| 45 | aniEvRxTcontsResp = "aniEvRxTcontsResp" |
| 46 | aniEvRxGemntcpsResp = "aniEvRxGemntcpsResp" |
| 47 | aniEvRxGemiwsResp = "aniEvRxGemiwsResp" |
| 48 | aniEvRxPrioqsResp = "aniEvRxPrioqsResp" |
| 49 | aniEvRxDot1pmapSResp = "aniEvRxDot1pmapSResp" |
| 50 | aniEvRemGemiw = "aniEvRemGemiw" |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 51 | aniEvWaitFlowRem = "aniEvWaitFlowRem" |
| 52 | aniEvFlowRemDone = "aniEvFlowRemDone" |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 53 | aniEvRxRemGemiwResp = "aniEvRxRemGemiwResp" |
| 54 | aniEvRxRemGemntpResp = "aniEvRxRemGemntpResp" |
| 55 | aniEvRemTcontPath = "aniEvRemTcontPath" |
| 56 | aniEvRxResetTcontResp = "aniEvRxResetTcontResp" |
| 57 | aniEvRxRem1pMapperResp = "aniEvRxRem1pMapperResp" |
| 58 | aniEvRxRemAniBPCDResp = "aniEvRxRemAniBPCDResp" |
| 59 | aniEvTimeoutSimple = "aniEvTimeoutSimple" |
| 60 | aniEvTimeoutMids = "aniEvTimeoutMids" |
| 61 | aniEvReset = "aniEvReset" |
| 62 | aniEvRestart = "aniEvRestart" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 63 | ) |
| 64 | const ( |
| 65 | // states of config PON ANI port FSM |
| 66 | aniStDisabled = "aniStDisabled" |
| 67 | aniStStarting = "aniStStarting" |
| 68 | aniStCreatingDot1PMapper = "aniStCreatingDot1PMapper" |
| 69 | aniStCreatingMBPCD = "aniStCreatingMBPCD" |
| 70 | aniStSettingTconts = "aniStSettingTconts" |
| 71 | aniStCreatingGemNCTPs = "aniStCreatingGemNCTPs" |
| 72 | aniStCreatingGemIWs = "aniStCreatingGemIWs" |
| 73 | aniStSettingPQs = "aniStSettingPQs" |
| 74 | aniStSettingDot1PMapper = "aniStSettingDot1PMapper" |
| 75 | aniStConfigDone = "aniStConfigDone" |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 76 | aniStRemovingGemIW = "aniStRemovingGemIW" |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 77 | aniStWaitingFlowRem = "aniStWaitingFlowRem" |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 78 | aniStRemovingGemNCTP = "aniStRemovingGemNCTP" |
| 79 | aniStResetTcont = "aniStResetTcont" |
| 80 | aniStRemDot1PMapper = "aniStRemDot1PMapper" |
| 81 | aniStRemAniBPCD = "aniStRemAniBPCD" |
| 82 | aniStRemoveDone = "aniStRemoveDone" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 83 | aniStResetting = "aniStResetting" |
| 84 | ) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 85 | const cAniFsmIdleState = aniStConfigDone |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 86 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 87 | const ( |
| 88 | tpIDOffset = 64 |
| 89 | ) |
| 90 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 91 | type ponAniGemPortAttribs struct { |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 92 | gemPortID uint16 |
| 93 | upQueueID uint16 |
| 94 | downQueueID uint16 |
| 95 | direction uint8 |
| 96 | qosPolicy string |
| 97 | weight uint8 |
| 98 | pbitString string |
| 99 | isMulticast bool |
| 100 | multicastGemID uint16 |
| 101 | staticACL string |
| 102 | dynamicACL string |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 105 | //uniPonAniConfigFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI |
| 106 | type uniPonAniConfigFsm struct { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 107 | pDeviceHandler *deviceHandler |
| 108 | deviceID string |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 109 | pOmciCC *omciCC |
| 110 | pOnuUniPort *onuUniPort |
| 111 | pUniTechProf *onuUniTechProf |
| 112 | pOnuDB *onuDeviceDB |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 113 | techProfileID uint8 |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 114 | uniTpKey uniTP |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 115 | requestEvent OnuDeviceEvent |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 116 | mutexIsAwaitingResponse sync.RWMutex |
| 117 | isAwaitingResponse bool |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 118 | omciMIdsResponseReceived chan bool //separate channel needed for checking multiInstance OMCI message responses |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 119 | pAdaptFsm *AdapterFsm |
| 120 | chSuccess chan<- uint8 |
| 121 | procStep uint8 |
| 122 | chanSet bool |
| 123 | mapperSP0ID uint16 |
| 124 | macBPCD0ID uint16 |
| 125 | tcont0ID uint16 |
| 126 | alloc0ID uint16 |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 127 | gemPortAttribsSlice []ponAniGemPortAttribs |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 128 | pLastTxMeInstance *me.ManagedEntity |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 129 | requestEventOffset uint8 //used to indicate ConfigDone or Removed using successor (enum) |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame^] | 130 | isWaitingForFlowDelete bool |
| 131 | waitFlowDeleteChannel chan bool |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 134 | //newUniPonAniConfigFsm is the 'constructor' for the state machine to config the PON ANI ports of ONU UNI ports via OMCI |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 135 | func newUniPonAniConfigFsm(ctx context.Context, apDevOmciCC *omciCC, apUniPort *onuUniPort, apUniTechProf *onuUniTechProf, |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 136 | apOnuDB *onuDeviceDB, aTechProfileID uint8, aRequestEvent OnuDeviceEvent, aName string, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 137 | apDeviceHandler *deviceHandler, aCommChannel chan Message) *uniPonAniConfigFsm { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 138 | instFsm := &uniPonAniConfigFsm{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 139 | pDeviceHandler: apDeviceHandler, |
| 140 | deviceID: apDeviceHandler.deviceID, |
| 141 | pOmciCC: apDevOmciCC, |
| 142 | pOnuUniPort: apUniPort, |
| 143 | pUniTechProf: apUniTechProf, |
| 144 | pOnuDB: apOnuDB, |
| 145 | techProfileID: aTechProfileID, |
| 146 | requestEvent: aRequestEvent, |
| 147 | chanSet: false, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 148 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 149 | instFsm.uniTpKey = uniTP{uniID: apUniPort.uniID, tpID: aTechProfileID} |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame^] | 150 | instFsm.waitFlowDeleteChannel = make(chan bool) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 151 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 152 | instFsm.pAdaptFsm = NewAdapterFsm(aName, instFsm.deviceID, aCommChannel) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 153 | if instFsm.pAdaptFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 154 | logger.Errorw(ctx, "uniPonAniConfigFsm's AdapterFsm could not be instantiated!!", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 155 | "device-id": instFsm.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 156 | return nil |
| 157 | } |
| 158 | |
| 159 | instFsm.pAdaptFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 160 | aniStDisabled, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 161 | fsm.Events{ |
| 162 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 163 | {Name: aniEvStart, Src: []string{aniStDisabled}, Dst: aniStStarting}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 164 | |
| 165 | //Note: .1p-Mapper and MBPCD might also have multi instances (per T-Cont) - by now only one 1 T-Cont considered! |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 166 | {Name: aniEvStartConfig, Src: []string{aniStStarting}, Dst: aniStCreatingDot1PMapper}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 167 | {Name: aniEvRxDot1pmapCResp, Src: []string{aniStCreatingDot1PMapper}, Dst: aniStCreatingMBPCD}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 168 | {Name: aniEvRxMbpcdResp, Src: []string{aniStCreatingMBPCD}, Dst: aniStSettingTconts}, |
| 169 | {Name: aniEvRxTcontsResp, Src: []string{aniStSettingTconts}, Dst: aniStCreatingGemNCTPs}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 170 | // the creatingGemNCTPs state is used for multi ME config if required for all configured/available GemPorts |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 171 | {Name: aniEvRxGemntcpsResp, Src: []string{aniStCreatingGemNCTPs}, Dst: aniStCreatingGemIWs}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 172 | // the creatingGemIWs state is used for multi ME config if required for all configured/available GemPorts |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 173 | {Name: aniEvRxGemiwsResp, Src: []string{aniStCreatingGemIWs}, Dst: aniStSettingPQs}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 174 | // the settingPQs state is used for multi ME config if required for all configured/available upstream PriorityQueues |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 175 | {Name: aniEvRxPrioqsResp, Src: []string{aniStSettingPQs}, Dst: aniStSettingDot1PMapper}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 176 | {Name: aniEvRxDot1pmapSResp, Src: []string{aniStSettingDot1PMapper}, Dst: aniStConfigDone}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 177 | |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 178 | //for removing Gem related resources |
| 179 | {Name: aniEvRemGemiw, Src: []string{aniStConfigDone}, Dst: aniStRemovingGemIW}, |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 180 | {Name: aniEvWaitFlowRem, Src: []string{aniStRemovingGemIW}, Dst: aniStWaitingFlowRem}, |
| 181 | {Name: aniEvFlowRemDone, Src: []string{aniStWaitingFlowRem}, Dst: aniStRemovingGemIW}, |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 182 | {Name: aniEvRxRemGemiwResp, Src: []string{aniStRemovingGemIW}, Dst: aniStRemovingGemNCTP}, |
| 183 | {Name: aniEvRxRemGemntpResp, Src: []string{aniStRemovingGemNCTP}, Dst: aniStConfigDone}, |
| 184 | |
| 185 | //for removing TCONT related resources |
| 186 | {Name: aniEvRemTcontPath, Src: []string{aniStConfigDone}, Dst: aniStResetTcont}, |
| 187 | {Name: aniEvRxResetTcontResp, Src: []string{aniStResetTcont}, Dst: aniStRemDot1PMapper}, |
| 188 | {Name: aniEvRxRem1pMapperResp, Src: []string{aniStRemDot1PMapper}, Dst: aniStRemAniBPCD}, |
| 189 | {Name: aniEvRxRemAniBPCDResp, Src: []string{aniStRemAniBPCD}, Dst: aniStRemoveDone}, |
| 190 | |
| 191 | {Name: aniEvTimeoutSimple, Src: []string{aniStCreatingDot1PMapper, aniStCreatingMBPCD, aniStSettingTconts, aniStSettingDot1PMapper, |
| 192 | aniStRemovingGemIW, aniStRemovingGemNCTP, |
| 193 | aniStResetTcont, aniStRemDot1PMapper, aniStRemAniBPCD, aniStRemoveDone}, Dst: aniStStarting}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 194 | {Name: aniEvTimeoutMids, Src: []string{ |
| 195 | aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs}, Dst: aniStStarting}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 196 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 197 | // exceptional treatment for all states except aniStResetting |
| 198 | {Name: aniEvReset, Src: []string{aniStStarting, aniStCreatingDot1PMapper, aniStCreatingMBPCD, |
| 199 | aniStSettingTconts, aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs, aniStSettingDot1PMapper, |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame^] | 200 | aniStConfigDone, aniStRemovingGemIW, aniStWaitingFlowRem, aniStRemovingGemNCTP, |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 201 | aniStResetTcont, aniStRemDot1PMapper, aniStRemAniBPCD, aniStRemoveDone}, Dst: aniStResetting}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 202 | // the only way to get to resource-cleared disabled state again is via "resseting" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 203 | {Name: aniEvRestart, Src: []string{aniStResetting}, Dst: aniStDisabled}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 204 | }, |
| 205 | |
| 206 | fsm.Callbacks{ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 207 | "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(ctx, e) }, |
| 208 | ("enter_" + aniStStarting): func(e *fsm.Event) { instFsm.enterConfigStartingState(ctx, e) }, |
| 209 | ("enter_" + aniStCreatingDot1PMapper): func(e *fsm.Event) { instFsm.enterCreatingDot1PMapper(ctx, e) }, |
| 210 | ("enter_" + aniStCreatingMBPCD): func(e *fsm.Event) { instFsm.enterCreatingMBPCD(ctx, e) }, |
| 211 | ("enter_" + aniStSettingTconts): func(e *fsm.Event) { instFsm.enterSettingTconts(ctx, e) }, |
| 212 | ("enter_" + aniStCreatingGemNCTPs): func(e *fsm.Event) { instFsm.enterCreatingGemNCTPs(ctx, e) }, |
| 213 | ("enter_" + aniStCreatingGemIWs): func(e *fsm.Event) { instFsm.enterCreatingGemIWs(ctx, e) }, |
| 214 | ("enter_" + aniStSettingPQs): func(e *fsm.Event) { instFsm.enterSettingPQs(ctx, e) }, |
| 215 | ("enter_" + aniStSettingDot1PMapper): func(e *fsm.Event) { instFsm.enterSettingDot1PMapper(ctx, e) }, |
| 216 | ("enter_" + aniStConfigDone): func(e *fsm.Event) { instFsm.enterAniConfigDone(ctx, e) }, |
| 217 | ("enter_" + aniStRemovingGemIW): func(e *fsm.Event) { instFsm.enterRemovingGemIW(ctx, e) }, |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame^] | 218 | ("enter_" + aniStWaitingFlowRem): func(e *fsm.Event) { instFsm.enterWaitingFlowRem(ctx, e) }, |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 219 | ("enter_" + aniStRemovingGemNCTP): func(e *fsm.Event) { instFsm.enterRemovingGemNCTP(ctx, e) }, |
| 220 | ("enter_" + aniStResetTcont): func(e *fsm.Event) { instFsm.enterResettingTcont(ctx, e) }, |
| 221 | ("enter_" + aniStRemDot1PMapper): func(e *fsm.Event) { instFsm.enterRemoving1pMapper(ctx, e) }, |
| 222 | ("enter_" + aniStRemAniBPCD): func(e *fsm.Event) { instFsm.enterRemovingAniBPCD(ctx, e) }, |
| 223 | ("enter_" + aniStRemoveDone): func(e *fsm.Event) { instFsm.enterAniRemoveDone(ctx, e) }, |
| 224 | ("enter_" + aniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(ctx, e) }, |
| 225 | ("enter_" + aniStDisabled): func(e *fsm.Event) { instFsm.enterDisabledState(ctx, e) }, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 226 | }, |
| 227 | ) |
| 228 | if instFsm.pAdaptFsm.pFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 229 | logger.Errorw(ctx, "uniPonAniConfigFsm's Base FSM could not be instantiated!!", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 230 | "device-id": instFsm.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 231 | return nil |
| 232 | } |
| 233 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 234 | logger.Debugw(ctx, "uniPonAniConfigFsm created", log.Fields{"device-id": instFsm.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 235 | return instFsm |
| 236 | } |
| 237 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 238 | //setFsmCompleteChannel sets the requested channel and channel result for transfer on success |
| 239 | func (oFsm *uniPonAniConfigFsm) setFsmCompleteChannel(aChSuccess chan<- uint8, aProcStep uint8) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 240 | oFsm.chSuccess = aChSuccess |
| 241 | oFsm.procStep = aProcStep |
| 242 | oFsm.chanSet = true |
| 243 | } |
| 244 | |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 245 | //CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 246 | func (oFsm *uniPonAniConfigFsm) CancelProcessing(ctx context.Context) { |
| 247 | //early indication about started reset processing |
| 248 | oFsm.pUniTechProf.setProfileResetting(ctx, oFsm.pOnuUniPort.uniID, oFsm.techProfileID, true) |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 249 | //mutex protection is required for possible concurrent access to FSM members |
| 250 | oFsm.mutexIsAwaitingResponse.RLock() |
| 251 | defer oFsm.mutexIsAwaitingResponse.RUnlock() |
| 252 | if oFsm.isAwaitingResponse { |
| 253 | //use channel to indicate that the response waiting shall be aborted |
| 254 | oFsm.omciMIdsResponseReceived <- false |
| 255 | } |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame^] | 256 | if oFsm.isWaitingForFlowDelete { |
| 257 | //use channel to indicate that the response waiting shall be aborted |
| 258 | oFsm.waitFlowDeleteChannel <- false |
| 259 | } |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 260 | // in any case (even if it might be automatically requested by above cancellation of waiting) ensure resetting the FSM |
| 261 | pAdaptFsm := oFsm.pAdaptFsm |
| 262 | if pAdaptFsm != nil { |
| 263 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 264 | go func(aPAFsm *AdapterFsm) { |
| 265 | if aPAFsm.pFsm != nil { |
| 266 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
| 267 | } |
| 268 | }(pAdaptFsm) |
| 269 | } |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 270 | |
| 271 | //wait for completion of possibly ongoing techprofile config/remove requests to avoid |
| 272 | // access conflicts on internal data by next needed data clearance |
| 273 | //activity should be aborted in short time if running with FSM due to above FSM reset |
| 274 | // or finished without FSM dependency in short time |
| 275 | oFsm.pUniTechProf.lockTpProcMutex() |
| 276 | defer oFsm.pUniTechProf.unlockTpProcMutex() |
| 277 | //remove all TechProf related internal data to allow for new configuration |
| 278 | oFsm.pUniTechProf.clearAniSideConfig(ctx, oFsm.pOnuUniPort.uniID, oFsm.techProfileID) |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 279 | } |
| 280 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 281 | func (oFsm *uniPonAniConfigFsm) prepareAndEnterConfigState(ctx context.Context, aPAFsm *AdapterFsm) { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 282 | if aPAFsm != nil && aPAFsm.pFsm != nil { |
| 283 | //stick to pythonAdapter numbering scheme |
| 284 | //index 0 in naming refers to possible usage of multiple instances (later) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 285 | oFsm.mapperSP0ID = ieeeMapperServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo) + uint16(oFsm.techProfileID) |
| 286 | oFsm.macBPCD0ID = macBridgePortAniEID + uint16(oFsm.pOnuUniPort.entityID) + uint16(oFsm.techProfileID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 287 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 288 | /* |
| 289 | // Find a free TCONT Instance ID and use it |
| 290 | foundFreeTcontInstID := false |
| 291 | */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 292 | if tcontInstKeys := oFsm.pOnuDB.getSortedInstKeys(ctx, me.TContClassID); len(tcontInstKeys) > 0 { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 293 | |
| 294 | // FIXME: Ideally the ME configurations on the ONU should constantly be MIB Synced back to the ONU DB |
| 295 | // So, as soon as we use up a TCONT Entity on the ONU, the DB at ONU adapter should know that the TCONT |
| 296 | // entity is used up via MIB Sync procedure and it will not use it for subsequent TCONT on that ONU. |
| 297 | // But, it seems, due to the absence of the constant mib-sync procedure, the TCONT Entities show up as |
| 298 | // free even though they are already reserved on the ONU. It seems the mib is synced only once, initially |
| 299 | // when the ONU is discovered. |
| 300 | /* |
| 301 | for _, tcontInstID := range tcontInstKeys { |
| 302 | tconInst := oFsm.pOnuDB.GetMe(me.TContClassID, tcontInstID) |
| 303 | returnVal := tconInst["AllocId"] |
| 304 | if returnVal != nil { |
| 305 | if allocID, err := oFsm.pOnuDB.getUint16Attrib(returnVal); err == nil { |
| 306 | // If the TCONT Instance ID is set to 0xff or 0xffff, it means it is free to use. |
| 307 | if allocID == 0xff || allocID == 0xffff { |
| 308 | foundFreeTcontInstID = true |
| 309 | oFsm.tcont0ID = uint16(tcontInstID) |
| 310 | logger.Debugw("Used TcontId:", log.Fields{"TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16), |
| 311 | "device-id": oFsm.deviceID}) |
| 312 | break |
| 313 | } |
| 314 | } else { |
| 315 | logger.Errorw("error-converting-alloc-id-to-uint16", log.Fields{"device-id": oFsm.deviceID, "tcont-inst": tcontInstID}) |
| 316 | } |
| 317 | } else { |
| 318 | logger.Errorw("error-extracting-alloc-id-attribute", log.Fields{"device-id": oFsm.deviceID, "tcont-inst": tcontInstID}) |
| 319 | } |
| 320 | } |
| 321 | */ |
| 322 | |
| 323 | // Ensure that the techProfileID is in a valid range so that we can allocate a free Tcont for it. |
| 324 | if oFsm.techProfileID >= tpIDOffset && oFsm.techProfileID < uint8(tpIDOffset+len(tcontInstKeys)) { |
| 325 | // For now, as a dirty workaround, use the tpIDOffset to index the TcontEntityID to be used. |
| 326 | // The first TP ID for the ONU will get the first TcontEntityID, the next will get second and so on. |
| 327 | // Here the assumption is TP ID will always start from 64 (this is also true to Technology Profile Specification) and the |
| 328 | // TP ID will increment in single digit |
| 329 | oFsm.tcont0ID = tcontInstKeys[oFsm.techProfileID-tpIDOffset] |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 330 | logger.Debugw(ctx, "Used TcontId:", log.Fields{"TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16), |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 331 | "device-id": oFsm.deviceID}) |
| 332 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 333 | logger.Errorw(ctx, "tech profile id not in valid range", log.Fields{"device-id": oFsm.deviceID, "tp-id": oFsm.techProfileID, "num-tcont": len(tcontInstKeys)}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 334 | if oFsm.chanSet { |
| 335 | // indicate processing error/abort to the caller |
| 336 | oFsm.chSuccess <- 0 |
| 337 | oFsm.chanSet = false //reset the internal channel state |
| 338 | } |
| 339 | //reset the state machine to enable usage on subsequent requests |
| 340 | _ = aPAFsm.pFsm.Event(aniEvReset) |
| 341 | return |
| 342 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 343 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 344 | logger.Errorw(ctx, "No TCont instances found", log.Fields{"device-id": oFsm.deviceID}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 345 | return |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 346 | } |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 347 | /* |
| 348 | if !foundFreeTcontInstID { |
| 349 | // This should never happen. If it does, the behavior is unpredictable. |
| 350 | logger.Warnw("No free TCONT instances found", log.Fields{"device-id": oFsm.deviceID}) |
| 351 | }*/ |
| 352 | |
| 353 | // Access critical state with lock |
| 354 | oFsm.pUniTechProf.mutexTPState.Lock() |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 355 | oFsm.alloc0ID = oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID |
| 356 | mapGemPortParams := oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].mapGemPortParams |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 357 | oFsm.pUniTechProf.mutexTPState.Unlock() |
| 358 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 359 | //for all TechProfile set GemIndices |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 360 | for _, gemEntry := range mapGemPortParams { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 361 | loGemPortAttribs := ponAniGemPortAttribs{} |
| 362 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 363 | //collect all GemConfigData in a separate Fsm related slice (needed also to avoid mix-up with unsorted mapPonAniConfig) |
| 364 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 365 | if queueInstKeys := oFsm.pOnuDB.getSortedInstKeys(ctx, me.PriorityQueueClassID); len(queueInstKeys) > 0 { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 366 | |
| 367 | loGemPortAttribs.gemPortID = gemEntry.gemPortID |
| 368 | // MibDb usage: upstream PrioQueue.RelatedPort = xxxxyyyy with xxxx=TCont.Entity(incl. slot) and yyyy=prio |
| 369 | // i.e.: search PrioQueue list with xxxx=actual T-Cont.Entity, |
| 370 | // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == yyyy (expect 0..7) |
| 371 | usQrelPortMask := uint32((((uint32)(oFsm.tcont0ID)) << 16) + uint32(gemEntry.prioQueueIndex)) |
| 372 | |
| 373 | // MibDb usage: downstream PrioQueue.RelatedPort = xxyyzzzz with xx=slot, yy=UniPort and zzzz=prio |
| 374 | // i.e.: search PrioQueue list with yy=actual pOnuUniPort.uniID, |
| 375 | // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == zzzz (expect 0..7) |
| 376 | // Note: As we do not maintain any slot numbering, slot number will be excluded from seatch pattern. |
| 377 | // Furthermore OMCI Onu port-Id is expected to start with 1 (not 0). |
| 378 | dsQrelPortMask := uint32((((uint32)(oFsm.pOnuUniPort.uniID + 1)) << 16) + uint32(gemEntry.prioQueueIndex)) |
| 379 | |
| 380 | usQueueFound := false |
| 381 | dsQueueFound := false |
| 382 | for _, mgmtEntityID := range queueInstKeys { |
| 383 | if meAttributes := oFsm.pOnuDB.GetMe(me.PriorityQueueClassID, mgmtEntityID); meAttributes != nil { |
| 384 | returnVal := meAttributes["RelatedPort"] |
| 385 | if returnVal != nil { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 386 | if relatedPort, err := oFsm.pOnuDB.getUint32Attrib(returnVal); err == nil { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 387 | if relatedPort == usQrelPortMask { |
| 388 | loGemPortAttribs.upQueueID = mgmtEntityID |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 389 | logger.Debugw(ctx, "UpQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 390 | "upQueueID": strconv.FormatInt(int64(loGemPortAttribs.upQueueID), 16), "device-id": oFsm.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 391 | usQueueFound = true |
| 392 | } else if (relatedPort&0xFFFFFF) == dsQrelPortMask && mgmtEntityID < 0x8000 { |
| 393 | loGemPortAttribs.downQueueID = mgmtEntityID |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 394 | logger.Debugw(ctx, "DownQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 395 | "downQueueID": strconv.FormatInt(int64(loGemPortAttribs.downQueueID), 16), "device-id": oFsm.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 396 | dsQueueFound = true |
| 397 | } |
| 398 | if usQueueFound && dsQueueFound { |
| 399 | break |
| 400 | } |
| 401 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 402 | logger.Warnw(ctx, "Could not convert attribute value", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 403 | } |
| 404 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 405 | logger.Warnw(ctx, "'RelatedPort' not found in meAttributes:", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 406 | } |
| 407 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 408 | logger.Warnw(ctx, "No attributes available in DB:", log.Fields{"meClassID": me.PriorityQueueClassID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 409 | "mgmtEntityID": mgmtEntityID, "device-id": oFsm.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 413 | logger.Warnw(ctx, "No PriorityQueue instances found", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 414 | } |
| 415 | loGemPortAttribs.direction = gemEntry.direction |
| 416 | loGemPortAttribs.qosPolicy = gemEntry.queueSchedPolicy |
| 417 | loGemPortAttribs.weight = gemEntry.queueWeight |
| 418 | loGemPortAttribs.pbitString = gemEntry.pbitString |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 419 | if gemEntry.isMulticast { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 420 | //TODO this might effectively ignore the for loop starting at line 316 |
| 421 | loGemPortAttribs.gemPortID = gemEntry.multicastGemPortID |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 422 | loGemPortAttribs.isMulticast = true |
| 423 | loGemPortAttribs.multicastGemID = gemEntry.multicastGemPortID |
| 424 | loGemPortAttribs.staticACL = gemEntry.staticACL |
| 425 | loGemPortAttribs.dynamicACL = gemEntry.dynamicACL |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 426 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 427 | logger.Debugw(ctx, "Multicast GemPort attributes:", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 428 | "gemPortID": loGemPortAttribs.gemPortID, |
| 429 | "isMulticast": loGemPortAttribs.isMulticast, |
| 430 | "multicastGemID": loGemPortAttribs.multicastGemID, |
| 431 | "staticACL": loGemPortAttribs.staticACL, |
| 432 | "dynamicACL": loGemPortAttribs.dynamicACL, |
| 433 | }) |
| 434 | |
| 435 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 436 | logger.Debugw(ctx, "Upstream GemPort attributes:", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 437 | "gemPortID": loGemPortAttribs.gemPortID, |
| 438 | "upQueueID": loGemPortAttribs.upQueueID, |
| 439 | "downQueueID": loGemPortAttribs.downQueueID, |
| 440 | "pbitString": loGemPortAttribs.pbitString, |
| 441 | "prioQueueIndex": gemEntry.prioQueueIndex, |
| 442 | }) |
| 443 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 444 | |
| 445 | oFsm.gemPortAttribsSlice = append(oFsm.gemPortAttribsSlice, loGemPortAttribs) |
| 446 | } |
| 447 | _ = aPAFsm.pFsm.Event(aniEvStartConfig) |
| 448 | } |
| 449 | } |
| 450 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 451 | func (oFsm *uniPonAniConfigFsm) enterConfigStartingState(ctx context.Context, e *fsm.Event) { |
| 452 | logger.Debugw(ctx, "UniPonAniConfigFsm start", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 453 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 454 | // in case the used channel is not yet defined (can be re-used after restarts) |
| 455 | if oFsm.omciMIdsResponseReceived == nil { |
| 456 | oFsm.omciMIdsResponseReceived = make(chan bool) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 457 | logger.Debug(ctx, "uniPonAniConfigFsm - OMCI multiInstance RxChannel defined") |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 458 | } else { |
| 459 | // as we may 're-use' this instance of FSM and the connected channel |
| 460 | // make sure there is no 'lingering' request in the already existing channel: |
| 461 | // (simple loop sufficient as we are the only receiver) |
| 462 | for len(oFsm.omciMIdsResponseReceived) > 0 { |
| 463 | <-oFsm.omciMIdsResponseReceived |
| 464 | } |
| 465 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 466 | //ensure internal slices are empty (which might be set from previous run) - release memory |
| 467 | oFsm.gemPortAttribsSlice = nil |
| 468 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 469 | // start go routine for processing of ANI config messages |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 470 | go oFsm.processOmciAniMessages(ctx) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 471 | |
| 472 | //let the state machine run forward from here directly |
| 473 | pConfigAniStateAFsm := oFsm.pAdaptFsm |
| 474 | if pConfigAniStateAFsm != nil { |
| 475 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 476 | go oFsm.prepareAndEnterConfigState(ctx, pConfigAniStateAFsm) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 477 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 481 | func (oFsm *uniPonAniConfigFsm) enterCreatingDot1PMapper(ctx context.Context, e *fsm.Event) { |
| 482 | logger.Debugw(ctx, "uniPonAniConfigFsm Tx Create::Dot1PMapper", log.Fields{ |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 483 | "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16), |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 484 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
| 485 | oFsm.requestEventOffset = 0 //0 offset for last config request activity |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 486 | meInstance := oFsm.pOmciCC.sendCreateDot1PMapper(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 487 | oFsm.mapperSP0ID, oFsm.pAdaptFsm.commChan) |
| 488 | //accept also nil as (error) return value for writing to LastTx |
| 489 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 490 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 491 | } |
| 492 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 493 | func (oFsm *uniPonAniConfigFsm) enterCreatingMBPCD(ctx context.Context, e *fsm.Event) { |
| 494 | logger.Debugw(ctx, "uniPonAniConfigFsm Tx Create::MBPCD", log.Fields{ |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 495 | "EntitytId": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16), |
| 496 | "TPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16), |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 497 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 498 | bridgePtr := macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo) //cmp also omci_cc.go::sendCreateMBServiceProfile |
| 499 | meParams := me.ParamData{ |
| 500 | EntityID: oFsm.macBPCD0ID, |
| 501 | Attributes: me.AttributeValueMap{ |
| 502 | "BridgeIdPointer": bridgePtr, |
| 503 | "PortNum": 0xFF, //fixed unique ANI side indication |
| 504 | "TpType": 3, //for .1PMapper |
| 505 | "TpPointer": oFsm.mapperSP0ID, |
| 506 | }, |
| 507 | } |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 508 | meInstance := oFsm.pOmciCC.sendCreateMBPConfigDataVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 509 | oFsm.pAdaptFsm.commChan, meParams) |
| 510 | //accept also nil as (error) return value for writing to LastTx |
| 511 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 512 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 513 | } |
| 514 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 515 | func (oFsm *uniPonAniConfigFsm) enterSettingTconts(ctx context.Context, e *fsm.Event) { |
| 516 | logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::Tcont", log.Fields{ |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 517 | "EntitytId": strconv.FormatInt(int64(oFsm.tcont0ID), 16), |
| 518 | "AllocId": strconv.FormatInt(int64(oFsm.alloc0ID), 16), |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 519 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 520 | meParams := me.ParamData{ |
| 521 | EntityID: oFsm.tcont0ID, |
| 522 | Attributes: me.AttributeValueMap{ |
| 523 | "AllocId": oFsm.alloc0ID, |
| 524 | }, |
| 525 | } |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 526 | meInstance := oFsm.pOmciCC.sendSetTcontVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 527 | oFsm.pAdaptFsm.commChan, meParams) |
| 528 | //accept also nil as (error) return value for writing to LastTx |
| 529 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 530 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 531 | } |
| 532 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 533 | func (oFsm *uniPonAniConfigFsm) enterCreatingGemNCTPs(ctx context.Context, e *fsm.Event) { |
| 534 | logger.Debugw(ctx, "uniPonAniConfigFsm - start creating GemNWCtp loop", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 535 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 536 | go oFsm.performCreatingGemNCTPs(ctx) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 537 | } |
| 538 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 539 | func (oFsm *uniPonAniConfigFsm) enterCreatingGemIWs(ctx context.Context, e *fsm.Event) { |
| 540 | logger.Debugw(ctx, "uniPonAniConfigFsm - start creating GemIwTP loop", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 541 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 542 | go oFsm.performCreatingGemIWs(ctx) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 543 | } |
| 544 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 545 | func (oFsm *uniPonAniConfigFsm) enterSettingPQs(ctx context.Context, e *fsm.Event) { |
| 546 | logger.Debugw(ctx, "uniPonAniConfigFsm - start setting PrioQueue loop", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 547 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 548 | go oFsm.performSettingPQs(ctx) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 549 | } |
| 550 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 551 | func (oFsm *uniPonAniConfigFsm) enterSettingDot1PMapper(ctx context.Context, e *fsm.Event) { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 552 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 553 | logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::.1pMapper with all PBits set", log.Fields{"EntitytId": 0x8042, /*cmp above*/ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 554 | "toGemIw": 1024, /* cmp above */ |
| 555 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 556 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 557 | logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::1pMapper", log.Fields{ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 558 | "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 559 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 560 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 561 | meParams := me.ParamData{ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 562 | EntityID: oFsm.mapperSP0ID, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 563 | Attributes: make(me.AttributeValueMap), |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 564 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 565 | |
| 566 | //assign the GemPorts according to the configured Prio |
| 567 | var loPrioGemPortArray [8]uint16 |
| 568 | for _, gemPortAttribs := range oFsm.gemPortAttribsSlice { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 569 | if gemPortAttribs.isMulticast { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 570 | logger.Debugw(ctx, "uniPonAniConfigFsm Port is Multicast, ignoring .1pMapper", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 571 | "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID, |
| 572 | "prioString": gemPortAttribs.pbitString}) |
| 573 | continue |
| 574 | } |
| 575 | if gemPortAttribs.pbitString == "" { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 576 | logger.Warnw(ctx, "uniPonAniConfigFsm PrioString empty string error", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 577 | "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID, |
| 578 | "prioString": gemPortAttribs.pbitString}) |
| 579 | continue |
| 580 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 581 | for i := 0; i < 8; i++ { |
| 582 | // "lenOfPbitMap(8) - i + 1" will give i-th pbit value from LSB position in the pbit map string |
| 583 | if prio, err := strconv.Atoi(string(gemPortAttribs.pbitString[7-i])); err == nil { |
| 584 | if prio == 1 { // Check this p-bit is set |
| 585 | if loPrioGemPortArray[i] == 0 { |
| 586 | loPrioGemPortArray[i] = gemPortAttribs.gemPortID //gemPortId=EntityID and unique |
| 587 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 588 | logger.Warnw(ctx, "uniPonAniConfigFsm PrioString not unique", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 589 | "device-id": oFsm.deviceID, "IgnoredGemPort": gemPortAttribs.gemPortID, |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 590 | "SetGemPort": loPrioGemPortArray[i]}) |
| 591 | } |
| 592 | } |
| 593 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 594 | logger.Warnw(ctx, "uniPonAniConfigFsm PrioString evaluation error", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 595 | "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID, |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 596 | "prioString": gemPortAttribs.pbitString, "position": i}) |
| 597 | } |
| 598 | |
| 599 | } |
| 600 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 601 | |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 602 | var foundIwPtr = false |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 603 | for index, value := range loPrioGemPortArray { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 604 | meAttribute := fmt.Sprintf("InterworkTpPointerForPBitPriority%d", index) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 605 | if value != 0 { |
| 606 | foundIwPtr = true |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 607 | meParams.Attributes[meAttribute] = value |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 608 | logger.Debugw(ctx, "UniPonAniConfigFsm Set::1pMapper", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 609 | "for Prio": index, |
| 610 | "IwPtr": strconv.FormatInt(int64(value), 16), |
| 611 | "device-id": oFsm.deviceID}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 612 | } else { |
| 613 | // The null pointer 0xFFFF specifies that frames with the associated priority are to be discarded. |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 614 | // setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting |
| 615 | // but except for processing effort does not really harm - left to keep changes low |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 616 | meParams.Attributes[meAttribute] = 0xffff |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 617 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 618 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 619 | // The TP type value 0 also indicates bridging mapping, and the TP pointer should be set to 0xFFFF |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 620 | // setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting |
| 621 | // but except for processing effort does not really harm - left to keep changes low |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 622 | meParams.Attributes["TpPointer"] = 0xffff |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 623 | |
| 624 | if !foundIwPtr { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 625 | logger.Debugw(ctx, "UniPonAniConfigFsm no GemIwPtr found for .1pMapper - abort", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 626 | "device-id": oFsm.deviceID}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 627 | //TODO With multicast is possible that no upstream gem ports are not present in the tech profile, |
| 628 | // this reset needs to be performed only if the tech profile provides upstream gem ports but no priority is set |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 629 | //let's reset the state machine in order to release all resources now |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 630 | //pConfigAniStateAFsm := oFsm.pAdaptFsm |
| 631 | //if pConfigAniStateAFsm != nil { |
| 632 | // // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 633 | // go func(aPAFsm *AdapterFsm) { |
| 634 | // if aPAFsm != nil && aPAFsm.pFsm != nil { |
| 635 | // _ = aPAFsm.pFsm.Event(aniEvReset) |
| 636 | // } |
| 637 | // }(pConfigAniStateAFsm) |
| 638 | //} |
| 639 | //Moving forward the FSM as if the response was received correctly. |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 640 | pConfigAniStateAFsm := oFsm.pAdaptFsm |
| 641 | if pConfigAniStateAFsm != nil { |
| 642 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 643 | go func(aPAFsm *AdapterFsm) { |
| 644 | if aPAFsm != nil && aPAFsm.pFsm != nil { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 645 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxDot1pmapSResp) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 646 | } |
| 647 | }(pConfigAniStateAFsm) |
| 648 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 649 | } else { |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 650 | meInstance := oFsm.pOmciCC.sendSetDot1PMapperVar(context.TODO(), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 651 | oFsm.pAdaptFsm.commChan, meParams) |
| 652 | //accept also nil as (error) return value for writing to LastTx |
| 653 | // - this avoids misinterpretation of new received OMCI messages |
| 654 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 655 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 656 | } |
| 657 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 658 | func (oFsm *uniPonAniConfigFsm) enterAniConfigDone(ctx context.Context, e *fsm.Event) { |
| 659 | logger.Debugw(ctx, "uniPonAniConfigFsm ani config done", log.Fields{ |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 660 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, "techProfile-id": oFsm.techProfileID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 661 | //use DeviceHandler event notification directly |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 662 | oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset))) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 663 | //store that the UNI related techProfile processing is done for the given Profile and Uni |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 664 | oFsm.pUniTechProf.setConfigDone(oFsm.pOnuUniPort.uniID, oFsm.techProfileID, true) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 665 | //if techProfile processing is done it must be checked, if some prior/parallel flow configuration is pending |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 666 | // but only in case the techProfile was configured (not deleted) |
| 667 | if oFsm.requestEventOffset == 0 { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 668 | go oFsm.pDeviceHandler.verifyUniVlanConfigRequest(ctx, oFsm.pOnuUniPort, oFsm.techProfileID) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 669 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 670 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 671 | if oFsm.chanSet { |
| 672 | // indicate processing done to the caller |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 673 | logger.Debugw(ctx, "uniPonAniConfigFsm processingDone on channel", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 674 | "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 675 | oFsm.chSuccess <- oFsm.procStep |
| 676 | oFsm.chanSet = false //reset the internal channel state |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 677 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 678 | |
| 679 | //the FSM is left active in this state as long as no specific reset or remove is requested from outside |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 680 | } |
| 681 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 682 | func (oFsm *uniPonAniConfigFsm) enterRemovingGemIW(ctx context.Context, e *fsm.Event) { |
mpagenko | a23a629 | 2021-02-23 10:40:10 +0000 | [diff] [blame] | 683 | oFsm.pUniTechProf.mutexTPState.Lock() |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame^] | 684 | //flush the waitFlowDeleteChannel - possibly already/still set by some previous activity |
| 685 | select { |
| 686 | case <-oFsm.waitFlowDeleteChannel: |
| 687 | logger.Debug(ctx, "flushed waitFlowDeleteChannel") |
| 688 | default: |
| 689 | } |
| 690 | if oFsm.pDeviceHandler.UniVlanConfigFsmMap[oFsm.pOnuUniPort.uniID].IsFlowRemovePending(oFsm.waitFlowDeleteChannel) { |
mpagenko | a23a629 | 2021-02-23 10:40:10 +0000 | [diff] [blame] | 691 | oFsm.pUniTechProf.mutexTPState.Unlock() |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 692 | logger.Debugw(ctx, "flow remove pending - wait before processing gem port delete", |
| 693 | log.Fields{"device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, "techProfile-id": oFsm.techProfileID}) |
| 694 | // if flow remove is pending then wait for flow remove to finish first before proceeding with gem port delete |
| 695 | pConfigAniStateAFsm := oFsm.pAdaptFsm |
| 696 | if pConfigAniStateAFsm != nil { |
| 697 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 698 | go func(aPAFsm *AdapterFsm) { |
| 699 | if aPAFsm != nil && aPAFsm.pFsm != nil { |
| 700 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvWaitFlowRem) |
| 701 | } |
| 702 | }(pConfigAniStateAFsm) |
| 703 | } else { |
| 704 | logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{"device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, "techProfile-id": oFsm.techProfileID}) |
| 705 | } |
| 706 | return |
| 707 | } |
| 708 | |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 709 | // get the related GemPort entity Id from pUniTechProf, OMCI Gem* entityID is set to be equal to GemPortId! |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 710 | loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID |
| 711 | oFsm.pUniTechProf.mutexTPState.Unlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 712 | logger.Debugw(ctx, "uniPonAniConfigFsm - start removing one GemIwTP", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 713 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, |
| 714 | "GemIwTp-entity-id": loGemPortID}) |
| 715 | oFsm.requestEventOffset = 1 //offset 1 to indicate last activity = remove |
| 716 | |
| 717 | // this state entry is only expected in a suitable state (checked outside in onu_uni_tp) |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 718 | meInstance := oFsm.pOmciCC.sendDeleteGemIWTP(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 719 | oFsm.pAdaptFsm.commChan, loGemPortID) |
| 720 | oFsm.pLastTxMeInstance = meInstance |
| 721 | } |
| 722 | |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame^] | 723 | func (oFsm *uniPonAniConfigFsm) enterWaitingFlowRem(ctx context.Context, e *fsm.Event) { |
| 724 | oFsm.mutexIsAwaitingResponse.Lock() |
| 725 | oFsm.isWaitingForFlowDelete = true |
| 726 | oFsm.mutexIsAwaitingResponse.Unlock() |
| 727 | select { |
| 728 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
| 729 | // case <-ctx.Done(): |
| 730 | // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID}) |
| 731 | case <-time.After(10 * time.Second): //give flow processing enough time to finish (but try to be less than rwCore flow timeouts) |
| 732 | logger.Warnw(ctx, "uniPonAniConfigFsm WaitingFlowRem timeout", log.Fields{ |
| 733 | "for device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, "techProfile-id": oFsm.techProfileID}) |
| 734 | oFsm.mutexIsAwaitingResponse.Lock() |
| 735 | oFsm.isWaitingForFlowDelete = false |
| 736 | oFsm.mutexIsAwaitingResponse.Unlock() |
| 737 | //if the flow is not removed as expected we just try to continue with GemPort removal and hope things are clearing up afterwards |
| 738 | pConfigAniStateAFsm := oFsm.pAdaptFsm |
| 739 | if pConfigAniStateAFsm != nil { |
| 740 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 741 | go func(aPAFsm *AdapterFsm) { |
| 742 | if aPAFsm != nil && aPAFsm.pFsm != nil { |
| 743 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvFlowRemDone) |
| 744 | } |
| 745 | }(pConfigAniStateAFsm) |
| 746 | } else { |
| 747 | logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{ |
| 748 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, "techProfile-id": oFsm.techProfileID}) |
| 749 | } |
| 750 | return |
| 751 | |
| 752 | case success := <-oFsm.waitFlowDeleteChannel: |
| 753 | if success { |
| 754 | logger.Debugw(ctx, "uniPonAniConfigFsm flow removed info received", log.Fields{ |
| 755 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, "techProfile-id": oFsm.techProfileID}) |
| 756 | oFsm.mutexIsAwaitingResponse.Lock() |
| 757 | oFsm.isWaitingForFlowDelete = false |
| 758 | oFsm.mutexIsAwaitingResponse.Unlock() |
| 759 | pConfigAniStateAFsm := oFsm.pAdaptFsm |
| 760 | if pConfigAniStateAFsm != nil { |
| 761 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 762 | go func(aPAFsm *AdapterFsm) { |
| 763 | if aPAFsm != nil && aPAFsm.pFsm != nil { |
| 764 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvFlowRemDone) |
| 765 | } |
| 766 | }(pConfigAniStateAFsm) |
| 767 | } else { |
| 768 | logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{ |
| 769 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, "techProfile-id": oFsm.techProfileID}) |
| 770 | } |
| 771 | return |
| 772 | } |
| 773 | // waiting was aborted (probably on external request) |
| 774 | logger.Debugw(ctx, "uniPonAniConfigFsm WaitingFlowRem aborted", log.Fields{ |
| 775 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, "techProfile-id": oFsm.techProfileID}) |
| 776 | oFsm.mutexIsAwaitingResponse.Lock() |
| 777 | oFsm.isWaitingForFlowDelete = false |
| 778 | oFsm.mutexIsAwaitingResponse.Unlock() |
| 779 | //to be sure we can just generate the reset-event to ensure leaving this state towards 'reset' |
| 780 | pConfigAniStateAFsm := oFsm.pAdaptFsm |
| 781 | if pConfigAniStateAFsm != nil { |
| 782 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 783 | go func(aPAFsm *AdapterFsm) { |
| 784 | if aPAFsm != nil && aPAFsm.pFsm != nil { |
| 785 | _ = aPAFsm.pFsm.Event(aniEvReset) |
| 786 | } |
| 787 | }(pConfigAniStateAFsm) |
| 788 | } |
| 789 | return |
| 790 | } |
| 791 | } |
| 792 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 793 | func (oFsm *uniPonAniConfigFsm) enterRemovingGemNCTP(ctx context.Context, e *fsm.Event) { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 794 | oFsm.pUniTechProf.mutexTPState.Lock() |
| 795 | loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID |
| 796 | oFsm.pUniTechProf.mutexTPState.Unlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 797 | logger.Debugw(ctx, "uniPonAniConfigFsm - start removing one GemNCTP", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 798 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID, |
| 799 | "GemNCTP-entity-id": loGemPortID}) |
| 800 | // this state entry is only expected in a suitable state (checked outside in onu_uni_tp) |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 801 | meInstance := oFsm.pOmciCC.sendDeleteGemNCTP(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 802 | oFsm.pAdaptFsm.commChan, loGemPortID) |
| 803 | oFsm.pLastTxMeInstance = meInstance |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 804 | // Mark the gem port to be removed for Performance History monitoring |
| 805 | if oFsm.pDeviceHandler.pOnuMetricsMgr != nil { |
| 806 | oFsm.pDeviceHandler.pOnuMetricsMgr.RemoveGemPortForPerfMonitoring(loGemPortID) |
| 807 | } |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 808 | } |
| 809 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 810 | func (oFsm *uniPonAniConfigFsm) enterResettingTcont(ctx context.Context, e *fsm.Event) { |
| 811 | logger.Debugw(ctx, "uniPonAniConfigFsm - start resetting the TCont", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 812 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
| 813 | |
| 814 | oFsm.requestEventOffset = 1 //offset 1 for last remove activity |
| 815 | // this state entry is only expected in a suitable state (checked outside in onu_uni_tp) |
| 816 | meParams := me.ParamData{ |
| 817 | EntityID: oFsm.tcont0ID, |
| 818 | Attributes: me.AttributeValueMap{ |
| 819 | "AllocId": unusedTcontAllocID, |
| 820 | }, |
| 821 | } |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 822 | meInstance := oFsm.pOmciCC.sendSetTcontVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 823 | oFsm.pAdaptFsm.commChan, meParams) |
| 824 | oFsm.pLastTxMeInstance = meInstance |
| 825 | } |
| 826 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 827 | func (oFsm *uniPonAniConfigFsm) enterRemoving1pMapper(ctx context.Context, e *fsm.Event) { |
| 828 | logger.Debugw(ctx, "uniPonAniConfigFsm - start deleting the .1pMapper", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 829 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
| 830 | |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 831 | meInstance := oFsm.pOmciCC.sendDeleteDot1PMapper(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 832 | oFsm.pAdaptFsm.commChan, oFsm.mapperSP0ID) |
| 833 | oFsm.pLastTxMeInstance = meInstance |
| 834 | } |
| 835 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 836 | func (oFsm *uniPonAniConfigFsm) enterRemovingAniBPCD(ctx context.Context, e *fsm.Event) { |
| 837 | logger.Debugw(ctx, "uniPonAniConfigFsm - start deleting the ANI MBCD", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 838 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
| 839 | |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 840 | meInstance := oFsm.pOmciCC.sendDeleteMBPConfigData(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 841 | oFsm.pAdaptFsm.commChan, oFsm.macBPCD0ID) |
| 842 | oFsm.pLastTxMeInstance = meInstance |
| 843 | } |
| 844 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 845 | func (oFsm *uniPonAniConfigFsm) enterAniRemoveDone(ctx context.Context, e *fsm.Event) { |
| 846 | logger.Debugw(ctx, "uniPonAniConfigFsm ani removal done", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 847 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
| 848 | //use DeviceHandler event notification directly |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 849 | oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset))) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 850 | if oFsm.chanSet { |
| 851 | // indicate processing done to the caller |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 852 | logger.Debugw(ctx, "uniPonAniConfigFsm processingDone on channel", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 853 | "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 854 | oFsm.chSuccess <- oFsm.procStep |
| 855 | oFsm.chanSet = false //reset the internal channel state |
| 856 | } |
| 857 | |
| 858 | //let's reset the state machine in order to release all resources now |
| 859 | pConfigAniStateAFsm := oFsm.pAdaptFsm |
| 860 | if pConfigAniStateAFsm != nil { |
| 861 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 862 | go func(aPAFsm *AdapterFsm) { |
| 863 | if aPAFsm != nil && aPAFsm.pFsm != nil { |
| 864 | _ = aPAFsm.pFsm.Event(aniEvReset) |
| 865 | } |
| 866 | }(pConfigAniStateAFsm) |
| 867 | } |
| 868 | } |
| 869 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 870 | func (oFsm *uniPonAniConfigFsm) enterResettingState(ctx context.Context, e *fsm.Event) { |
| 871 | logger.Debugw(ctx, "uniPonAniConfigFsm resetting", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 872 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 873 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 874 | pConfigAniStateAFsm := oFsm.pAdaptFsm |
| 875 | if pConfigAniStateAFsm != nil { |
| 876 | // abort running message processing |
| 877 | fsmAbortMsg := Message{ |
| 878 | Type: TestMsg, |
| 879 | Data: TestMessage{ |
| 880 | TestMessageVal: AbortMessageProcessing, |
| 881 | }, |
| 882 | } |
| 883 | pConfigAniStateAFsm.commChan <- fsmAbortMsg |
| 884 | |
| 885 | //try to restart the FSM to 'disabled', decouple event transfer |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 886 | go func(aPAFsm *AdapterFsm) { |
| 887 | if aPAFsm != nil && aPAFsm.pFsm != nil { |
| 888 | _ = aPAFsm.pFsm.Event(aniEvRestart) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 889 | } |
| 890 | }(pConfigAniStateAFsm) |
| 891 | } |
| 892 | } |
| 893 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 894 | func (oFsm *uniPonAniConfigFsm) enterDisabledState(ctx context.Context, e *fsm.Event) { |
| 895 | logger.Debugw(ctx, "uniPonAniConfigFsm enters disabled state", log.Fields{ |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 896 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.uniID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 897 | oFsm.pLastTxMeInstance = nil |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 898 | } |
| 899 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 900 | func (oFsm *uniPonAniConfigFsm) processOmciAniMessages(ctx context.Context) { |
| 901 | logger.Debugw(ctx, "Start uniPonAniConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 902 | loop: |
| 903 | for { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 904 | // case <-ctx.Done(): |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 905 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 906 | // break loop |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 907 | message, ok := <-oFsm.pAdaptFsm.commChan |
| 908 | if !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 909 | logger.Info(ctx, "UniPonAniConfigFsm 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] | 910 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
| 911 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
| 912 | break loop |
| 913 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 914 | logger.Debugw(ctx, "UniPonAniConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 915 | |
| 916 | switch message.Type { |
| 917 | case TestMsg: |
| 918 | msg, _ := message.Data.(TestMessage) |
| 919 | if msg.TestMessageVal == AbortMessageProcessing { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 920 | logger.Infow(ctx, "UniPonAniConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 921 | break loop |
| 922 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 923 | logger.Warnw(ctx, "UniPonAniConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 924 | case OMCI: |
| 925 | msg, _ := message.Data.(OmciMessage) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 926 | oFsm.handleOmciAniConfigMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 927 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 928 | logger.Warn(ctx, "UniPonAniConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 929 | "message.Type": message.Type}) |
| 930 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 931 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 932 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 933 | logger.Infow(ctx, "End uniPonAniConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 934 | } |
| 935 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 936 | func (oFsm *uniPonAniConfigFsm) handleOmciAniConfigCreateResponseMessage(ctx context.Context, msg OmciMessage) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 937 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse) |
| 938 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 939 | logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 940 | log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 941 | return |
| 942 | } |
| 943 | msgObj, msgOk := msgLayer.(*omci.CreateResponse) |
| 944 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 945 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 946 | log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 947 | return |
| 948 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 949 | logger.Debugw(ctx, "CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 950 | if msgObj.Result == me.Success || msgObj.Result == me.InstanceExists { |
| 951 | //if the result is ok or Instance already exists (latest needed at least as long as we do not clear the OMCI techProfile data) |
| 952 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 953 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 954 | // maybe we can use just the same eventName for different state transitions like "forward" |
| 955 | // - might be checked, but so far I go for sure and have to inspect the concrete state events ... |
| 956 | switch oFsm.pLastTxMeInstance.GetName() { |
| 957 | case "Ieee8021PMapperServiceProfile": |
| 958 | { // let the FSM proceed ... |
| 959 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxDot1pmapCResp) |
| 960 | } |
| 961 | case "MacBridgePortConfigurationData": |
| 962 | { // let the FSM proceed ... |
| 963 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxMbpcdResp) |
| 964 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 965 | case "GemPortNetworkCtp", "GemInterworkingTerminationPoint", "MulticastGemInterworkingTerminationPoint": |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 966 | { // let aniConfig Multi-Id processing proceed by stopping the wait function |
| 967 | oFsm.omciMIdsResponseReceived <- true |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 972 | logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 973 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 974 | return |
| 975 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 976 | } |
| 977 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 978 | func (oFsm *uniPonAniConfigFsm) handleOmciAniConfigSetResponseMessage(ctx context.Context, msg OmciMessage) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 979 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 980 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 981 | logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be detected for SetResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 982 | log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 983 | return |
| 984 | } |
| 985 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 986 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 987 | logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be assigned for SetResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 988 | log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 989 | return |
| 990 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 991 | logger.Debugw(ctx, "UniPonAniConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 992 | if msgObj.Result != me.Success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 993 | logger.Errorw(ctx, "UniPonAniConfigFsm - Omci SetResponse Error - later: drive FSM to abort state ?", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 994 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 995 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 996 | return |
| 997 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 998 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 999 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1000 | //store the created ME into DB //TODO??? obviously the Python code does not store the config ... |
| 1001 | // if, then something like: |
| 1002 | //oFsm.pOnuDB.StoreMe(msgObj) |
| 1003 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1004 | switch oFsm.pLastTxMeInstance.GetName() { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1005 | case "TCont": |
| 1006 | { // let the FSM proceed ... |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1007 | if oFsm.requestEventOffset == 0 { //from TCont config request |
| 1008 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxTcontsResp) |
| 1009 | } else { // from T-Cont reset request |
| 1010 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxResetTcontResp) |
| 1011 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1012 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1013 | case "PriorityQueue", "MulticastGemInterworkingTerminationPoint": |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1014 | { // let the PrioQueue init proceed by stopping the wait function |
| 1015 | oFsm.omciMIdsResponseReceived <- true |
| 1016 | } |
| 1017 | case "Ieee8021PMapperServiceProfile": |
| 1018 | { // let the FSM proceed ... |
| 1019 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxDot1pmapSResp) |
| 1020 | } |
| 1021 | } |
| 1022 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1025 | func (oFsm *uniPonAniConfigFsm) handleOmciAniConfigDeleteResponseMessage(ctx context.Context, msg OmciMessage) { |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1026 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeDeleteResponse) |
| 1027 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1028 | logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be detected for DeleteResponse", |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1029 | log.Fields{"device-id": oFsm.deviceID}) |
| 1030 | return |
| 1031 | } |
| 1032 | msgObj, msgOk := msgLayer.(*omci.DeleteResponse) |
| 1033 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1034 | logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be assigned for DeleteResponse", |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1035 | log.Fields{"device-id": oFsm.deviceID}) |
| 1036 | return |
| 1037 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1038 | logger.Debugw(ctx, "UniPonAniConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1039 | if msgObj.Result != me.Success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1040 | logger.Errorw(ctx, "UniPonAniConfigFsm - Omci DeleteResponse Error", |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1041 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
| 1042 | //TODO: - later: possibly force FSM into abort or ignore some errors for some messages? |
| 1043 | // store error for mgmt display? |
| 1044 | return |
| 1045 | } |
| 1046 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 1047 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 1048 | //remove ME from DB //TODO??? obviously the Python code does not store/remove the config ... |
| 1049 | // if, then something like: oFsm.pOnuDB.XyyMe(msgObj) |
| 1050 | |
| 1051 | switch oFsm.pLastTxMeInstance.GetName() { |
| 1052 | case "GemInterworkingTerminationPoint": |
| 1053 | { // let the FSM proceed ... |
| 1054 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxRemGemiwResp) |
| 1055 | } |
| 1056 | case "GemPortNetworkCtp": |
| 1057 | { // let the FSM proceed ... |
| 1058 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxRemGemntpResp) |
| 1059 | } |
| 1060 | case "Ieee8021PMapperServiceProfile": |
| 1061 | { // let the FSM proceed ... |
| 1062 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxRem1pMapperResp) |
| 1063 | } |
| 1064 | case "MacBridgePortConfigurationData": |
| 1065 | { // this is the last event of the T-Cont cleanup procedure, FSM may be reset here |
| 1066 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxRemAniBPCDResp) |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1072 | func (oFsm *uniPonAniConfigFsm) handleOmciAniConfigMessage(ctx context.Context, msg OmciMessage) { |
| 1073 | logger.Debugw(ctx, "Rx OMCI UniPonAniConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1074 | "msgType": msg.OmciMsg.MessageType}) |
| 1075 | |
| 1076 | switch msg.OmciMsg.MessageType { |
| 1077 | case omci.CreateResponseType: |
| 1078 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1079 | oFsm.handleOmciAniConfigCreateResponseMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1080 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1081 | } //CreateResponseType |
| 1082 | case omci.SetResponseType: |
| 1083 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1084 | oFsm.handleOmciAniConfigSetResponseMessage(ctx, msg) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1085 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1086 | } //SetResponseType |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1087 | case omci.DeleteResponseType: |
| 1088 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1089 | oFsm.handleOmciAniConfigDeleteResponseMessage(ctx, msg) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1090 | |
| 1091 | } //SetResponseType |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1092 | default: |
| 1093 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1094 | logger.Errorw(ctx, "uniPonAniConfigFsm - Rx OMCI unhandled MsgType", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1095 | log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1096 | return |
| 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1101 | func (oFsm *uniPonAniConfigFsm) performCreatingGemNCTPs(ctx context.Context) { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1102 | // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice |
| 1103 | for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1104 | logger.Debugw(ctx, "uniPonAniConfigFsm Tx Create::GemNWCtp", log.Fields{ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1105 | "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16), |
| 1106 | "TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1107 | "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1108 | meParams := me.ParamData{ |
| 1109 | EntityID: gemPortAttribs.gemPortID, //unique, same as PortId |
| 1110 | Attributes: me.AttributeValueMap{ |
| 1111 | "PortId": gemPortAttribs.gemPortID, |
| 1112 | "TContPointer": oFsm.tcont0ID, |
| 1113 | "Direction": gemPortAttribs.direction, |
| 1114 | //ONU-G.TrafficManagementOption dependency ->PrioQueue or TCont |
| 1115 | // TODO!! verify dependency and QueueId in case of Multi-GemPort setup! |
| 1116 | "TrafficManagementPointerForUpstream": gemPortAttribs.upQueueID, //might be different in wrr-only Setup - tcont0ID |
| 1117 | "PriorityQueuePointerForDownStream": gemPortAttribs.downQueueID, |
| 1118 | }, |
| 1119 | } |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 1120 | meInstance := oFsm.pOmciCC.sendCreateGemNCTPVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1121 | oFsm.pAdaptFsm.commChan, meParams) |
| 1122 | //accept also nil as (error) return value for writing to LastTx |
| 1123 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1124 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1125 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1126 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1127 | err := oFsm.waitforOmciResponse(ctx) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1128 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1129 | logger.Errorw(ctx, "GemNWCtp create failed, aborting AniConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1130 | log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1131 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1132 | return |
| 1133 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1134 | // Mark the gem port to be removed for Performance History monitoring |
| 1135 | if oFsm.pDeviceHandler.pOnuMetricsMgr != nil { |
| 1136 | oFsm.pDeviceHandler.pOnuMetricsMgr.AddGemPortForPerfMonitoring(gemPortAttribs.gemPortID) |
| 1137 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1138 | } //for all GemPorts of this T-Cont |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1139 | |
| 1140 | // if Config has been done for all GemPort instances let the FSM proceed |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1141 | logger.Debugw(ctx, "GemNWCtp create loop finished", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1142 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxGemntcpsResp) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1145 | func (oFsm *uniPonAniConfigFsm) performCreatingGemIWs(ctx context.Context) { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1146 | // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice |
| 1147 | for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1148 | logger.Debugw(ctx, "uniPonAniConfigFsm Tx Create::GemIwTp", log.Fields{ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1149 | "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16), |
| 1150 | "SPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1151 | "device-id": oFsm.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1152 | |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 1153 | //TODO if the port has only downstream direction the isMulticast flag can be removed. |
| 1154 | if gemPortAttribs.isMulticast { |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 1155 | |
| 1156 | meParams := me.ParamData{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1157 | EntityID: gemPortAttribs.multicastGemID, |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 1158 | Attributes: me.AttributeValueMap{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1159 | "GemPortNetworkCtpConnectivityPointer": gemPortAttribs.multicastGemID, |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 1160 | "InterworkingOption": 0, // Don't Care |
| 1161 | "ServiceProfilePointer": 0, // Don't Care |
| 1162 | "GalProfilePointer": galEthernetEID, |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 1163 | }, |
| 1164 | } |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 1165 | meInstance := oFsm.pOmciCC.sendCreateMulticastGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 1166 | true, oFsm.pAdaptFsm.commChan, meParams) |
| 1167 | oFsm.pLastTxMeInstance = meInstance |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1168 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1169 | err := oFsm.waitforOmciResponse(ctx) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1170 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1171 | logger.Errorw(ctx, "GemTP IW multicast create failed, aborting AniConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1172 | log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex}) |
| 1173 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
| 1174 | return |
| 1175 | } |
| 1176 | ipv4MulticastTable := make([]uint8, 12) |
| 1177 | //Gem Port ID |
| 1178 | binary.BigEndian.PutUint16(ipv4MulticastTable[0:], gemPortAttribs.multicastGemID) |
| 1179 | //Secondary Key |
| 1180 | binary.BigEndian.PutUint16(ipv4MulticastTable[2:], 0) |
| 1181 | // Multicast IP range start This is the 224.0.0.1 address |
| 1182 | binary.BigEndian.PutUint32(ipv4MulticastTable[4:], IPToInt32(net.IPv4(224, 0, 0, 0))) |
| 1183 | // MulticastIp range stop |
| 1184 | binary.BigEndian.PutUint32(ipv4MulticastTable[8:], IPToInt32(net.IPv4(239, 255, 255, 255))) |
| 1185 | |
| 1186 | meIPV4MCTableParams := me.ParamData{ |
| 1187 | EntityID: gemPortAttribs.multicastGemID, |
| 1188 | Attributes: me.AttributeValueMap{ |
| 1189 | "Ipv4MulticastAddressTable": ipv4MulticastTable, |
| 1190 | }, |
| 1191 | } |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 1192 | meIPV4MCTableInstance := oFsm.pOmciCC.sendSetMulticastGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1193 | true, oFsm.pAdaptFsm.commChan, meIPV4MCTableParams) |
| 1194 | oFsm.pLastTxMeInstance = meIPV4MCTableInstance |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 1195 | |
| 1196 | } else { |
| 1197 | meParams := me.ParamData{ |
| 1198 | EntityID: gemPortAttribs.gemPortID, |
| 1199 | Attributes: me.AttributeValueMap{ |
| 1200 | "GemPortNetworkCtpConnectivityPointer": gemPortAttribs.gemPortID, //same as EntityID, see above |
| 1201 | "InterworkingOption": 5, //fixed model:: G.998 .1pMapper |
| 1202 | "ServiceProfilePointer": oFsm.mapperSP0ID, |
| 1203 | "InterworkingTerminationPointPointer": 0, //not used with .1PMapper Mac bridge |
| 1204 | "GalProfilePointer": galEthernetEID, |
| 1205 | }, |
| 1206 | } |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 1207 | meInstance := oFsm.pOmciCC.sendCreateGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
ozgecanetsia | 4b23230 | 2020-11-11 10:58:10 +0300 | [diff] [blame] | 1208 | oFsm.pAdaptFsm.commChan, meParams) |
| 1209 | //accept also nil as (error) return value for writing to LastTx |
| 1210 | // - this avoids misinterpretation of new received OMCI messages |
| 1211 | oFsm.pLastTxMeInstance = meInstance |
| 1212 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1213 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1214 | err := oFsm.waitforOmciResponse(ctx) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1215 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1216 | logger.Errorw(ctx, "GemTP create failed, aborting AniConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1217 | log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1218 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1219 | return |
| 1220 | } |
| 1221 | } //for all GemPort's of this T-Cont |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1222 | |
| 1223 | // if Config has been done for all GemPort instances let the FSM proceed |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1224 | logger.Debugw(ctx, "GemIwTp create loop finished", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1225 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxGemiwsResp) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1228 | func (oFsm *uniPonAniConfigFsm) performSettingPQs(ctx context.Context) { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1229 | const cu16StrictPrioWeight uint16 = 0xFFFF |
| 1230 | //find all upstream PrioQueues related to this T-Cont |
| 1231 | loQueueMap := ordered_map.NewOrderedMap() |
| 1232 | for _, gemPortAttribs := range oFsm.gemPortAttribsSlice { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1233 | if gemPortAttribs.isMulticast { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1234 | logger.Debugw(ctx, "uniPonAniConfigFsm Port is Multicast, ignoring PQs", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1235 | "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID, |
| 1236 | "prioString": gemPortAttribs.pbitString}) |
| 1237 | continue |
| 1238 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1239 | if gemPortAttribs.qosPolicy == "WRR" { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1240 | if _, ok := loQueueMap.Get(gemPortAttribs.upQueueID); !ok { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1241 | //key does not yet exist |
| 1242 | loQueueMap.Set(gemPortAttribs.upQueueID, uint16(gemPortAttribs.weight)) |
| 1243 | } |
| 1244 | } else { |
| 1245 | loQueueMap.Set(gemPortAttribs.upQueueID, cu16StrictPrioWeight) //use invalid weight value to indicate SP |
| 1246 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1247 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1248 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1249 | //TODO: assumption here is that ONU data uses SP setting in the T-Cont and WRR in the TrafficScheduler |
| 1250 | // if that is not the case, the reverse case could be checked and reacted accordingly or if the |
| 1251 | // complete chain is not valid, then some error should be thrown and configuration can be aborted |
| 1252 | // or even be finished without correct SP/WRR setting |
| 1253 | |
| 1254 | //TODO: search for the (WRR)trafficScheduler related to the T-Cont of this queue |
| 1255 | //By now assume fixed value 0x8000, which is the only announce BBSIM TrafficScheduler, |
| 1256 | // even though its T-Cont seems to be wrong ... |
| 1257 | loTrafficSchedulerEID := 0x8000 |
| 1258 | //for all found queues |
| 1259 | iter := loQueueMap.IterFunc() |
| 1260 | for kv, ok := iter(); ok; kv, ok = iter() { |
| 1261 | queueIndex := (kv.Key).(uint16) |
| 1262 | meParams := me.ParamData{ |
| 1263 | EntityID: queueIndex, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1264 | Attributes: make(me.AttributeValueMap), |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1265 | } |
| 1266 | if (kv.Value).(uint16) == cu16StrictPrioWeight { |
| 1267 | //StrictPrio indication |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1268 | logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio", log.Fields{ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1269 | "EntitytId": strconv.FormatInt(int64(queueIndex), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1270 | "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1271 | meParams.Attributes["TrafficSchedulerPointer"] = 0 //ensure T-Cont defined StrictPrio scheduling |
| 1272 | } else { |
| 1273 | //WRR indication |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1274 | logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to WRR", log.Fields{ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1275 | "EntitytId": strconv.FormatInt(int64(queueIndex), 16), |
| 1276 | "Weight": kv.Value, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1277 | "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1278 | meParams.Attributes["TrafficSchedulerPointer"] = loTrafficSchedulerEID //ensure assignment of the relevant trafficScheduler |
| 1279 | meParams.Attributes["Weight"] = uint8(kv.Value.(uint16)) |
| 1280 | } |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 1281 | meInstance := oFsm.pOmciCC.sendSetPrioQueueVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1282 | oFsm.pAdaptFsm.commChan, meParams) |
| 1283 | //accept also nil as (error) return value for writing to LastTx |
| 1284 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1285 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1286 | |
| 1287 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1288 | err := oFsm.waitforOmciResponse(ctx) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1289 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1290 | logger.Errorw(ctx, "PrioQueue set failed, aborting AniConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1291 | log.Fields{"device-id": oFsm.deviceID, "QueueId": strconv.FormatInt(int64(queueIndex), 16)}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1292 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1293 | return |
| 1294 | } |
| 1295 | |
| 1296 | //TODO: In case of WRR setting of the GemPort/PrioQueue it might further be necessary to |
| 1297 | // write the assigned trafficScheduler with the requested Prio to be considered in the StrictPrio scheduling |
| 1298 | // of the (next upstream) assigned T-Cont, which is f(prioQueue[priority]) - in relation to other SP prioQueues |
| 1299 | // not yet done because of BBSIM TrafficScheduler issues (and not done in py code as well) |
| 1300 | |
| 1301 | } //for all upstream prioQueues |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1302 | |
| 1303 | // if Config has been done for all PrioQueue instances let the FSM proceed |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1304 | logger.Debugw(ctx, "PrioQueue set loop finished", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1305 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxPrioqsResp) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1308 | func (oFsm *uniPonAniConfigFsm) waitforOmciResponse(ctx context.Context) error { |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 1309 | oFsm.mutexIsAwaitingResponse.Lock() |
| 1310 | oFsm.isAwaitingResponse = true |
| 1311 | oFsm.mutexIsAwaitingResponse.Unlock() |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1312 | select { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1313 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1314 | // case <-ctx.Done(): |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1315 | // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1316 | case <-time.After(30 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1317 | logger.Warnw(ctx, "UniPonAniConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 1318 | oFsm.mutexIsAwaitingResponse.Lock() |
| 1319 | oFsm.isAwaitingResponse = false |
| 1320 | oFsm.mutexIsAwaitingResponse.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1321 | return fmt.Errorf("uniPonAniConfigFsm multi entity timeout %s", oFsm.deviceID) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1322 | case success := <-oFsm.omciMIdsResponseReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1323 | if success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1324 | logger.Debug(ctx, "uniPonAniConfigFsm multi entity response received") |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 1325 | oFsm.mutexIsAwaitingResponse.Lock() |
| 1326 | oFsm.isAwaitingResponse = false |
| 1327 | oFsm.mutexIsAwaitingResponse.Unlock() |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1328 | return nil |
| 1329 | } |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 1330 | // waiting was aborted (probably on external request) |
| 1331 | logger.Debugw(ctx, "uniPonAniConfigFsm wait for multi entity response aborted", log.Fields{"for device-id": oFsm.deviceID}) |
| 1332 | oFsm.mutexIsAwaitingResponse.Lock() |
| 1333 | oFsm.isAwaitingResponse = false |
| 1334 | oFsm.mutexIsAwaitingResponse.Unlock() |
| 1335 | return fmt.Errorf(cErrWaitAborted) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1336 | } |
| 1337 | } |