blob: e438a713364297e0fc66f75ea882799ec41873b3 [file] [log] [blame]
mpagenko3dbcdd22020-07-22 07:38:45 +00001/*
Joey Armstrong89c812c2024-01-12 19:00:20 -05002 * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors
mpagenko3dbcdd22020-07-22 07:38:45 +00003 *
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
praneeth kumar nalmas3947c582023-12-13 15:38:50 +053017// Package avcfg provides anig and vlan configuration functionality
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000018package avcfg
mpagenko3dbcdd22020-07-22 07:38:45 +000019
20import (
21 "context"
ozgecanetsia4b232302020-11-11 10:58:10 +030022 "encoding/binary"
Himani Chawla4d908332020-08-31 12:30:20 +053023 "fmt"
ozgecanetsia4b232302020-11-11 10:58:10 +030024 "net"
mpagenko3dbcdd22020-07-22 07:38:45 +000025 "strconv"
mpagenko7d6bb022021-03-11 15:07:55 +000026 "sync"
mpagenko3dbcdd22020-07-22 07:38:45 +000027 "time"
28
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000029 "github.com/cevaris/ordered_map"
mpagenko3dbcdd22020-07-22 07:38:45 +000030 "github.com/looplab/fsm"
mpagenko836a1fd2021-11-01 16:12:42 +000031 "github.com/opencord/omci-lib-go/v2"
32 me "github.com/opencord/omci-lib-go/v2/generated"
khenaidoo7d3c5582021-08-11 18:09:44 -040033 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000034
khenaidoo7d3c5582021-08-11 18:09:44 -040035 //ic "github.com/opencord/voltha-protos/v5/go/inter_container"
36 //"github.com/opencord/voltha-protos/v5/go/openflow_13"
37 //"github.com/opencord/voltha-protos/v5/go/voltha"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000038 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
39 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb"
mpagenko3dbcdd22020-07-22 07:38:45 +000040)
41
mpagenko1cc3cb42020-07-27 15:24:38 +000042const (
43 // events of config PON ANI port FSM
mpagenko8b07c1b2020-11-26 10:36:31 +000044 aniEvStart = "aniEvStart"
45 aniEvStartConfig = "aniEvStartConfig"
46 aniEvRxDot1pmapCResp = "aniEvRxDot1pmapCResp"
47 aniEvRxMbpcdResp = "aniEvRxMbpcdResp"
48 aniEvRxTcontsResp = "aniEvRxTcontsResp"
49 aniEvRxGemntcpsResp = "aniEvRxGemntcpsResp"
50 aniEvRxGemiwsResp = "aniEvRxGemiwsResp"
51 aniEvRxPrioqsResp = "aniEvRxPrioqsResp"
52 aniEvRxDot1pmapSResp = "aniEvRxDot1pmapSResp"
53 aniEvRemGemiw = "aniEvRemGemiw"
Girish Gowdra26a40922021-01-29 17:14:34 -080054 aniEvWaitFlowRem = "aniEvWaitFlowRem"
55 aniEvFlowRemDone = "aniEvFlowRemDone"
mpagenko8b07c1b2020-11-26 10:36:31 +000056 aniEvRxRemGemiwResp = "aniEvRxRemGemiwResp"
57 aniEvRxRemGemntpResp = "aniEvRxRemGemntpResp"
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +030058 aniEvRxRemTdResp = "aniEvRxRemTdResp"
mpagenko8b07c1b2020-11-26 10:36:31 +000059 aniEvRemTcontPath = "aniEvRemTcontPath"
60 aniEvRxResetTcontResp = "aniEvRxResetTcontResp"
61 aniEvRxRem1pMapperResp = "aniEvRxRem1pMapperResp"
62 aniEvRxRemAniBPCDResp = "aniEvRxRemAniBPCDResp"
63 aniEvTimeoutSimple = "aniEvTimeoutSimple"
64 aniEvTimeoutMids = "aniEvTimeoutMids"
65 aniEvReset = "aniEvReset"
66 aniEvRestart = "aniEvRestart"
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +000067 aniEvSkipOmciConfig = "aniEvSkipOmciConfig"
Mahir Gunyel9545be22021-07-04 15:53:16 -070068 aniEvRemGemDone = "aniEvRemGemDone"
mpagenko1cc3cb42020-07-27 15:24:38 +000069)
70const (
71 // states of config PON ANI port FSM
72 aniStDisabled = "aniStDisabled"
73 aniStStarting = "aniStStarting"
74 aniStCreatingDot1PMapper = "aniStCreatingDot1PMapper"
75 aniStCreatingMBPCD = "aniStCreatingMBPCD"
76 aniStSettingTconts = "aniStSettingTconts"
77 aniStCreatingGemNCTPs = "aniStCreatingGemNCTPs"
78 aniStCreatingGemIWs = "aniStCreatingGemIWs"
79 aniStSettingPQs = "aniStSettingPQs"
80 aniStSettingDot1PMapper = "aniStSettingDot1PMapper"
81 aniStConfigDone = "aniStConfigDone"
mpagenko8b07c1b2020-11-26 10:36:31 +000082 aniStRemovingGemIW = "aniStRemovingGemIW"
Girish Gowdra26a40922021-01-29 17:14:34 -080083 aniStWaitingFlowRem = "aniStWaitingFlowRem"
mpagenko8b07c1b2020-11-26 10:36:31 +000084 aniStRemovingGemNCTP = "aniStRemovingGemNCTP"
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +030085 aniStRemovingTD = "aniStRemovingTD"
mpagenko8b07c1b2020-11-26 10:36:31 +000086 aniStResetTcont = "aniStResetTcont"
87 aniStRemDot1PMapper = "aniStRemDot1PMapper"
88 aniStRemAniBPCD = "aniStRemAniBPCD"
89 aniStRemoveDone = "aniStRemoveDone"
mpagenko1cc3cb42020-07-27 15:24:38 +000090 aniStResetting = "aniStResetting"
91)
92
Girish Gowdra09e5f212021-09-30 16:28:36 -070093const (
94 bitTrafficSchedulerPtrSetPermitted = 0x0002 // Refer section 9.1.2 ONU-2G, table for "Quality of service (QoS) configuration flexibility" IE
95)
Holger Hildebrandtc408f492022-07-14 08:39:24 +000096const cTechProfileTypeXgsPon = "XGS-PON"
97
98// definitions as per G.988
99// Gem Encryption Key Ring
100const (
101 // No encryption. The downstream key index is ignored, and upstream traffic is transmitted with key index 0.
102 GemEncryptKeyRingNoEncrypt = 0
103 // Unicast payload encryption in both directions. Keys are generated by the ONU and transmitted to the OLT via the PLOAM channel.
104 GemEncryptKeyRingUnicastPayload = 1
105 // Broadcast (multicast) encryption. Keys are generated by the OLT and distributed via the OMCI.
106 GemEncryptKeyRingBroadcastMulticast = 2
107 // Unicast encryption, downstream only. Keys are generated by the ONU and transmitted to the OLT via the PLOAM channel.
108 GemEncryptKeyRingUnicastDownstreamOnly = 3
109)
Girish Gowdra09e5f212021-09-30 16:28:36 -0700110
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000111// CAniFsmIdleState - TODO: add comment
112const CAniFsmIdleState = aniStConfigDone
113
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000114type ponAniGemPortAttribs struct {
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530115 qosPolicy string
116 pbitString string
117 staticACL string
118 dynamicACL string
ozgecanetsia4b232302020-11-11 10:58:10 +0300119 gemPortID uint16
120 upQueueID uint16
121 downQueueID uint16
ozgecanetsia4b232302020-11-11 10:58:10 +0300122 multicastGemID uint16
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530123 direction uint8
124 weight uint8
125 isMulticast bool
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000126}
127
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530128// UniPonAniConfigFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000129type UniPonAniConfigFsm struct {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000130 pDeviceHandler cmn.IdeviceHandler
131 pOnuDeviceEntry cmn.IonuDeviceEntry
132 pOmciCC *cmn.OmciCC
133 pOnuUniPort *cmn.OnuUniPort
134 pUniTechProf *OnuUniTechProf
135 pOnuDB *devdb.OnuDeviceDB
Himani Chawla4d908332020-08-31 12:30:20 +0530136 omciMIdsResponseReceived chan bool //separate channel needed for checking multiInstance OMCI message responses
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000137 PAdaptFsm *cmn.AdapterFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000138 chSuccess chan<- uint8
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530139 pLastTxMeInstance *me.ManagedEntity
140 waitFlowDeleteChannel chan bool
141 deviceID string
142 techProfileType string
143 gemPortAttribsSlice []ponAniGemPortAttribs
144 requestEvent cmn.OnuDeviceEvent
145 mutexIsAwaitingResponse sync.RWMutex
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000146 mutexChanSet sync.RWMutex
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530147 mutexPLastTxMeInstance sync.RWMutex
mpagenko3dbcdd22020-07-22 07:38:45 +0000148 mapperSP0ID uint16
149 macBPCD0ID uint16
150 tcont0ID uint16
151 alloc0ID uint16
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530152 uniTpKey uniTP
153 techProfileID uint8
154 isCanceled bool
155 isAwaitingResponse bool
156 procStep uint8
157 chanSet bool
mpagenko8b07c1b2020-11-26 10:36:31 +0000158 requestEventOffset uint8 //used to indicate ConfigDone or Removed using successor (enum)
mpagenkobb47bc22021-04-20 13:29:09 +0000159 isWaitingForFlowDelete bool
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700160 tcontSetBefore bool
mpagenko3dbcdd22020-07-22 07:38:45 +0000161}
162
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530163// NewUniPonAniConfigFsm is the 'constructor' for the state machine to config the PON ANI ports of ONU UNI ports via OMCI
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000164func NewUniPonAniConfigFsm(ctx context.Context, apDevOmciCC *cmn.OmciCC, apUniPort *cmn.OnuUniPort, apUniTechProf *OnuUniTechProf,
Holger Hildebrandtc408f492022-07-14 08:39:24 +0000165 apOnuDB *devdb.OnuDeviceDB, aTechProfileID uint8, aTechProfileType string, aRequestEvent cmn.OnuDeviceEvent, aName string,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000166 apDeviceHandler cmn.IdeviceHandler, apOnuDeviceEntry cmn.IonuDeviceEntry, aCommChannel chan cmn.Message) *UniPonAniConfigFsm {
167 instFsm := &UniPonAniConfigFsm{
168 pDeviceHandler: apDeviceHandler,
169 pOnuDeviceEntry: apOnuDeviceEntry,
170 deviceID: apDeviceHandler.GetDeviceID(),
171 pOmciCC: apDevOmciCC,
172 pOnuUniPort: apUniPort,
173 pUniTechProf: apUniTechProf,
174 pOnuDB: apOnuDB,
175 techProfileID: aTechProfileID,
Holger Hildebrandtc408f492022-07-14 08:39:24 +0000176 techProfileType: aTechProfileType,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000177 requestEvent: aRequestEvent,
178 chanSet: false,
179 tcontSetBefore: false,
mpagenko3dbcdd22020-07-22 07:38:45 +0000180 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000181 instFsm.uniTpKey = uniTP{uniID: apUniPort.UniID, tpID: aTechProfileID}
mpagenkobb47bc22021-04-20 13:29:09 +0000182 instFsm.waitFlowDeleteChannel = make(chan bool)
mpagenko8b07c1b2020-11-26 10:36:31 +0000183
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000184 instFsm.PAdaptFsm = cmn.NewAdapterFsm(aName, instFsm.deviceID, aCommChannel)
185 if instFsm.PAdaptFsm == nil {
186 logger.Errorw(ctx, "UniPonAniConfigFsm's cmn.AdapterFsm could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000187 "device-id": instFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000188 return nil
189 }
190
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000191 instFsm.PAdaptFsm.PFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000192 aniStDisabled,
mpagenko3dbcdd22020-07-22 07:38:45 +0000193 fsm.Events{
194
mpagenko1cc3cb42020-07-27 15:24:38 +0000195 {Name: aniEvStart, Src: []string{aniStDisabled}, Dst: aniStStarting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000196
197 //Note: .1p-Mapper and MBPCD might also have multi instances (per T-Cont) - by now only one 1 T-Cont considered!
mpagenko1cc3cb42020-07-27 15:24:38 +0000198 {Name: aniEvStartConfig, Src: []string{aniStStarting}, Dst: aniStCreatingDot1PMapper},
mpagenkodff5dda2020-08-28 11:52:01 +0000199 {Name: aniEvRxDot1pmapCResp, Src: []string{aniStCreatingDot1PMapper}, Dst: aniStCreatingMBPCD},
mpagenko1cc3cb42020-07-27 15:24:38 +0000200 {Name: aniEvRxMbpcdResp, Src: []string{aniStCreatingMBPCD}, Dst: aniStSettingTconts},
201 {Name: aniEvRxTcontsResp, Src: []string{aniStSettingTconts}, Dst: aniStCreatingGemNCTPs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000202 // the creatingGemNCTPs state is used for multi ME config if required for all configured/available GemPorts
mpagenko1cc3cb42020-07-27 15:24:38 +0000203 {Name: aniEvRxGemntcpsResp, Src: []string{aniStCreatingGemNCTPs}, Dst: aniStCreatingGemIWs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000204 // the creatingGemIWs state is used for multi ME config if required for all configured/available GemPorts
mpagenko1cc3cb42020-07-27 15:24:38 +0000205 {Name: aniEvRxGemiwsResp, Src: []string{aniStCreatingGemIWs}, Dst: aniStSettingPQs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000206 // the settingPQs state is used for multi ME config if required for all configured/available upstream PriorityQueues
mpagenko1cc3cb42020-07-27 15:24:38 +0000207 {Name: aniEvRxPrioqsResp, Src: []string{aniStSettingPQs}, Dst: aniStSettingDot1PMapper},
mpagenkodff5dda2020-08-28 11:52:01 +0000208 {Name: aniEvRxDot1pmapSResp, Src: []string{aniStSettingDot1PMapper}, Dst: aniStConfigDone},
mpagenko3dbcdd22020-07-22 07:38:45 +0000209
mpagenko8b07c1b2020-11-26 10:36:31 +0000210 //for removing Gem related resources
211 {Name: aniEvRemGemiw, Src: []string{aniStConfigDone}, Dst: aniStRemovingGemIW},
Girish Gowdra26a40922021-01-29 17:14:34 -0800212 {Name: aniEvWaitFlowRem, Src: []string{aniStRemovingGemIW}, Dst: aniStWaitingFlowRem},
213 {Name: aniEvFlowRemDone, Src: []string{aniStWaitingFlowRem}, Dst: aniStRemovingGemIW},
mpagenko8b07c1b2020-11-26 10:36:31 +0000214 {Name: aniEvRxRemGemiwResp, Src: []string{aniStRemovingGemIW}, Dst: aniStRemovingGemNCTP},
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300215 {Name: aniEvRxRemGemntpResp, Src: []string{aniStRemovingGemNCTP}, Dst: aniStRemovingTD},
Mahir Gunyel9545be22021-07-04 15:53:16 -0700216 {Name: aniEvRxRemTdResp, Src: []string{aniStRemovingTD}, Dst: aniStRemDot1PMapper},
217 {Name: aniEvRemGemDone, Src: []string{aniStRemDot1PMapper}, Dst: aniStConfigDone},
218 {Name: aniEvRxRem1pMapperResp, Src: []string{aniStRemDot1PMapper}, Dst: aniStRemAniBPCD},
219 {Name: aniEvRxRemAniBPCDResp, Src: []string{aniStRemAniBPCD}, Dst: aniStRemoveDone},
mpagenko8b07c1b2020-11-26 10:36:31 +0000220
221 //for removing TCONT related resources
222 {Name: aniEvRemTcontPath, Src: []string{aniStConfigDone}, Dst: aniStResetTcont},
Mahir Gunyel9545be22021-07-04 15:53:16 -0700223 {Name: aniEvRxResetTcontResp, Src: []string{aniStResetTcont}, Dst: aniStConfigDone},
mpagenko8b07c1b2020-11-26 10:36:31 +0000224
225 {Name: aniEvTimeoutSimple, Src: []string{aniStCreatingDot1PMapper, aniStCreatingMBPCD, aniStSettingTconts, aniStSettingDot1PMapper,
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300226 aniStRemovingGemIW, aniStRemovingGemNCTP, aniStRemovingTD,
mpagenko8b07c1b2020-11-26 10:36:31 +0000227 aniStResetTcont, aniStRemDot1PMapper, aniStRemAniBPCD, aniStRemoveDone}, Dst: aniStStarting},
mpagenko1cc3cb42020-07-27 15:24:38 +0000228 {Name: aniEvTimeoutMids, Src: []string{
229 aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs}, Dst: aniStStarting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000230
mpagenko1cc3cb42020-07-27 15:24:38 +0000231 // exceptional treatment for all states except aniStResetting
232 {Name: aniEvReset, Src: []string{aniStStarting, aniStCreatingDot1PMapper, aniStCreatingMBPCD,
233 aniStSettingTconts, aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs, aniStSettingDot1PMapper,
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300234 aniStConfigDone, aniStRemovingGemIW, aniStWaitingFlowRem, aniStRemovingGemNCTP, aniStRemovingTD,
mpagenko8b07c1b2020-11-26 10:36:31 +0000235 aniStResetTcont, aniStRemDot1PMapper, aniStRemAniBPCD, aniStRemoveDone}, Dst: aniStResetting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000236 // the only way to get to resource-cleared disabled state again is via "resseting"
mpagenko1cc3cb42020-07-27 15:24:38 +0000237 {Name: aniEvRestart, Src: []string{aniStResetting}, Dst: aniStDisabled},
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000238 {Name: aniEvSkipOmciConfig, Src: []string{aniStStarting}, Dst: aniStConfigDone},
mpagenko3dbcdd22020-07-22 07:38:45 +0000239 },
240
241 fsm.Callbacks{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000242 "enter_state": func(e *fsm.Event) { instFsm.PAdaptFsm.LogFsmStateChange(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000243 ("enter_" + aniStStarting): func(e *fsm.Event) { instFsm.enterConfigStartingState(ctx, e) },
244 ("enter_" + aniStCreatingDot1PMapper): func(e *fsm.Event) { instFsm.enterCreatingDot1PMapper(ctx, e) },
245 ("enter_" + aniStCreatingMBPCD): func(e *fsm.Event) { instFsm.enterCreatingMBPCD(ctx, e) },
246 ("enter_" + aniStSettingTconts): func(e *fsm.Event) { instFsm.enterSettingTconts(ctx, e) },
247 ("enter_" + aniStCreatingGemNCTPs): func(e *fsm.Event) { instFsm.enterCreatingGemNCTPs(ctx, e) },
248 ("enter_" + aniStCreatingGemIWs): func(e *fsm.Event) { instFsm.enterCreatingGemIWs(ctx, e) },
249 ("enter_" + aniStSettingPQs): func(e *fsm.Event) { instFsm.enterSettingPQs(ctx, e) },
250 ("enter_" + aniStSettingDot1PMapper): func(e *fsm.Event) { instFsm.enterSettingDot1PMapper(ctx, e) },
251 ("enter_" + aniStConfigDone): func(e *fsm.Event) { instFsm.enterAniConfigDone(ctx, e) },
252 ("enter_" + aniStRemovingGemIW): func(e *fsm.Event) { instFsm.enterRemovingGemIW(ctx, e) },
mpagenkobb47bc22021-04-20 13:29:09 +0000253 ("enter_" + aniStWaitingFlowRem): func(e *fsm.Event) { instFsm.enterWaitingFlowRem(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000254 ("enter_" + aniStRemovingGemNCTP): func(e *fsm.Event) { instFsm.enterRemovingGemNCTP(ctx, e) },
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300255 ("enter_" + aniStRemovingTD): func(e *fsm.Event) { instFsm.enterRemovingTD(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000256 ("enter_" + aniStResetTcont): func(e *fsm.Event) { instFsm.enterResettingTcont(ctx, e) },
257 ("enter_" + aniStRemDot1PMapper): func(e *fsm.Event) { instFsm.enterRemoving1pMapper(ctx, e) },
258 ("enter_" + aniStRemAniBPCD): func(e *fsm.Event) { instFsm.enterRemovingAniBPCD(ctx, e) },
259 ("enter_" + aniStRemoveDone): func(e *fsm.Event) { instFsm.enterAniRemoveDone(ctx, e) },
260 ("enter_" + aniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(ctx, e) },
261 ("enter_" + aniStDisabled): func(e *fsm.Event) { instFsm.enterDisabledState(ctx, e) },
mpagenko3dbcdd22020-07-22 07:38:45 +0000262 },
263 )
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000264 if instFsm.PAdaptFsm.PFsm == nil {
265 logger.Errorw(ctx, "UniPonAniConfigFsm's Base FSM could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000266 "device-id": instFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000267 return nil
268 }
269
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000270 logger.Debugw(ctx, "UniPonAniConfigFsm created", log.Fields{"device-id": instFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000271 return instFsm
272}
273
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530274// setFsmCompleteChannel sets the requested channel and channel result for transfer on success
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000275func (oFsm *UniPonAniConfigFsm) setFsmCompleteChannel(aChSuccess chan<- uint8, aProcStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000276 oFsm.chSuccess = aChSuccess
277 oFsm.procStep = aProcStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000278 oFsm.setChanSet(true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000279}
280
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530281// CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000282func (oFsm *UniPonAniConfigFsm) CancelProcessing(ctx context.Context) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530283 logger.Info(ctx, "CancelProcessing entered", log.Fields{"device-id": oFsm.deviceID})
mpagenko73143992021-04-09 15:17:10 +0000284 //early indication about started reset processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000285 oFsm.pUniTechProf.setProfileResetting(ctx, oFsm.pOnuUniPort.UniID, oFsm.techProfileID, true)
mpagenko7d6bb022021-03-11 15:07:55 +0000286 //mutex protection is required for possible concurrent access to FSM members
mpagenkocf48e452021-04-23 09:23:00 +0000287 oFsm.mutexIsAwaitingResponse.Lock()
288 oFsm.isCanceled = true
mpagenko7d6bb022021-03-11 15:07:55 +0000289 if oFsm.isAwaitingResponse {
mpagenkocf48e452021-04-23 09:23:00 +0000290 //attention: for an unbuffered channel the sender is blocked until the value is received (processed)!
291 // accordingly the mutex must be released before sending to channel here (mutex acquired in receiver)
292 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko7d6bb022021-03-11 15:07:55 +0000293 //use channel to indicate that the response waiting shall be aborted
294 oFsm.omciMIdsResponseReceived <- false
mpagenkocf48e452021-04-23 09:23:00 +0000295 } else {
296 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko7d6bb022021-03-11 15:07:55 +0000297 }
mpagenkocf48e452021-04-23 09:23:00 +0000298
299 oFsm.mutexIsAwaitingResponse.Lock()
mpagenkobb47bc22021-04-20 13:29:09 +0000300 if oFsm.isWaitingForFlowDelete {
mpagenkocf48e452021-04-23 09:23:00 +0000301 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenkobb47bc22021-04-20 13:29:09 +0000302 //use channel to indicate that the response waiting shall be aborted
303 oFsm.waitFlowDeleteChannel <- false
mpagenkocf48e452021-04-23 09:23:00 +0000304 } else {
305 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenkobb47bc22021-04-20 13:29:09 +0000306 }
mpagenkocf48e452021-04-23 09:23:00 +0000307
mpagenko7d6bb022021-03-11 15:07:55 +0000308 // in any case (even if it might be automatically requested by above cancellation of waiting) ensure resetting the FSM
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000309 PAdaptFsm := oFsm.PAdaptFsm
310 if PAdaptFsm != nil {
mpagenko7d6bb022021-03-11 15:07:55 +0000311 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000312 go func(aPAFsm *cmn.AdapterFsm) {
313 if aPAFsm.PFsm != nil {
314 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
mpagenko7d6bb022021-03-11 15:07:55 +0000315 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000316 }(PAdaptFsm)
mpagenko7d6bb022021-03-11 15:07:55 +0000317 }
mpagenko73143992021-04-09 15:17:10 +0000318
mpagenko45cc6a32021-07-23 10:06:57 +0000319 // possible access conflicts on internal data by next needed data clearance
320 // are avoided by using mutexTPState also from within clearAniSideConfig
321 // do not try to lock TpProcMutex here as done in previous code version
322 // as it may result in deadlock situations (as observed at soft-reboot handling where
323 // TpProcMutex is already locked by some ongoing TechProfile config/removal processing
mpagenko73143992021-04-09 15:17:10 +0000324 //remove all TechProf related internal data to allow for new configuration
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000325 oFsm.pUniTechProf.clearAniSideConfig(ctx, oFsm.pOnuUniPort.UniID, oFsm.techProfileID)
mpagenko7d6bb022021-03-11 15:07:55 +0000326}
327
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530328// nolint: gocyclo
329// TODO:visit here for refactoring for gocyclo
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000330func (oFsm *UniPonAniConfigFsm) prepareAndEnterConfigState(ctx context.Context, aPAFsm *cmn.AdapterFsm) {
331 if aPAFsm != nil && aPAFsm.PFsm != nil {
Mahir Gunyel6781f962021-05-16 23:30:08 -0700332 var err error
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000333 oFsm.mapperSP0ID, err = cmn.GenerateIeeMaperServiceProfileEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.techProfileID))
Mahir Gunyel6781f962021-05-16 23:30:08 -0700334 if err != nil {
335 logger.Errorw(ctx, "error generating maper id", log.Fields{"device-id": oFsm.deviceID,
336 "techProfileID": oFsm.techProfileID, "error": err})
337 return
338 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000339 oFsm.macBPCD0ID, err = cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.techProfileID))
Mahir Gunyel6781f962021-05-16 23:30:08 -0700340 if err != nil {
341 logger.Errorw(ctx, "error generating mbpcd id", log.Fields{"device-id": oFsm.deviceID,
342 "techProfileID": oFsm.techProfileID, "error": err})
343 return
344 }
345 logger.Debugw(ctx, "generated ids for ani config", log.Fields{"mapperSP0ID": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
346 "macBPCD0ID": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16), "device-id": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000347 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "techProfileID": oFsm.techProfileID})
348 if oFsm.pOnuDeviceEntry == nil {
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700349 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": oFsm.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800350 return
Himani Chawla26e555c2020-08-31 12:30:20 +0530351 }
bseenivaeba8eb12024-12-13 11:54:28 +0530352 // Access critical state with lock
353 oFsm.pUniTechProf.mutexTPState.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000354 tcontInstID, tcontAlreadyExist, err := oFsm.pOnuDeviceEntry.AllocateFreeTcont(ctx, oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700355 if err != nil {
356 logger.Errorw(ctx, "No TCont instances found", log.Fields{"device-id": oFsm.deviceID, "err": err})
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700357 //reset the state machine to enable usage on subsequent requests
bseenivaeba8eb12024-12-13 11:54:28 +0530358 oFsm.pUniTechProf.mutexTPState.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000359 _ = aPAFsm.PFsm.Event(aniEvReset)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700360 return
361 }
362 oFsm.tcont0ID = tcontInstID
363 oFsm.tcontSetBefore = tcontAlreadyExist
364 logger.Debugw(ctx, "used-tcont-instance-id", log.Fields{"tcont-inst-id": oFsm.tcont0ID,
365 "alloc-id": oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID,
366 "tcontAlreadyExist": tcontAlreadyExist,
367 "device-id": oFsm.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800368
mpagenko8b07c1b2020-11-26 10:36:31 +0000369 oFsm.alloc0ID = oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID
370 mapGemPortParams := oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].mapGemPortParams
mpagenko3ce9fa02021-07-28 13:26:54 +0000371 oFsm.pUniTechProf.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800372
Himani Chawla26e555c2020-08-31 12:30:20 +0530373 //for all TechProfile set GemIndices
Girish Gowdra041dcb32020-11-16 16:54:30 -0800374 for _, gemEntry := range mapGemPortParams {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300375 loGemPortAttribs := ponAniGemPortAttribs{}
376
Himani Chawla26e555c2020-08-31 12:30:20 +0530377 //collect all GemConfigData in a separate Fsm related slice (needed also to avoid mix-up with unsorted mapPonAniConfig)
378
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000379 if queueInstKeys := oFsm.pOnuDB.GetSortedInstKeys(ctx, me.PriorityQueueClassID); len(queueInstKeys) > 0 {
Himani Chawla26e555c2020-08-31 12:30:20 +0530380
381 loGemPortAttribs.gemPortID = gemEntry.gemPortID
382 // MibDb usage: upstream PrioQueue.RelatedPort = xxxxyyyy with xxxx=TCont.Entity(incl. slot) and yyyy=prio
383 // i.e.: search PrioQueue list with xxxx=actual T-Cont.Entity,
384 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == yyyy (expect 0..7)
385 usQrelPortMask := uint32((((uint32)(oFsm.tcont0ID)) << 16) + uint32(gemEntry.prioQueueIndex))
386
387 // MibDb usage: downstream PrioQueue.RelatedPort = xxyyzzzz with xx=slot, yy=UniPort and zzzz=prio
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000388 // i.e.: search PrioQueue list with yy=actual pOnuUniPort.UniID,
Himani Chawla26e555c2020-08-31 12:30:20 +0530389 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == zzzz (expect 0..7)
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +0000390 // Note: As we do not maintain any slot numbering, slot number will be excluded from search pattern.
Himani Chawla26e555c2020-08-31 12:30:20 +0530391 // Furthermore OMCI Onu port-Id is expected to start with 1 (not 0).
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000392 dsQrelPortMask := uint32((((uint32)(oFsm.pOnuUniPort.UniID + 1)) << 16) + uint32(gemEntry.prioQueueIndex))
Himani Chawla26e555c2020-08-31 12:30:20 +0530393
394 usQueueFound := false
395 dsQueueFound := false
396 for _, mgmtEntityID := range queueInstKeys {
397 if meAttributes := oFsm.pOnuDB.GetMe(me.PriorityQueueClassID, mgmtEntityID); meAttributes != nil {
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000398 returnVal := meAttributes[me.PriorityQueue_RelatedPort]
Himani Chawla26e555c2020-08-31 12:30:20 +0530399 if returnVal != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000400 if relatedPort, err := oFsm.pOnuDB.GetUint32Attrib(returnVal); err == nil {
Himani Chawla26e555c2020-08-31 12:30:20 +0530401 if relatedPort == usQrelPortMask {
402 loGemPortAttribs.upQueueID = mgmtEntityID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000403 logger.Debugw(ctx, "UpQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
mpagenko01e726e2020-10-23 09:45:29 +0000404 "upQueueID": strconv.FormatInt(int64(loGemPortAttribs.upQueueID), 16), "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530405 usQueueFound = true
406 } else if (relatedPort&0xFFFFFF) == dsQrelPortMask && mgmtEntityID < 0x8000 {
407 loGemPortAttribs.downQueueID = mgmtEntityID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000408 logger.Debugw(ctx, "DownQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
mpagenko01e726e2020-10-23 09:45:29 +0000409 "downQueueID": strconv.FormatInt(int64(loGemPortAttribs.downQueueID), 16), "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530410 dsQueueFound = true
411 }
412 if usQueueFound && dsQueueFound {
413 break
414 }
415 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000416 logger.Warnw(ctx, "Could not convert attribute value", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530417 }
418 } else {
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000419 logger.Warnw(ctx, "PrioQueue.RelatedPort not found in meAttributes:", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530420 }
421 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000422 logger.Warnw(ctx, "No attributes available in DB:", log.Fields{"meClassID": me.PriorityQueueClassID,
mpagenko01e726e2020-10-23 09:45:29 +0000423 "mgmtEntityID": mgmtEntityID, "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530424 }
425 }
426 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000427 logger.Warnw(ctx, "No PriorityQueue instances found", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530428 }
429 loGemPortAttribs.direction = gemEntry.direction
430 loGemPortAttribs.qosPolicy = gemEntry.queueSchedPolicy
431 loGemPortAttribs.weight = gemEntry.queueWeight
432 loGemPortAttribs.pbitString = gemEntry.pbitString
ozgecanetsia82b91a62021-05-21 18:54:49 +0300433
ozgecanetsia4b232302020-11-11 10:58:10 +0300434 if gemEntry.isMulticast {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300435 //TODO this might effectively ignore the for loop starting at line 316
436 loGemPortAttribs.gemPortID = gemEntry.multicastGemPortID
ozgecanetsia4b232302020-11-11 10:58:10 +0300437 loGemPortAttribs.isMulticast = true
438 loGemPortAttribs.multicastGemID = gemEntry.multicastGemPortID
439 loGemPortAttribs.staticACL = gemEntry.staticACL
440 loGemPortAttribs.dynamicACL = gemEntry.dynamicACL
Himani Chawla26e555c2020-08-31 12:30:20 +0530441
dbainbri4d3a0dc2020-12-02 00:33:42 +0000442 logger.Debugw(ctx, "Multicast GemPort attributes:", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300443 "gemPortID": loGemPortAttribs.gemPortID,
444 "isMulticast": loGemPortAttribs.isMulticast,
445 "multicastGemID": loGemPortAttribs.multicastGemID,
446 "staticACL": loGemPortAttribs.staticACL,
447 "dynamicACL": loGemPortAttribs.dynamicACL,
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000448 "device-id": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300449 })
450
451 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000452 logger.Debugw(ctx, "Upstream GemPort attributes:", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300453 "gemPortID": loGemPortAttribs.gemPortID,
454 "upQueueID": loGemPortAttribs.upQueueID,
455 "downQueueID": loGemPortAttribs.downQueueID,
456 "pbitString": loGemPortAttribs.pbitString,
457 "prioQueueIndex": gemEntry.prioQueueIndex,
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000458 "device-id": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300459 })
460 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530461
462 oFsm.gemPortAttribsSlice = append(oFsm.gemPortAttribsSlice, loGemPortAttribs)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530463 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
464 meParams := me.ParamData{
465 EntityID: loGemPortAttribs.gemPortID,
466 Attributes: me.AttributeValueMap{
467 me.GemPortNetworkCtp_PortId: loGemPortAttribs.gemPortID,
468 me.GemPortNetworkCtp_TContPointer: oFsm.tcont0ID,
469 me.GemPortNetworkCtp_Direction: loGemPortAttribs.direction,
470 me.GemPortNetworkCtp_TrafficManagementPointerForUpstream: loGemPortAttribs.upQueueID,
471 me.GemPortNetworkCtp_PriorityQueuePointerForDownStream: loGemPortAttribs.downQueueID,
472 },
473 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530474 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpClassID, loGemPortAttribs.gemPortID, meParams.Attributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530475 var meAttributes me.AttributeValueMap //dummy , anyways we are not going to use the values.
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530476 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID, loGemPortAttribs.gemPortID, meAttributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530477
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530478 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemInterworkingTerminationPointClassID, loGemPortAttribs.gemPortID, meAttributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530479
480 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530481 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000482 if !oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
483 _ = aPAFsm.PFsm.Event(aniEvStartConfig)
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000484 } else {
485 logger.Debugw(ctx, "reconciling - skip omci-config of ANI side ", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000486 _ = aPAFsm.PFsm.Event(aniEvSkipOmciConfig)
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000487 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530488 }
489}
490
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530491//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000492func (oFsm *UniPonAniConfigFsm) enterConfigStartingState(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530493 logger.Info(ctx, "UniPonAniConfigFsm start", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000494 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000495 // in case the used channel is not yet defined (can be re-used after restarts)
496 if oFsm.omciMIdsResponseReceived == nil {
497 oFsm.omciMIdsResponseReceived = make(chan bool)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000498 logger.Debug(ctx, "UniPonAniConfigFsm - OMCI multiInstance RxChannel defined")
mpagenko3dbcdd22020-07-22 07:38:45 +0000499 } else {
500 // as we may 're-use' this instance of FSM and the connected channel
501 // make sure there is no 'lingering' request in the already existing channel:
502 // (simple loop sufficient as we are the only receiver)
503 for len(oFsm.omciMIdsResponseReceived) > 0 {
504 <-oFsm.omciMIdsResponseReceived
505 }
506 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000507 //ensure internal slices are empty (which might be set from previous run) - release memory
508 oFsm.gemPortAttribsSlice = nil
mpagenkocf48e452021-04-23 09:23:00 +0000509 oFsm.mutexIsAwaitingResponse.Lock()
510 //reset the canceled state possibly existing from previous reset
511 oFsm.isCanceled = false
512 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000513
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000514 // start go routine for processing of ANI config messages
dbainbri4d3a0dc2020-12-02 00:33:42 +0000515 go oFsm.processOmciAniMessages(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000516
517 //let the state machine run forward from here directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000518 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000519 if pConfigAniStateAFsm != nil {
520 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000521 go oFsm.prepareAndEnterConfigState(ctx, pConfigAniStateAFsm)
mpagenko3dbcdd22020-07-22 07:38:45 +0000522
mpagenko3dbcdd22020-07-22 07:38:45 +0000523 }
524}
525
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530526//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000527func (oFsm *UniPonAniConfigFsm) enterCreatingDot1PMapper(ctx context.Context, e *fsm.Event) {
528 logger.Debugw(ctx, "UniPonAniConfigFsm Tx Create::Dot1PMapper", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000529 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000530 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000531 oFsm.requestEventOffset = 0 //0 offset for last config request activity
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000532 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000533 meInstance, err := oFsm.pOmciCC.SendCreateDot1PMapper(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
534 oFsm.mapperSP0ID, oFsm.PAdaptFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300535 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000536 logger.Errorw(ctx, "Dot1PMapper create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300537 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000538 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300539 if pConfigAniStateAFsm != nil {
540 oFsm.mutexPLastTxMeInstance.Unlock()
541 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000542 go func(aPAFsm *cmn.AdapterFsm) {
543 if aPAFsm != nil && aPAFsm.PFsm != nil {
544 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300545 }
546 }(pConfigAniStateAFsm)
547 return
548 }
549 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000550 //accept also nil as (error) return value for writing to LastTx
551 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000552 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300553 oFsm.mutexPLastTxMeInstance.Unlock()
554
mpagenko3dbcdd22020-07-22 07:38:45 +0000555}
556
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530557//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000558func (oFsm *UniPonAniConfigFsm) enterCreatingMBPCD(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530559 logger.Info(ctx, "Creating Tx MAC Bridge Port Config Data", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000560 "EntitytId": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16),
561 "TPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000562 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
563 bridgePtr := cmn.MacBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.MacBpNo) //cmp also omci_cc.go::sendCreateMBServiceProfile
mpagenko3dbcdd22020-07-22 07:38:45 +0000564 meParams := me.ParamData{
565 EntityID: oFsm.macBPCD0ID,
566 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000567 me.MacBridgePortConfigurationData_BridgeIdPointer: bridgePtr,
568 me.MacBridgePortConfigurationData_PortNum: 0xFF, //fixed unique ANI side indication
569 me.MacBridgePortConfigurationData_TpType: 3, //for .1PMapper
570 me.MacBridgePortConfigurationData_TpPointer: oFsm.mapperSP0ID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000571 },
572 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000573 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000574 meInstance, err := oFsm.pOmciCC.SendCreateMBPConfigDataVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
575 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300576 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000577 logger.Errorw(ctx, "MBPConfigDataVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300578 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000579 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300580 if pConfigAniStateAFsm != nil {
581 oFsm.mutexPLastTxMeInstance.Unlock()
582 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000583 go func(aPAFsm *cmn.AdapterFsm) {
584 if aPAFsm != nil && aPAFsm.PFsm != nil {
585 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300586 }
587 }(pConfigAniStateAFsm)
588 return
589 }
590 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000591 //accept also nil as (error) return value for writing to LastTx
592 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000593 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300594 oFsm.mutexPLastTxMeInstance.Unlock()
595
mpagenko3dbcdd22020-07-22 07:38:45 +0000596}
597
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530598//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000599func (oFsm *UniPonAniConfigFsm) enterSettingTconts(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530600 logger.Info(ctx, "Tx Setting Tcont ", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000601 "EntitytId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
602 "AllocId": strconv.FormatInt(int64(oFsm.alloc0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000603 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700604 "tcontExist": oFsm.tcontSetBefore})
605 //If tcont was set before, then no need to set it again. Let state machine to proceed.
606 if oFsm.tcontSetBefore {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000607 go func(aPAFsm *cmn.AdapterFsm) {
608 if aPAFsm != nil && aPAFsm.PFsm != nil {
609 _ = aPAFsm.PFsm.Event(aniEvRxTcontsResp)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700610 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000611 }(oFsm.PAdaptFsm)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700612 return
613 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000614 meParams := me.ParamData{
615 EntityID: oFsm.tcont0ID,
616 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000617 me.TCont_AllocId: oFsm.alloc0ID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000618 },
619 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000620 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000621 meInstance, err := oFsm.pOmciCC.SendSetTcontVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
622 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300623 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000624 logger.Errorw(ctx, "TcontVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300625 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000626 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300627 if pConfigAniStateAFsm != nil {
628 oFsm.mutexPLastTxMeInstance.Unlock()
629 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000630 go func(aPAFsm *cmn.AdapterFsm) {
631 if aPAFsm != nil && aPAFsm.PFsm != nil {
632 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300633 }
634 }(pConfigAniStateAFsm)
635 return
636 }
637 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000638 //accept also nil as (error) return value for writing to LastTx
639 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000640 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300641 oFsm.mutexPLastTxMeInstance.Unlock()
642
mpagenko3dbcdd22020-07-22 07:38:45 +0000643}
644
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530645//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000646func (oFsm *UniPonAniConfigFsm) enterCreatingGemNCTPs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530647 logger.Info(ctx, "UniPonAniConfigFsm - start creating GemNWCtp loop", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000648 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000649 go oFsm.performCreatingGemNCTPs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000650}
651
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530652//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000653func (oFsm *UniPonAniConfigFsm) enterCreatingGemIWs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530654 logger.Info(ctx, "UniPonAniConfigFsm - start creating GemIwTP loop", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000655 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000656 go oFsm.performCreatingGemIWs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000657}
658
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000659func (oFsm *UniPonAniConfigFsm) enterSettingPQs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530660 logger.Info(ctx, "UniPonAniConfigFsm - start setting PrioQueue loop", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000661 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000662 go oFsm.performSettingPQs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000663}
664
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000665func (oFsm *UniPonAniConfigFsm) enterSettingDot1PMapper(ctx context.Context, e *fsm.Event) {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300666
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530667 logger.Info(ctx, "UniPonAniConfigFsm Tx Set::.1pMapper with all PBits set", log.Fields{"EntitytId": 0x8042, /*cmp above*/
mpagenko8b07c1b2020-11-26 10:36:31 +0000668 "toGemIw": 1024, /* cmp above */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000669 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000670
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530671 logger.Info(ctx, "UniPonAniConfigFsm Tx Set::1pMapper", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000672 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +0000673 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000674
mpagenko3dbcdd22020-07-22 07:38:45 +0000675 meParams := me.ParamData{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000676 EntityID: oFsm.mapperSP0ID,
Himani Chawla4d908332020-08-31 12:30:20 +0530677 Attributes: make(me.AttributeValueMap),
mpagenko3dbcdd22020-07-22 07:38:45 +0000678 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000679
680 //assign the GemPorts according to the configured Prio
681 var loPrioGemPortArray [8]uint16
682 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300683 if gemPortAttribs.isMulticast {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000684 logger.Debugw(ctx, "UniPonAniConfigFsm Port is Multicast, ignoring .1pMapper", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300685 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
686 "prioString": gemPortAttribs.pbitString})
687 continue
688 }
689 if gemPortAttribs.pbitString == "" {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000690 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString empty string error", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300691 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
692 "prioString": gemPortAttribs.pbitString})
693 continue
694 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000695 for i := 0; i < 8; i++ {
696 // "lenOfPbitMap(8) - i + 1" will give i-th pbit value from LSB position in the pbit map string
697 if prio, err := strconv.Atoi(string(gemPortAttribs.pbitString[7-i])); err == nil {
698 if prio == 1 { // Check this p-bit is set
699 if loPrioGemPortArray[i] == 0 {
700 loPrioGemPortArray[i] = gemPortAttribs.gemPortID //gemPortId=EntityID and unique
701 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000702 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString not unique", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000703 "device-id": oFsm.deviceID, "IgnoredGemPort": gemPortAttribs.gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000704 "SetGemPort": loPrioGemPortArray[i]})
705 }
706 }
707 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000708 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString evaluation error", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000709 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000710 "prioString": gemPortAttribs.pbitString, "position": i})
711 }
712
713 }
714 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300715
ozgecanetsia4b232302020-11-11 10:58:10 +0300716 var foundIwPtr = false
Himani Chawla4d908332020-08-31 12:30:20 +0530717 for index, value := range loPrioGemPortArray {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300718 meAttribute := fmt.Sprintf("InterworkTpPointerForPBitPriority%d", index)
Himani Chawla4d908332020-08-31 12:30:20 +0530719 if value != 0 {
720 foundIwPtr = true
Himani Chawla4d908332020-08-31 12:30:20 +0530721 meParams.Attributes[meAttribute] = value
dbainbri4d3a0dc2020-12-02 00:33:42 +0000722 logger.Debugw(ctx, "UniPonAniConfigFsm Set::1pMapper", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000723 "for Prio": index,
724 "IwPtr": strconv.FormatInt(int64(value), 16),
725 "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300726 } else {
727 // The null pointer 0xFFFF specifies that frames with the associated priority are to be discarded.
mpagenko8b5fdd22020-12-17 17:58:32 +0000728 // setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting
729 // but except for processing effort does not really harm - left to keep changes low
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300730 meParams.Attributes[meAttribute] = 0xffff
Himani Chawla4d908332020-08-31 12:30:20 +0530731 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000732 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300733 // The TP type value 0 also indicates bridging mapping, and the TP pointer should be set to 0xFFFF
mpagenko8b5fdd22020-12-17 17:58:32 +0000734 // setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting
735 // but except for processing effort does not really harm - left to keep changes low
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000736 meParams.Attributes[me.Ieee8021PMapperServiceProfile_TpPointer] = 0xffff
Himani Chawla4d908332020-08-31 12:30:20 +0530737
738 if !foundIwPtr {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530739 logger.Warn(ctx, "UniPonAniConfigFsm no GemIwPtr found for .1pMapper - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000740 "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300741 //TODO With multicast is possible that no upstream gem ports are not present in the tech profile,
742 // this reset needs to be performed only if the tech profile provides upstream gem ports but no priority is set
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000743 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000744 //pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300745 //if pConfigAniStateAFsm != nil {
746 // // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000747 // go func(aPAFsm *cmn.AdapterFsm) {
748 // if aPAFsm != nil && aPAFsm.PFsm != nil {
749 // _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300750 // }
751 // }(pConfigAniStateAFsm)
752 //}
753 //Moving forward the FSM as if the response was received correctly.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000754 pConfigAniStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000755 if pConfigAniStateAFsm != nil {
756 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000757 go func(aPAFsm *cmn.AdapterFsm) {
758 if aPAFsm != nil && aPAFsm.PFsm != nil {
759 _ = aPAFsm.PFsm.Event(aniEvRxDot1pmapSResp)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000760 }
761 }(pConfigAniStateAFsm)
762 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300763 } else {
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000764 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000765 meInstance, err := oFsm.pOmciCC.SendSetDot1PMapperVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(), true,
766 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300767 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000768 logger.Errorw(ctx, "Dot1PMapperVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300769 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000770 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300771 if pConfigAniStateAFsm != nil {
772 oFsm.mutexPLastTxMeInstance.Unlock()
773 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000774 go func(aPAFsm *cmn.AdapterFsm) {
775 if aPAFsm != nil && aPAFsm.PFsm != nil {
776 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300777 }
778 }(pConfigAniStateAFsm)
779 return
780 }
781 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300782 //accept also nil as (error) return value for writing to LastTx
783 // - this avoids misinterpretation of new received OMCI messages
784 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300785 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000786 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000787}
788
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000789func (oFsm *UniPonAniConfigFsm) enterAniConfigDone(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530790 logger.Info(ctx, "UniPonAniConfigFsm ani config done", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000791 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenko01e726e2020-10-23 09:45:29 +0000792 //store that the UNI related techProfile processing is done for the given Profile and Uni
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000793 oFsm.pUniTechProf.setConfigDone(oFsm.pOnuUniPort.UniID, oFsm.techProfileID, true)
794 if !oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000795 //use DeviceHandler event notification directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000796 oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset)))
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000797 //if techProfile processing is done it must be checked, if some prior/parallel flow configuration is pending
798 // but only in case the techProfile was configured (not deleted)
799 if oFsm.requestEventOffset == 0 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000800 go oFsm.pDeviceHandler.VerifyUniVlanConfigRequest(ctx, oFsm.pOnuUniPort, oFsm.techProfileID)
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000801 }
802 } else {
803 logger.Debugw(ctx, "reconciling - skip AniConfigDone processing", log.Fields{"device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000804 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000805 if oFsm.isChanSet() {
mpagenko01e726e2020-10-23 09:45:29 +0000806 // indicate processing done to the caller
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000807 logger.Debugw(ctx, "UniPonAniConfigFsm processingDone on channel", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000808 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
809 oFsm.chSuccess <- oFsm.procStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000810 oFsm.setChanSet(false) //reset the internal channel state
mpagenko3dbcdd22020-07-22 07:38:45 +0000811 }
mpagenko01e726e2020-10-23 09:45:29 +0000812
813 //the FSM is left active in this state as long as no specific reset or remove is requested from outside
mpagenko3dbcdd22020-07-22 07:38:45 +0000814}
815
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530816//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000817func (oFsm *UniPonAniConfigFsm) enterRemovingGemIW(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +0000818 // no need to protect access to oFsm.waitFlowDeleteChannel, only used in synchronized state entries
819 // or CancelProcessing() that uses separate isWaitingForFlowDelete to write to the channel
mpagenkobb47bc22021-04-20 13:29:09 +0000820 //flush the waitFlowDeleteChannel - possibly already/still set by some previous activity
821 select {
822 case <-oFsm.waitFlowDeleteChannel:
823 logger.Debug(ctx, "flushed waitFlowDeleteChannel")
824 default:
825 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000826
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000827 uniVlanConfigFsm := oFsm.pDeviceHandler.GetUniVlanConfigFsm(oFsm.pOnuUniPort.UniID)
828 if uniVlanConfigFsm != nil {
mpagenko3ce9fa02021-07-28 13:26:54 +0000829 // ensure mutexTPState not locked before calling some VlanConfigFsm activity (that might already be pending on it)
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000830 if uniVlanConfigFsm.IsFlowRemovePending(ctx, oFsm.waitFlowDeleteChannel) {
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000831 logger.Debugw(ctx, "flow remove pending - wait before processing gem port delete",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000832 log.Fields{"device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000833 // if flow remove is pending then wait for flow remove to finish first before proceeding with gem port delete
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000834 pConfigAniStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000835 if pConfigAniStateAFsm != nil {
836 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000837 go func(aPAFsm *cmn.AdapterFsm) {
838 if aPAFsm != nil && aPAFsm.PFsm != nil {
839 _ = aPAFsm.PFsm.Event(aniEvWaitFlowRem)
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000840 }
841 }(pConfigAniStateAFsm)
842 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000843 logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{"device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000844 }
845 return
Girish Gowdra26a40922021-01-29 17:14:34 -0800846 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000847 } else {
848 logger.Debugw(ctx, "uni vlan config doesn't exist - no flow remove could be pending",
849 log.Fields{"device-id": oFsm.deviceID, "techProfile-id": oFsm.techProfileID})
Girish Gowdra26a40922021-01-29 17:14:34 -0800850 }
851
mpagenko3ce9fa02021-07-28 13:26:54 +0000852 oFsm.pUniTechProf.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000853 // get the related GemPort entity Id from pUniTechProf, OMCI Gem* entityID is set to be equal to GemPortId!
mpagenko8b07c1b2020-11-26 10:36:31 +0000854 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +0000855 oFsm.pUniTechProf.mutexTPState.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000856 logger.Debugw(ctx, "UniPonAniConfigFsm - start removing one GemIwTP", log.Fields{
857 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko8b07c1b2020-11-26 10:36:31 +0000858 "GemIwTp-entity-id": loGemPortID})
859 oFsm.requestEventOffset = 1 //offset 1 to indicate last activity = remove
860
861 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000862 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000863 meInstance, err := oFsm.pOmciCC.SendDeleteGemIWTP(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
864 oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300865 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000866 logger.Errorw(ctx, "GemIWTP delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300867 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000868 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300869 if pConfigAniStateAFsm != nil {
870 oFsm.mutexPLastTxMeInstance.Unlock()
871 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000872 go func(aPAFsm *cmn.AdapterFsm) {
873 if aPAFsm != nil && aPAFsm.PFsm != nil {
874 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300875 }
876 }(pConfigAniStateAFsm)
877 return
878 }
879 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000880 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300881 oFsm.mutexPLastTxMeInstance.Unlock()
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530882 logger.Infow(ctx, "Deleting GemIWTP at the ONU DB ", log.Fields{"device-id": oFsm.deviceID, "GEMID": loGemPortID})
883 oFsm.pOnuDB.DeleteMe(me.GemInterworkingTerminationPointClassID, loGemPortID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000884}
885
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530886//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000887func (oFsm *UniPonAniConfigFsm) enterWaitingFlowRem(ctx context.Context, e *fsm.Event) {
mpagenkobb47bc22021-04-20 13:29:09 +0000888 oFsm.mutexIsAwaitingResponse.Lock()
889 oFsm.isWaitingForFlowDelete = true
890 oFsm.mutexIsAwaitingResponse.Unlock()
891 select {
892 // maybe be also some outside cancel (but no context modeled for the moment ...)
893 // case <-ctx.Done():
894 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000895 case <-time.After(2 * oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //give flow processing enough time to finish (but try to be less than rwCore flow timeouts)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000896 logger.Warnw(ctx, "UniPonAniConfigFsm WaitingFlowRem timeout", log.Fields{
897 "for device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000898 oFsm.mutexIsAwaitingResponse.Lock()
899 oFsm.isWaitingForFlowDelete = false
900 oFsm.mutexIsAwaitingResponse.Unlock()
901 //if the flow is not removed as expected we just try to continue with GemPort removal and hope things are clearing up afterwards
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000902 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000903 if pConfigAniStateAFsm != nil {
904 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000905 go func(aPAFsm *cmn.AdapterFsm) {
906 if aPAFsm != nil && aPAFsm.PFsm != nil {
907 _ = aPAFsm.PFsm.Event(aniEvFlowRemDone)
mpagenkobb47bc22021-04-20 13:29:09 +0000908 }
909 }(pConfigAniStateAFsm)
910 } else {
911 logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000912 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000913 }
914 return
915
916 case success := <-oFsm.waitFlowDeleteChannel:
917 if success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000918 logger.Debugw(ctx, "UniPonAniConfigFsm flow removed info received", log.Fields{
919 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000920 oFsm.mutexIsAwaitingResponse.Lock()
921 oFsm.isWaitingForFlowDelete = false
922 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000923 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000924 if pConfigAniStateAFsm != nil {
925 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000926 go func(aPAFsm *cmn.AdapterFsm) {
927 if aPAFsm != nil && aPAFsm.PFsm != nil {
928 _ = aPAFsm.PFsm.Event(aniEvFlowRemDone)
mpagenkobb47bc22021-04-20 13:29:09 +0000929 }
930 }(pConfigAniStateAFsm)
931 } else {
932 logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000933 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000934 }
935 return
936 }
937 // waiting was aborted (probably on external request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000938 logger.Debugw(ctx, "UniPonAniConfigFsm WaitingFlowRem aborted", log.Fields{
939 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000940 oFsm.mutexIsAwaitingResponse.Lock()
941 oFsm.isWaitingForFlowDelete = false
942 oFsm.mutexIsAwaitingResponse.Unlock()
943 //to be sure we can just generate the reset-event to ensure leaving this state towards 'reset'
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000944 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000945 if pConfigAniStateAFsm != nil {
946 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000947 go func(aPAFsm *cmn.AdapterFsm) {
948 if aPAFsm != nil && aPAFsm.PFsm != nil {
949 _ = aPAFsm.PFsm.Event(aniEvReset)
mpagenkobb47bc22021-04-20 13:29:09 +0000950 }
951 }(pConfigAniStateAFsm)
952 }
953 return
954 }
955}
956
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530957//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000958func (oFsm *UniPonAniConfigFsm) enterRemovingGemNCTP(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +0000959 oFsm.pUniTechProf.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000960 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +0000961 oFsm.pUniTechProf.mutexTPState.RUnlock()
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530962 logger.Info(ctx, "UniPonAniConfigFsm - start removing one GemNCTP", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000963 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko8b07c1b2020-11-26 10:36:31 +0000964 "GemNCTP-entity-id": loGemPortID})
965 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000966 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000967 meInstance, err := oFsm.pOmciCC.SendDeleteGemNCTP(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
968 oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300969 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000970 logger.Errorw(ctx, "GemNCTP delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300971 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000972 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300973 if pConfigAniStateAFsm != nil {
974 oFsm.mutexPLastTxMeInstance.Unlock()
975 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000976 go func(aPAFsm *cmn.AdapterFsm) {
977 if aPAFsm != nil && aPAFsm.PFsm != nil {
978 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300979 }
980 }(pConfigAniStateAFsm)
981 return
982 }
983 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000984 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000985 oFsm.mutexPLastTxMeInstance.Unlock()
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530986 oFsm.pOnuDB.DeleteMe(me.GemPortNetworkCtpClassID, loGemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800987 // Mark the gem port to be removed for Performance History monitoring
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000988 OnuMetricsManager := oFsm.pDeviceHandler.GetOnuMetricsManager()
989 if OnuMetricsManager != nil {
990 OnuMetricsManager.RemoveGemPortForPerfMonitoring(ctx, loGemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -0800991 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000992}
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530993
994//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000995func (oFsm *UniPonAniConfigFsm) enterRemovingTD(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +0000996 oFsm.pUniTechProf.mutexTPState.RLock()
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300997 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +0000998 oFsm.pUniTechProf.mutexTPState.RUnlock()
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530999 logger.Info(ctx, "UniPonAniConfigFsm - start removing Traffic Descriptor", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001000 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001001 "TD-entity-id": loGemPortID})
1002
1003 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001004 meInstance, err := oFsm.pOmciCC.SendDeleteTD(log.WithSpanFromContext(context.TODO(), ctx),
1005 oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001006
1007 if err != nil {
1008 logger.Errorw(ctx, "TD delete failed - proceed fsm",
1009 log.Fields{"device-id": oFsm.deviceID, "gemPortID": loGemPortID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001010 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001011 if pConfigAniStateAFsm != nil {
1012 oFsm.mutexPLastTxMeInstance.Unlock()
1013 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001014 go func(aPAFsm *cmn.AdapterFsm) {
1015 if aPAFsm != nil && aPAFsm.PFsm != nil {
1016 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001017 }
1018 }(pConfigAniStateAFsm)
1019 return
1020 }
1021 }
1022 oFsm.pLastTxMeInstance = meInstance
1023 oFsm.mutexPLastTxMeInstance.Unlock()
1024}
mpagenko8b07c1b2020-11-26 10:36:31 +00001025
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301026//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001027func (oFsm *UniPonAniConfigFsm) enterResettingTcont(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301028 logger.Info(ctx, "UniPonAniConfigFsm - start resetting the TCont", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001029 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001030
1031 oFsm.requestEventOffset = 1 //offset 1 for last remove activity
1032 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
1033 meParams := me.ParamData{
1034 EntityID: oFsm.tcont0ID,
1035 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001036 me.TCont_AllocId: cmn.UnusedTcontAllocID,
mpagenko8b07c1b2020-11-26 10:36:31 +00001037 },
1038 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001039 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001040 meInstance, err := oFsm.pOmciCC.SendSetTcontVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1041 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001042 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001043 logger.Errorw(ctx, "TcontVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001044 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001045 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001046 if pConfigAniStateAFsm != nil {
1047 oFsm.mutexPLastTxMeInstance.Unlock()
1048 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001049 go func(aPAFsm *cmn.AdapterFsm) {
1050 if aPAFsm != nil && aPAFsm.PFsm != nil {
1051 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001052 }
1053 }(pConfigAniStateAFsm)
1054 return
1055 }
1056 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001057 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001058 oFsm.mutexPLastTxMeInstance.Unlock()
1059
mpagenko8b07c1b2020-11-26 10:36:31 +00001060}
1061
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301062//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001063func (oFsm *UniPonAniConfigFsm) enterRemoving1pMapper(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301064 logger.Info(ctx, "UniPonAniConfigFsm - start deleting the .1pMapper", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001065 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
bseenivaeba8eb12024-12-13 11:54:28 +05301066 var mapGemPortParams map[uint16]*gemPortParamStruct
Mahir Gunyel9545be22021-07-04 15:53:16 -07001067 unicastGemCount := 0
bseenivaeba8eb12024-12-13 11:54:28 +05301068 oFsm.pUniTechProf.mutexTPState.RLock()
1069 if _, ok := oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey]; ok {
1070 mapGemPortParams = oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].mapGemPortParams
1071 } else {
1072 logger.Warnw(ctx, "GemPortParams not found in mapPonAniConfig", log.Fields{"device-id": oFsm.deviceID,
1073 "uni-id": oFsm.pOnuUniPort.UniID})
1074 }
1075 oFsm.pUniTechProf.mutexTPState.RUnlock()
Mahir Gunyel9545be22021-07-04 15:53:16 -07001076 for _, gemEntry := range mapGemPortParams {
1077 if !gemEntry.isMulticast {
1078 unicastGemCount++
1079 }
1080 }
1081 if unicastGemCount > 1 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001082 logger.Debugw(ctx, "UniPonAniConfigFsm - Not the last gem in fsm. Skip the rest", log.Fields{
1083 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "unicast-gem-count": unicastGemCount, "gem-count": len(mapGemPortParams)})
1084 pConfigAniStateAFsm := oFsm.PAdaptFsm
Mahir Gunyel9545be22021-07-04 15:53:16 -07001085 if pConfigAniStateAFsm != nil {
1086 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001087 go func(aPAFsm *cmn.AdapterFsm) {
1088 if aPAFsm != nil && aPAFsm.PFsm != nil {
1089 _ = aPAFsm.PFsm.Event(aniEvRemGemDone)
Mahir Gunyel9545be22021-07-04 15:53:16 -07001090 }
1091 }(pConfigAniStateAFsm)
1092 return
1093 }
1094 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001095 logger.Debugw(ctx, "UniPonAniConfigFsm - Last gem in fsm. Continue with Mapper removal", log.Fields{
1096 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "unicast-gem-count": unicastGemCount, "gem-count": len(mapGemPortParams)})
mpagenko8b07c1b2020-11-26 10:36:31 +00001097
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001098 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001099 meInstance, err := oFsm.pOmciCC.SendDeleteDot1PMapper(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1100 oFsm.PAdaptFsm.CommChan, oFsm.mapperSP0ID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001101 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001102 logger.Errorw(ctx, "Dot1Mapper delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001103 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001104 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001105 if pConfigAniStateAFsm != nil {
1106 oFsm.mutexPLastTxMeInstance.Unlock()
1107 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001108 go func(aPAFsm *cmn.AdapterFsm) {
1109 if aPAFsm != nil && aPAFsm.PFsm != nil {
1110 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001111 }
1112 }(pConfigAniStateAFsm)
1113 return
1114 }
1115 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001116 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001117 oFsm.mutexPLastTxMeInstance.Unlock()
1118
mpagenko8b07c1b2020-11-26 10:36:31 +00001119}
1120
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301121//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001122func (oFsm *UniPonAniConfigFsm) enterRemovingAniBPCD(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301123 logger.Info(ctx, "UniPonAniConfigFsm - start deleting the ANI MBCD", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001124 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001125
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001126 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001127 meInstance, err := oFsm.pOmciCC.SendDeleteMBPConfigData(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1128 oFsm.PAdaptFsm.CommChan, oFsm.macBPCD0ID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001129 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001130 logger.Errorw(ctx, "MBPConfigData delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001131 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001132 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001133 if pConfigAniStateAFsm != nil {
1134 oFsm.mutexPLastTxMeInstance.Unlock()
1135 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001136 go func(aPAFsm *cmn.AdapterFsm) {
1137 if aPAFsm != nil && aPAFsm.PFsm != nil {
1138 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001139 }
1140 }(pConfigAniStateAFsm)
1141 return
1142 }
1143 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001144 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001145 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +00001146}
1147
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001148func (oFsm *UniPonAniConfigFsm) enterAniRemoveDone(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301149 logger.Info(ctx, "UniPonAniConfigFsm ani removal done", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001150 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001151 //use DeviceHandler event notification directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001152 oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset)))
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001153 if oFsm.isChanSet() {
mpagenko8b07c1b2020-11-26 10:36:31 +00001154 // indicate processing done to the caller
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001155 logger.Debugw(ctx, "UniPonAniConfigFsm processingDone on channel", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +00001156 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
1157 oFsm.chSuccess <- oFsm.procStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001158 oFsm.setChanSet(false) //reset the internal channel state
mpagenko8b07c1b2020-11-26 10:36:31 +00001159 }
1160
1161 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001162 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko8b07c1b2020-11-26 10:36:31 +00001163 if pConfigAniStateAFsm != nil {
1164 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001165 go func(aPAFsm *cmn.AdapterFsm) {
1166 if aPAFsm != nil && aPAFsm.PFsm != nil {
1167 _ = aPAFsm.PFsm.Event(aniEvReset)
mpagenko8b07c1b2020-11-26 10:36:31 +00001168 }
1169 }(pConfigAniStateAFsm)
1170 }
1171}
1172
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001173func (oFsm *UniPonAniConfigFsm) enterResettingState(ctx context.Context, e *fsm.Event) {
1174 logger.Debugw(ctx, "UniPonAniConfigFsm resetting", log.Fields{
1175 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001176
mpagenko45cc6a32021-07-23 10:06:57 +00001177 if oFsm.isChanSet() {
1178 // indicate processing error to the caller (in case there was still some open request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001179 logger.Debugw(ctx, "UniPonAniConfigFsm processingError on channel", log.Fields{
mpagenko45cc6a32021-07-23 10:06:57 +00001180 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
1181 //use non-blocking channel send to avoid blocking because of non-existing receiver
1182 // (even though the channel is checked on 'set', the outside receiver channel might (theoretically) already be deleted)
1183 select {
1184 case oFsm.chSuccess <- 0:
1185 default:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001186 logger.Debugw(ctx, "UniPonAniConfigFsm processingError not send on channel (no receiver)", log.Fields{
mpagenko45cc6a32021-07-23 10:06:57 +00001187 "device-id": oFsm.deviceID})
1188 }
1189 oFsm.setChanSet(false) //reset the internal channel state
1190 }
1191
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001192 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko3dbcdd22020-07-22 07:38:45 +00001193 if pConfigAniStateAFsm != nil {
1194 // abort running message processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001195 fsmAbortMsg := cmn.Message{
1196 Type: cmn.TestMsg,
1197 Data: cmn.TestMessage{
1198 TestMessageVal: cmn.AbortMessageProcessing,
mpagenko3dbcdd22020-07-22 07:38:45 +00001199 },
1200 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001201 pConfigAniStateAFsm.CommChan <- fsmAbortMsg
mpagenko3dbcdd22020-07-22 07:38:45 +00001202
1203 //try to restart the FSM to 'disabled', decouple event transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001204 go func(aPAFsm *cmn.AdapterFsm) {
1205 if aPAFsm != nil && aPAFsm.PFsm != nil {
1206 _ = aPAFsm.PFsm.Event(aniEvRestart)
mpagenko3dbcdd22020-07-22 07:38:45 +00001207 }
1208 }(pConfigAniStateAFsm)
Akash Soni3de0e062024-12-11 16:37:26 +05301209 logger.Warnf(ctx, "calling HandleAniConfigFSMFailure resetting", log.Fields{
1210 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
1211 oFsm.pDeviceHandler.HandleAniConfigFSMFailure(ctx, oFsm.pOnuUniPort.UniID)
mpagenko3dbcdd22020-07-22 07:38:45 +00001212 }
1213}
1214
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301215//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001216func (oFsm *UniPonAniConfigFsm) enterDisabledState(ctx context.Context, e *fsm.Event) {
1217 logger.Debugw(ctx, "UniPonAniConfigFsm enters disabled state", log.Fields{
1218 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001219 oFsm.mutexPLastTxMeInstance.Lock()
1220 defer oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00001221 oFsm.pLastTxMeInstance = nil
mpagenko1cc3cb42020-07-27 15:24:38 +00001222}
1223
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001224func (oFsm *UniPonAniConfigFsm) processOmciAniMessages(ctx context.Context) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301225 logger.Info(ctx, "Start UniPonAniConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001226loop:
1227 for {
mpagenko3dbcdd22020-07-22 07:38:45 +00001228 // case <-ctx.Done():
mpagenko01e726e2020-10-23 09:45:29 +00001229 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001230 // break loop
bseenivaeba8eb12024-12-13 11:54:28 +05301231 select {
1232 case message, ok := <-oFsm.PAdaptFsm.CommChan:
1233 if !ok {
1234 logger.Warn(ctx, "UniPonAniConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID})
1235 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
1236 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +00001237 break loop
1238 }
bseenivaeba8eb12024-12-13 11:54:28 +05301239 logger.Debugw(ctx, "UniPonAniConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID})
1240
1241 switch message.Type {
1242 case cmn.TestMsg:
1243 msg, _ := message.Data.(cmn.TestMessage)
1244 if msg.TestMessageVal == cmn.AbortMessageProcessing {
1245 logger.Infow(ctx, "UniPonAniConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID})
1246 break loop
1247 }
1248 logger.Warnw(ctx, "UniPonAniConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal})
1249 case cmn.OMCI:
1250 msg, _ := message.Data.(cmn.OmciMessage)
1251 oFsm.handleOmciAniConfigMessage(ctx, msg)
1252 default:
1253 logger.Warn(ctx, "UniPonAniConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID,
1254 "message.Type": message.Type})
1255 }
1256 case _, ok := <-oFsm.pDeviceHandler.GetDeviceDeleteCommChan(ctx):
1257 if !ok {
1258 logger.Warnw(ctx, "Device deletion channel closed", log.Fields{"device-id": oFsm.deviceID})
1259 }
1260 break loop
Himani Chawla4d908332020-08-31 12:30:20 +05301261 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001262
Himani Chawla4d908332020-08-31 12:30:20 +05301263 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001264 logger.Infow(ctx, "End UniPonAniConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301265}
1266
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001267func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigCreateResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +05301268 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse)
1269 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001270 logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001271 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301272 return
1273 }
1274 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
1275 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001276 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001277 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301278 return
1279 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001280 logger.Debugw(ctx, "CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenkofc4f56e2020-11-04 17:17:49 +00001281 if msgObj.Result == me.Success || msgObj.Result == me.InstanceExists {
1282 //if the result is ok or Instance already exists (latest needed at least as long as we do not clear the OMCI techProfile data)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001283 oFsm.mutexPLastTxMeInstance.RLock()
1284 if oFsm.pLastTxMeInstance != nil {
1285 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1286 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1287 // maybe we can use just the same eventName for different state transitions like "forward"
1288 // - might be checked, but so far I go for sure and have to inspect the concrete state events ...
1289 switch oFsm.pLastTxMeInstance.GetName() {
1290 case "Ieee8021PMapperServiceProfile":
1291 { // let the FSM proceed ...
1292 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001293 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxDot1pmapCResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001294 }
1295 case "MacBridgePortConfigurationData":
1296 { // let the FSM proceed ...
1297 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001298 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxMbpcdResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001299 }
1300 case "GemPortNetworkCtp", "GemInterworkingTerminationPoint", "MulticastGemInterworkingTerminationPoint":
1301 { // let aniConfig Multi-Id processing proceed by stopping the wait function
1302 oFsm.mutexPLastTxMeInstance.RUnlock()
1303 oFsm.omciMIdsResponseReceived <- true
1304 }
1305 default:
1306 {
1307 oFsm.mutexPLastTxMeInstance.RUnlock()
1308 logger.Warnw(ctx, "Unsupported ME name received!",
1309 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1310 }
mpagenkofc4f56e2020-11-04 17:17:49 +00001311 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001312 } else {
1313 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenkofc4f56e2020-11-04 17:17:49 +00001314 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001315 } else {
1316 oFsm.mutexPLastTxMeInstance.RUnlock()
1317 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +00001318 }
1319 } else {
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001320 logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?",
1321 log.Fields{"Error": msgObj.Result, "device-id": oFsm.deviceID})
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001322 // possibly force FSM into abort or ignore some errors for some messages?
1323 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1324 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
Himani Chawla4d908332020-08-31 12:30:20 +05301325 return
1326 }
Himani Chawla4d908332020-08-31 12:30:20 +05301327}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001328func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigSetFailResponseMessage(ctx context.Context, msgObj *omci.SetResponse) {
Mahir Gunyel01034b62021-06-29 11:25:09 -07001329 //If TCONT fails, then we need to revert the allocated TCONT in DB.
1330 //Because FSMs are running sequentially, we don't expect the same TCONT hit by another tech-profile FSM while this FSM is running.
1331 oFsm.mutexPLastTxMeInstance.RLock()
1332 defer oFsm.mutexPLastTxMeInstance.RUnlock()
1333 if oFsm.pLastTxMeInstance != nil && msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1334 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1335 switch oFsm.pLastTxMeInstance.GetName() {
1336 case "TCont":
1337 //If this is for TCONT creation(requestEventOffset=0) and this is the first allocation of TCONT(so noone else is using the same TCONT)
1338 //We should revert DB
bseenivaeba8eb12024-12-13 11:54:28 +05301339 oFsm.pUniTechProf.mutexTPState.RLock()
Mahir Gunyel01034b62021-06-29 11:25:09 -07001340 if oFsm.requestEventOffset == 0 && !oFsm.tcontSetBefore && oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey] != nil {
1341 logger.Debugw(ctx, "UniPonAniConfigFsm TCONT creation failed on device. Freeing alloc id", log.Fields{"device-id": oFsm.deviceID,
1342 "alloc-id": oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID, "uni-tp": oFsm.uniTpKey})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001343 if oFsm.pOnuDeviceEntry != nil {
1344 oFsm.pOnuDeviceEntry.FreeTcont(ctx, oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID)
Mahir Gunyel01034b62021-06-29 11:25:09 -07001345 } else {
1346 logger.Warnw(ctx, "Unable to get device entry! couldn't free tcont",
1347 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1348 }
1349 }
bseenivaeba8eb12024-12-13 11:54:28 +05301350 oFsm.pUniTechProf.mutexTPState.RUnlock()
Mahir Gunyel01034b62021-06-29 11:25:09 -07001351 default:
1352 logger.Warnw(ctx, "Unsupported ME name received with error!",
1353 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "result": msgObj.Result, "device-id": oFsm.deviceID})
1354 }
1355 }
1356}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001357func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigSetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +05301358 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
1359 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001360 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be detected for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001361 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301362 return
1363 }
1364 msgObj, msgOk := msgLayer.(*omci.SetResponse)
1365 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001366 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be assigned for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001367 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301368 return
1369 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001370 logger.Debugw(ctx, "UniPonAniConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +05301371 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001372 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci SetResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00001373 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001374 // possibly force FSM into abort or ignore some errors for some messages?
1375 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1376 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
Mahir Gunyel01034b62021-06-29 11:25:09 -07001377 oFsm.handleOmciAniConfigSetFailResponseMessage(ctx, msgObj)
Himani Chawla4d908332020-08-31 12:30:20 +05301378 return
1379 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001380 oFsm.mutexPLastTxMeInstance.RLock()
1381 if oFsm.pLastTxMeInstance != nil {
1382 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1383 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1384 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
1385 // if, then something like:
1386 //oFsm.pOnuDB.StoreMe(msgObj)
Himani Chawla4d908332020-08-31 12:30:20 +05301387
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001388 switch oFsm.pLastTxMeInstance.GetName() {
1389 case "TCont":
1390 { // let the FSM proceed ...
1391 oFsm.mutexPLastTxMeInstance.RUnlock()
1392 if oFsm.requestEventOffset == 0 { //from TCont config request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001393 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxTcontsResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001394 } else { // from T-Cont reset request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001395 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxResetTcontResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001396 }
1397 }
1398 case "PriorityQueue", "MulticastGemInterworkingTerminationPoint":
1399 { // let the PrioQueue init proceed by stopping the wait function
1400 oFsm.mutexPLastTxMeInstance.RUnlock()
1401 oFsm.omciMIdsResponseReceived <- true
1402 }
1403 case "Ieee8021PMapperServiceProfile":
1404 { // let the FSM proceed ...
1405 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001406 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxDot1pmapSResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001407 }
1408 default:
1409 {
1410 oFsm.mutexPLastTxMeInstance.RUnlock()
1411 logger.Warnw(ctx, "Unsupported ME name received!",
1412 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001413 }
Himani Chawla4d908332020-08-31 12:30:20 +05301414 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001415 } else {
1416 oFsm.mutexPLastTxMeInstance.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +05301417 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001418 } else {
1419 oFsm.mutexPLastTxMeInstance.RUnlock()
1420 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301421 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001422}
1423
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001424func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigDeleteResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
mpagenko8b07c1b2020-11-26 10:36:31 +00001425 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeDeleteResponse)
1426 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001427 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be detected for DeleteResponse",
mpagenko8b07c1b2020-11-26 10:36:31 +00001428 log.Fields{"device-id": oFsm.deviceID})
1429 return
1430 }
1431 msgObj, msgOk := msgLayer.(*omci.DeleteResponse)
1432 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001433 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be assigned for DeleteResponse",
mpagenko8b07c1b2020-11-26 10:36:31 +00001434 log.Fields{"device-id": oFsm.deviceID})
1435 return
1436 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001437 logger.Debugw(ctx, "UniPonAniConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
Akash Soni8eff4632024-12-11 13:41:46 +05301438 if msgObj.Result == me.UnknownInstance {
1439 logger.Warnw(ctx, "UniPonAniConfigFsm - Unknow Instance",
1440 log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj, "Error": msgObj.Result})
1441 } else if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001442 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci DeleteResponse Error",
mpagenko8b07c1b2020-11-26 10:36:31 +00001443 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
1444 //TODO: - later: possibly force FSM into abort or ignore some errors for some messages?
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001445 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1446 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
mpagenko8b07c1b2020-11-26 10:36:31 +00001447 return
1448 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001449 oFsm.mutexPLastTxMeInstance.RLock()
1450 if oFsm.pLastTxMeInstance != nil {
1451 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1452 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1453 //remove ME from DB //TODO??? obviously the Python code does not store/remove the config ...
1454 // if, then something like: oFsm.pOnuDB.XyyMe(msgObj)
mpagenko8b07c1b2020-11-26 10:36:31 +00001455
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001456 switch oFsm.pLastTxMeInstance.GetName() {
1457 case "GemInterworkingTerminationPoint":
1458 { // let the FSM proceed ...
1459 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001460 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemGemiwResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001461 }
1462 case "GemPortNetworkCtp":
1463 { // let the FSM proceed ...
1464 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001465 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemGemntpResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001466 }
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001467 case "TrafficDescriptor":
1468 { // let the FSM proceed ...
1469 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001470 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemTdResp)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001471 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001472 case "Ieee8021PMapperServiceProfile":
1473 { // let the FSM proceed ...
1474 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001475 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRem1pMapperResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001476 }
1477 case "MacBridgePortConfigurationData":
1478 { // this is the last event of the T-Cont cleanup procedure, FSM may be reset here
1479 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001480 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemAniBPCDResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001481 }
1482 default:
1483 {
1484 oFsm.mutexPLastTxMeInstance.RUnlock()
1485 logger.Warnw(ctx, "Unsupported ME name received!",
1486 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1487 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001488 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001489 } else {
1490 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko8b07c1b2020-11-26 10:36:31 +00001491 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001492 } else {
1493 oFsm.mutexPLastTxMeInstance.RUnlock()
1494 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001495 }
1496}
1497
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001498func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001499 logger.Debugw(ctx, "Rx OMCI UniPonAniConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001500 "msgType": msg.OmciMsg.MessageType})
1501
1502 switch msg.OmciMsg.MessageType {
1503 case omci.CreateResponseType:
1504 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001505 oFsm.handleOmciAniConfigCreateResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301506
mpagenko3dbcdd22020-07-22 07:38:45 +00001507 } //CreateResponseType
1508 case omci.SetResponseType:
1509 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001510 oFsm.handleOmciAniConfigSetResponseMessage(ctx, msg)
mpagenko3dbcdd22020-07-22 07:38:45 +00001511
mpagenko3dbcdd22020-07-22 07:38:45 +00001512 } //SetResponseType
mpagenko8b07c1b2020-11-26 10:36:31 +00001513 case omci.DeleteResponseType:
1514 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001515 oFsm.handleOmciAniConfigDeleteResponseMessage(ctx, msg)
mpagenko8b07c1b2020-11-26 10:36:31 +00001516
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001517 } //DeleteResponseType
mpagenko3dbcdd22020-07-22 07:38:45 +00001518 default:
1519 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001520 logger.Errorw(ctx, "UniPonAniConfigFsm - Rx OMCI unhandled MsgType",
mpagenko01e726e2020-10-23 09:45:29 +00001521 log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001522 return
1523 }
1524 }
1525}
1526
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001527func (oFsm *UniPonAniConfigFsm) performCreatingGemNCTPs(ctx context.Context) {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001528 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
1529 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301530 logger.Info(ctx, "UniPonAniConfigFsm Tx Create::GemNWCtp", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001531 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
1532 "TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001533 "device-id": oFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001534 meParams := me.ParamData{
1535 EntityID: gemPortAttribs.gemPortID, //unique, same as PortId
1536 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001537 me.GemPortNetworkCtp_PortId: gemPortAttribs.gemPortID,
1538 me.GemPortNetworkCtp_TContPointer: oFsm.tcont0ID,
1539 me.GemPortNetworkCtp_Direction: gemPortAttribs.direction,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001540 //ONU-G.TrafficManagementOption dependency ->PrioQueue or TCont
1541 // TODO!! verify dependency and QueueId in case of Multi-GemPort setup!
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001542 me.GemPortNetworkCtp_TrafficManagementPointerForUpstream: gemPortAttribs.upQueueID, //might be different in wrr-only Setup - tcont0ID
1543 me.GemPortNetworkCtp_PriorityQueuePointerForDownStream: gemPortAttribs.downQueueID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001544 },
1545 }
Holger Hildebrandtc408f492022-07-14 08:39:24 +00001546 if oFsm.techProfileType == cTechProfileTypeXgsPon {
1547 meParams.Attributes[me.GemPortNetworkCtp_EncryptionKeyRing] = GemEncryptKeyRingUnicastDownstreamOnly
1548 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001549 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001550 meInstance, err := oFsm.pOmciCC.SendCreateGemNCTPVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1551 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001552 if err != nil {
1553 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001554 logger.Errorw(ctx, "GemNCTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001555 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001556 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001557 return
1558 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001559 //accept also nil as (error) return value for writing to LastTx
1560 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001561 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001562 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001563 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001564 err = oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001565 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001566 logger.Errorw(ctx, "GemNWCtp create failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001567 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001568 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001569 return
1570 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301571 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpClassID, gemPortAttribs.gemPortID, meParams.Attributes)
Girish Gowdra50e56422021-06-01 16:46:04 -07001572 // Mark the gem port to be added for Performance History monitoring
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001573 OnuMetricsManager := oFsm.pDeviceHandler.GetOnuMetricsManager()
1574 if OnuMetricsManager != nil {
1575 OnuMetricsManager.AddGemPortForPerfMonitoring(ctx, gemPortAttribs.gemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001576 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001577 } //for all GemPorts of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +00001578
1579 // if Config has been done for all GemPort instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001580 logger.Debugw(ctx, "GemNWCtp create loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001581 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxGemntcpsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001582}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001583func (oFsm *UniPonAniConfigFsm) hasMulticastGem(ctx context.Context) bool {
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001584 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
1585 if gemPortAttribs.isMulticast {
1586 logger.Debugw(ctx, "Found multicast gem", log.Fields{"device-id": oFsm.deviceID})
1587 return true
1588 }
1589 }
1590 return false
1591}
mpagenko3dbcdd22020-07-22 07:38:45 +00001592
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001593func (oFsm *UniPonAniConfigFsm) performCreatingGemIWs(ctx context.Context) {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001594 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
1595 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301596 logger.Info(ctx, "UniPonAniConfigFsm Tx Create::GemIwTp", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001597 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
1598 "SPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001599 "device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001600
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301601 var meParams me.ParamData
ozgecanetsia4b232302020-11-11 10:58:10 +03001602 //TODO if the port has only downstream direction the isMulticast flag can be removed.
1603 if gemPortAttribs.isMulticast {
ozgecanetsia4b232302020-11-11 10:58:10 +03001604
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301605 meParams = me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001606 EntityID: gemPortAttribs.multicastGemID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001607 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001608 me.MulticastGemInterworkingTerminationPoint_GemPortNetworkCtpConnectivityPointer: gemPortAttribs.multicastGemID,
1609 me.MulticastGemInterworkingTerminationPoint_InterworkingOption: 0, // Don't Care
1610 me.MulticastGemInterworkingTerminationPoint_ServiceProfilePointer: 0, // Don't Care
1611 me.MulticastGemInterworkingTerminationPoint_GalProfilePointer: cmn.GalEthernetEID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001612 },
1613 }
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001614 if oFsm.pUniTechProf.multicastConfiguredForOtherUniTps(ctx, oFsm.uniTpKey) {
1615 logger.Debugw(ctx, "MulticastGemInterworkingTP already exist", log.Fields{"device-id": oFsm.deviceID, "multicast-gem-id": gemPortAttribs.multicastGemID})
1616 continue
1617 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001618 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001619 meInstance, err := oFsm.pOmciCC.SendCreateMulticastGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(),
1620 true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001621 if err != nil {
1622 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001623 logger.Errorw(ctx, "MulticastGemIWTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001624 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001625 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001626 return
1627
1628 }
ozgecanetsia4b232302020-11-11 10:58:10 +03001629 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001630 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001631 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001632 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001633 if err != nil {
ozgecanetsiab36ed572021-04-01 10:38:48 +03001634 logger.Errorw(ctx, "MulticastGemIWTP create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001635 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001636 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001637 return
1638 }
1639 ipv4MulticastTable := make([]uint8, 12)
1640 //Gem Port ID
1641 binary.BigEndian.PutUint16(ipv4MulticastTable[0:], gemPortAttribs.multicastGemID)
1642 //Secondary Key
1643 binary.BigEndian.PutUint16(ipv4MulticastTable[2:], 0)
1644 // Multicast IP range start This is the 224.0.0.1 address
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001645 binary.BigEndian.PutUint32(ipv4MulticastTable[4:], cmn.IPToInt32(net.IPv4(224, 0, 0, 0)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001646 // MulticastIp range stop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001647 binary.BigEndian.PutUint32(ipv4MulticastTable[8:], cmn.IPToInt32(net.IPv4(239, 255, 255, 255)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001648
1649 meIPV4MCTableParams := me.ParamData{
1650 EntityID: gemPortAttribs.multicastGemID,
1651 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001652 me.MulticastGemInterworkingTerminationPoint_Ipv4MulticastAddressTable: ipv4MulticastTable,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001653 },
1654 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001655 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001656 meIPV4MCTableInstance, err := oFsm.pOmciCC.SendSetMulticastGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(),
1657 true, oFsm.PAdaptFsm.CommChan, meIPV4MCTableParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001658 if err != nil {
1659 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001660 logger.Errorw(ctx, "MulticastGemIWTPVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001661 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001662 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001663 return
1664 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001665 oFsm.pLastTxMeInstance = meIPV4MCTableInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001666 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia4b232302020-11-11 10:58:10 +03001667
1668 } else {
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301669 meParams = me.ParamData{
ozgecanetsia4b232302020-11-11 10:58:10 +03001670 EntityID: gemPortAttribs.gemPortID,
1671 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001672 me.GemInterworkingTerminationPoint_GemPortNetworkCtpConnectivityPointer: gemPortAttribs.gemPortID, //same as EntityID, see above
1673 me.GemInterworkingTerminationPoint_InterworkingOption: 5, //fixed model:: G.998 .1pMapper
1674 me.GemInterworkingTerminationPoint_ServiceProfilePointer: oFsm.mapperSP0ID,
1675 me.GemInterworkingTerminationPoint_InterworkingTerminationPointPointer: 0, //not used with .1PMapper Mac bridge
1676 me.GemInterworkingTerminationPoint_GalProfilePointer: cmn.GalEthernetEID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001677 },
1678 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001679 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001680 meInstance, err := oFsm.pOmciCC.SendCreateGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1681 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001682 if err != nil {
1683 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001684 logger.Errorw(ctx, "GEMIWTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001685 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001686 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001687 return
1688 }
ozgecanetsia4b232302020-11-11 10:58:10 +03001689 //accept also nil as (error) return value for writing to LastTx
1690 // - this avoids misinterpretation of new received OMCI messages
1691 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001692 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia4b232302020-11-11 10:58:10 +03001693 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001694 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001695 err := oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001696 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001697 logger.Errorw(ctx, "GemTP create failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001698 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001699 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001700 return
1701 }
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301702 logger.Infow(ctx, "Adding GemIWTP to the ONU DB ", log.Fields{"device-id": oFsm.deviceID, "GEMID": gemPortAttribs.gemPortID})
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301703 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemInterworkingTerminationPointClassID, gemPortAttribs.gemPortID, meParams.Attributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301704
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001705 } //for all GemPort's of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +00001706
1707 // if Config has been done for all GemPort instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001708 logger.Debugw(ctx, "GemIwTp create loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001709 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxGemiwsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001710}
1711
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001712func (oFsm *UniPonAniConfigFsm) performSettingPQs(ctx context.Context) {
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001713 //If upstream PQs were set before, then no need to set them again. Let state machine to proceed.
1714 if oFsm.tcontSetBefore {
1715 logger.Debugw(ctx, "No need to set PQs again.", log.Fields{
1716 "device-id": oFsm.deviceID, "tcont": oFsm.alloc0ID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001717 "uni-id": oFsm.pOnuUniPort.UniID,
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001718 "techProfile-id": oFsm.techProfileID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001719 go func(aPAFsm *cmn.AdapterFsm) {
1720 if aPAFsm != nil && aPAFsm.PFsm != nil {
1721 _ = aPAFsm.PFsm.Event(aniEvRxPrioqsResp)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001722 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001723 }(oFsm.PAdaptFsm)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001724 return
1725 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001726 const cu16StrictPrioWeight uint16 = 0xFFFF
1727 //find all upstream PrioQueues related to this T-Cont
1728 loQueueMap := ordered_map.NewOrderedMap()
1729 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001730 if gemPortAttribs.isMulticast {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001731 logger.Debugw(ctx, "UniPonAniConfigFsm Port is Multicast, ignoring PQs", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001732 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
1733 "prioString": gemPortAttribs.pbitString})
1734 continue
1735 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001736 if gemPortAttribs.qosPolicy == "WRR" {
Himani Chawla4d908332020-08-31 12:30:20 +05301737 if _, ok := loQueueMap.Get(gemPortAttribs.upQueueID); !ok {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001738 //key does not yet exist
1739 loQueueMap.Set(gemPortAttribs.upQueueID, uint16(gemPortAttribs.weight))
1740 }
1741 } else {
1742 loQueueMap.Set(gemPortAttribs.upQueueID, cu16StrictPrioWeight) //use invalid weight value to indicate SP
1743 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001744 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001745
Girish Gowdra09e5f212021-09-30 16:28:36 -07001746 trafficSchedPtrSetSupported := false
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001747 loOnu2g := oFsm.pOnuDB.GetMe(me.Onu2GClassID, cmn.Onu2gMeID)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001748 if loOnu2g == nil {
1749 logger.Errorw(ctx, "onu2g is nil, cannot read qos configuration flexibility parameter",
1750 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001751 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001752 return
1753 }
1754 returnVal := loOnu2g["QualityOfServiceQosConfigurationFlexibility"]
1755 if returnVal != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001756 if qosCfgFlexParam, err := oFsm.pOnuDB.GetUint16Attrib(returnVal); err == nil {
Girish Gowdra09e5f212021-09-30 16:28:36 -07001757 trafficSchedPtrSetSupported = qosCfgFlexParam&bitTrafficSchedulerPtrSetPermitted == bitTrafficSchedulerPtrSetPermitted
1758 logger.Debugw(ctx, "trafficSchedPtrSetSupported set",
1759 log.Fields{"qosCfgFlexParam": qosCfgFlexParam, "trafficSchedPtrSetSupported": trafficSchedPtrSetSupported})
1760 } else {
1761 logger.Errorw(ctx, "Cannot extract qos configuration flexibility parameter",
1762 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001763 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001764 return
1765 }
1766 } else {
1767 logger.Errorw(ctx, "Cannot read qos configuration flexibility parameter",
1768 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001769 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001770 return
1771 }
1772
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001773 //TODO: assumption here is that ONU data uses SP setting in the T-Cont and WRR in the TrafficScheduler
1774 // if that is not the case, the reverse case could be checked and reacted accordingly or if the
1775 // complete chain is not valid, then some error should be thrown and configuration can be aborted
1776 // or even be finished without correct SP/WRR setting
1777
1778 //TODO: search for the (WRR)trafficScheduler related to the T-Cont of this queue
1779 //By now assume fixed value 0x8000, which is the only announce BBSIM TrafficScheduler,
1780 // even though its T-Cont seems to be wrong ...
1781 loTrafficSchedulerEID := 0x8000
1782 //for all found queues
1783 iter := loQueueMap.IterFunc()
1784 for kv, ok := iter(); ok; kv, ok = iter() {
1785 queueIndex := (kv.Key).(uint16)
1786 meParams := me.ParamData{
1787 EntityID: queueIndex,
Himani Chawla4d908332020-08-31 12:30:20 +05301788 Attributes: make(me.AttributeValueMap),
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001789 }
Girish Gowdra09e5f212021-09-30 16:28:36 -07001790 if trafficSchedPtrSetSupported {
1791 if (kv.Value).(uint16) == cu16StrictPrioWeight {
1792 //StrictPrio indication
1793 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio", log.Fields{
1794 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1795 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001796 meParams.Attributes[me.PriorityQueue_TrafficSchedulerPointer] = 0 //ensure T-Cont defined StrictPrio scheduling
Girish Gowdra09e5f212021-09-30 16:28:36 -07001797 } else {
1798 //WRR indication
1799 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to WRR", log.Fields{
1800 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1801 "Weight": kv.Value,
1802 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001803 meParams.Attributes[me.PriorityQueue_TrafficSchedulerPointer] = loTrafficSchedulerEID //ensure assignment of the relevant trafficScheduler
1804 meParams.Attributes[me.PriorityQueue_Weight] = uint8(kv.Value.(uint16))
Girish Gowdra09e5f212021-09-30 16:28:36 -07001805 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001806 } else {
Girish Gowdra09e5f212021-09-30 16:28:36 -07001807 // setting Traffic Scheduler (TS) pointer is not supported unless we point to another TS that points to the same TCONT.
1808 // For now lets use TS that is hardwired in the ONU and just update the weight in case of WRR, which in fact is all we need at the moment.
1809 // The code could get unnecessarily convoluted if we provide the flexibility try to find and point to another TS that points to the same TCONT.
1810 if (kv.Value).(uint16) == cu16StrictPrioWeight { // SP case, nothing to be done. Proceed to the next queue
1811 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio, traffic sched ptr set unsupported", log.Fields{
1812 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1813 "device-id": oFsm.deviceID})
1814 continue
1815 }
1816 // WRR case, update weight.
1817 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to WRR, traffic sched ptr set unsupported", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001818 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1819 "Weight": kv.Value,
mpagenko01e726e2020-10-23 09:45:29 +00001820 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001821 meParams.Attributes[me.PriorityQueue_Weight] = uint8(kv.Value.(uint16))
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001822 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001823 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001824 meInstance, err := oFsm.pOmciCC.SendSetPrioQueueVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1825 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001826 if err != nil {
1827 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001828 logger.Errorw(ctx, "PrioQueueVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001829 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001830 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001831 return
1832 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001833 //accept also nil as (error) return value for writing to LastTx
1834 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001835 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001836 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001837
1838 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001839 err = oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001840 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001841 logger.Errorw(ctx, "PrioQueue set failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001842 log.Fields{"device-id": oFsm.deviceID, "QueueId": strconv.FormatInt(int64(queueIndex), 16)})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001843 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001844 return
1845 }
1846
1847 //TODO: In case of WRR setting of the GemPort/PrioQueue it might further be necessary to
1848 // write the assigned trafficScheduler with the requested Prio to be considered in the StrictPrio scheduling
1849 // of the (next upstream) assigned T-Cont, which is f(prioQueue[priority]) - in relation to other SP prioQueues
1850 // not yet done because of BBSIM TrafficScheduler issues (and not done in py code as well)
1851
1852 } //for all upstream prioQueues
mpagenko3dbcdd22020-07-22 07:38:45 +00001853
1854 // if Config has been done for all PrioQueue instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001855 logger.Debugw(ctx, "PrioQueue set loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001856 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxPrioqsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001857}
1858
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001859func (oFsm *UniPonAniConfigFsm) waitforOmciResponse(ctx context.Context) error {
mpagenko7d6bb022021-03-11 15:07:55 +00001860 oFsm.mutexIsAwaitingResponse.Lock()
mpagenkocf48e452021-04-23 09:23:00 +00001861 if oFsm.isCanceled {
1862 // FSM already canceled before entering wait
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001863 logger.Debugw(ctx, "UniPonAniConfigFsm wait-for-multi-entity-response aborted (on enter)", log.Fields{"for device-id": oFsm.deviceID})
mpagenkocf48e452021-04-23 09:23:00 +00001864 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001865 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenkocf48e452021-04-23 09:23:00 +00001866 }
mpagenko7d6bb022021-03-11 15:07:55 +00001867 oFsm.isAwaitingResponse = true
1868 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko3dbcdd22020-07-22 07:38:45 +00001869 select {
Himani Chawla4d908332020-08-31 12:30:20 +05301870 // maybe be also some outside cancel (but no context modeled for the moment ...)
mpagenko3dbcdd22020-07-22 07:38:45 +00001871 // case <-ctx.Done():
mpagenko01e726e2020-10-23 09:45:29 +00001872 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +00001873 case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
dbainbri4d3a0dc2020-12-02 00:33:42 +00001874 logger.Warnw(ctx, "UniPonAniConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001875 oFsm.mutexIsAwaitingResponse.Lock()
1876 oFsm.isAwaitingResponse = false
1877 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001878 oFsm.mutexPLastTxMeInstance.RLock()
1879 if oFsm.pLastTxMeInstance != nil {
1880 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureTimeout, oFsm.pLastTxMeInstance.GetClassID(),
1881 oFsm.pLastTxMeInstance.GetEntityID(), oFsm.pLastTxMeInstance.GetClassID().String(), 0)
1882 }
1883 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00001884 return fmt.Errorf("uniPonAniConfigFsm multi entity timeout %s", oFsm.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +00001885 case success := <-oFsm.omciMIdsResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +05301886 if success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001887 logger.Debugw(ctx, "UniPonAniConfigFsm multi entity response received", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001888 oFsm.mutexIsAwaitingResponse.Lock()
1889 oFsm.isAwaitingResponse = false
1890 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko3dbcdd22020-07-22 07:38:45 +00001891 return nil
1892 }
mpagenko7d6bb022021-03-11 15:07:55 +00001893 // waiting was aborted (probably on external request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001894 logger.Debugw(ctx, "UniPonAniConfigFsm wait-for-multi-entity-response aborted", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001895 oFsm.mutexIsAwaitingResponse.Lock()
1896 oFsm.isAwaitingResponse = false
1897 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001898 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenko3dbcdd22020-07-22 07:38:45 +00001899 }
1900}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001901
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001902func (oFsm *UniPonAniConfigFsm) setChanSet(flagValue bool) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001903 oFsm.mutexChanSet.Lock()
1904 oFsm.chanSet = flagValue
1905 oFsm.mutexChanSet.Unlock()
1906}
1907
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001908func (oFsm *UniPonAniConfigFsm) isChanSet() bool {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001909 oFsm.mutexChanSet.RLock()
1910 flagValue := oFsm.chanSet
1911 oFsm.mutexChanSet.RUnlock()
1912 return flagValue
1913}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001914
1915// PrepareForGarbageCollection - remove references to prepare for garbage collection
1916func (oFsm *UniPonAniConfigFsm) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301917 logger.Info(ctx, "prepare for garbage collection", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001918 oFsm.pDeviceHandler = nil
1919 oFsm.pOnuDeviceEntry = nil
1920 oFsm.pOmciCC = nil
1921}