blob: c58b18f271492a02856b6d744eff822a9ce46d08 [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"
balaji.nagarajanca025612025-06-23 16:16:06 +053045 aniEvPrepareConfig = "aniEvPrepareConfig"
mpagenko8b07c1b2020-11-26 10:36:31 +000046 aniEvStartConfig = "aniEvStartConfig"
47 aniEvRxDot1pmapCResp = "aniEvRxDot1pmapCResp"
48 aniEvRxMbpcdResp = "aniEvRxMbpcdResp"
49 aniEvRxTcontsResp = "aniEvRxTcontsResp"
50 aniEvRxGemntcpsResp = "aniEvRxGemntcpsResp"
51 aniEvRxGemiwsResp = "aniEvRxGemiwsResp"
52 aniEvRxPrioqsResp = "aniEvRxPrioqsResp"
53 aniEvRxDot1pmapSResp = "aniEvRxDot1pmapSResp"
54 aniEvRemGemiw = "aniEvRemGemiw"
Girish Gowdra26a40922021-01-29 17:14:34 -080055 aniEvWaitFlowRem = "aniEvWaitFlowRem"
56 aniEvFlowRemDone = "aniEvFlowRemDone"
mpagenko8b07c1b2020-11-26 10:36:31 +000057 aniEvRxRemGemiwResp = "aniEvRxRemGemiwResp"
58 aniEvRxRemGemntpResp = "aniEvRxRemGemntpResp"
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +030059 aniEvRxRemTdResp = "aniEvRxRemTdResp"
mpagenko8b07c1b2020-11-26 10:36:31 +000060 aniEvRemTcontPath = "aniEvRemTcontPath"
61 aniEvRxResetTcontResp = "aniEvRxResetTcontResp"
62 aniEvRxRem1pMapperResp = "aniEvRxRem1pMapperResp"
63 aniEvRxRemAniBPCDResp = "aniEvRxRemAniBPCDResp"
64 aniEvTimeoutSimple = "aniEvTimeoutSimple"
65 aniEvTimeoutMids = "aniEvTimeoutMids"
66 aniEvReset = "aniEvReset"
67 aniEvRestart = "aniEvRestart"
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +000068 aniEvSkipOmciConfig = "aniEvSkipOmciConfig"
Mahir Gunyel9545be22021-07-04 15:53:16 -070069 aniEvRemGemDone = "aniEvRemGemDone"
mpagenko1cc3cb42020-07-27 15:24:38 +000070)
71const (
72 // states of config PON ANI port FSM
73 aniStDisabled = "aniStDisabled"
74 aniStStarting = "aniStStarting"
balaji.nagarajanca025612025-06-23 16:16:06 +053075 aniStPrepareConfig = "aniStPrepareConfig"
mpagenko1cc3cb42020-07-27 15:24:38 +000076 aniStCreatingDot1PMapper = "aniStCreatingDot1PMapper"
77 aniStCreatingMBPCD = "aniStCreatingMBPCD"
78 aniStSettingTconts = "aniStSettingTconts"
79 aniStCreatingGemNCTPs = "aniStCreatingGemNCTPs"
80 aniStCreatingGemIWs = "aniStCreatingGemIWs"
81 aniStSettingPQs = "aniStSettingPQs"
82 aniStSettingDot1PMapper = "aniStSettingDot1PMapper"
83 aniStConfigDone = "aniStConfigDone"
mpagenko8b07c1b2020-11-26 10:36:31 +000084 aniStRemovingGemIW = "aniStRemovingGemIW"
Girish Gowdra26a40922021-01-29 17:14:34 -080085 aniStWaitingFlowRem = "aniStWaitingFlowRem"
mpagenko8b07c1b2020-11-26 10:36:31 +000086 aniStRemovingGemNCTP = "aniStRemovingGemNCTP"
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +030087 aniStRemovingTD = "aniStRemovingTD"
mpagenko8b07c1b2020-11-26 10:36:31 +000088 aniStResetTcont = "aniStResetTcont"
89 aniStRemDot1PMapper = "aniStRemDot1PMapper"
90 aniStRemAniBPCD = "aniStRemAniBPCD"
91 aniStRemoveDone = "aniStRemoveDone"
mpagenko1cc3cb42020-07-27 15:24:38 +000092 aniStResetting = "aniStResetting"
93)
94
Girish Gowdra09e5f212021-09-30 16:28:36 -070095const (
96 bitTrafficSchedulerPtrSetPermitted = 0x0002 // Refer section 9.1.2 ONU-2G, table for "Quality of service (QoS) configuration flexibility" IE
97)
Holger Hildebrandtc408f492022-07-14 08:39:24 +000098const cTechProfileTypeXgsPon = "XGS-PON"
99
100// definitions as per G.988
101// Gem Encryption Key Ring
102const (
103 // No encryption. The downstream key index is ignored, and upstream traffic is transmitted with key index 0.
104 GemEncryptKeyRingNoEncrypt = 0
105 // Unicast payload encryption in both directions. Keys are generated by the ONU and transmitted to the OLT via the PLOAM channel.
106 GemEncryptKeyRingUnicastPayload = 1
107 // Broadcast (multicast) encryption. Keys are generated by the OLT and distributed via the OMCI.
108 GemEncryptKeyRingBroadcastMulticast = 2
109 // Unicast encryption, downstream only. Keys are generated by the ONU and transmitted to the OLT via the PLOAM channel.
110 GemEncryptKeyRingUnicastDownstreamOnly = 3
111)
Girish Gowdra09e5f212021-09-30 16:28:36 -0700112
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000113// CAniFsmIdleState - TODO: add comment
114const CAniFsmIdleState = aniStConfigDone
115
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000116type ponAniGemPortAttribs struct {
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530117 qosPolicy string
118 pbitString string
119 staticACL string
120 dynamicACL string
ozgecanetsia4b232302020-11-11 10:58:10 +0300121 gemPortID uint16
122 upQueueID uint16
123 downQueueID uint16
ozgecanetsia4b232302020-11-11 10:58:10 +0300124 multicastGemID uint16
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530125 direction uint8
126 weight uint8
127 isMulticast bool
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000128}
129
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530130// 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 +0000131type UniPonAniConfigFsm struct {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000132 pDeviceHandler cmn.IdeviceHandler
133 pOnuDeviceEntry cmn.IonuDeviceEntry
134 pOmciCC *cmn.OmciCC
135 pOnuUniPort *cmn.OnuUniPort
136 pUniTechProf *OnuUniTechProf
137 pOnuDB *devdb.OnuDeviceDB
Himani Chawla4d908332020-08-31 12:30:20 +0530138 omciMIdsResponseReceived chan bool //separate channel needed for checking multiInstance OMCI message responses
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000139 PAdaptFsm *cmn.AdapterFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000140 chSuccess chan<- uint8
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530141 pLastTxMeInstance *me.ManagedEntity
142 waitFlowDeleteChannel chan bool
143 deviceID string
144 techProfileType string
145 gemPortAttribsSlice []ponAniGemPortAttribs
146 requestEvent cmn.OnuDeviceEvent
147 mutexIsAwaitingResponse sync.RWMutex
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000148 mutexChanSet sync.RWMutex
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530149 mutexPLastTxMeInstance sync.RWMutex
mpagenko3dbcdd22020-07-22 07:38:45 +0000150 mapperSP0ID uint16
151 macBPCD0ID uint16
152 tcont0ID uint16
153 alloc0ID uint16
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530154 uniTpKey uniTP
155 techProfileID uint8
156 isCanceled bool
157 isAwaitingResponse bool
158 procStep uint8
159 chanSet bool
mpagenko8b07c1b2020-11-26 10:36:31 +0000160 requestEventOffset uint8 //used to indicate ConfigDone or Removed using successor (enum)
mpagenkobb47bc22021-04-20 13:29:09 +0000161 isWaitingForFlowDelete bool
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700162 tcontSetBefore bool
mpagenko3dbcdd22020-07-22 07:38:45 +0000163}
164
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530165// 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 +0000166func NewUniPonAniConfigFsm(ctx context.Context, apDevOmciCC *cmn.OmciCC, apUniPort *cmn.OnuUniPort, apUniTechProf *OnuUniTechProf,
Holger Hildebrandtc408f492022-07-14 08:39:24 +0000167 apOnuDB *devdb.OnuDeviceDB, aTechProfileID uint8, aTechProfileType string, aRequestEvent cmn.OnuDeviceEvent, aName string,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000168 apDeviceHandler cmn.IdeviceHandler, apOnuDeviceEntry cmn.IonuDeviceEntry, aCommChannel chan cmn.Message) *UniPonAniConfigFsm {
169 instFsm := &UniPonAniConfigFsm{
170 pDeviceHandler: apDeviceHandler,
171 pOnuDeviceEntry: apOnuDeviceEntry,
172 deviceID: apDeviceHandler.GetDeviceID(),
173 pOmciCC: apDevOmciCC,
174 pOnuUniPort: apUniPort,
175 pUniTechProf: apUniTechProf,
176 pOnuDB: apOnuDB,
177 techProfileID: aTechProfileID,
Holger Hildebrandtc408f492022-07-14 08:39:24 +0000178 techProfileType: aTechProfileType,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000179 requestEvent: aRequestEvent,
180 chanSet: false,
181 tcontSetBefore: false,
mpagenko3dbcdd22020-07-22 07:38:45 +0000182 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000183 instFsm.uniTpKey = uniTP{uniID: apUniPort.UniID, tpID: aTechProfileID}
mpagenkobb47bc22021-04-20 13:29:09 +0000184 instFsm.waitFlowDeleteChannel = make(chan bool)
mpagenko8b07c1b2020-11-26 10:36:31 +0000185
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000186 instFsm.PAdaptFsm = cmn.NewAdapterFsm(aName, instFsm.deviceID, aCommChannel)
187 if instFsm.PAdaptFsm == nil {
188 logger.Errorw(ctx, "UniPonAniConfigFsm's cmn.AdapterFsm could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000189 "device-id": instFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000190 return nil
191 }
192
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000193 instFsm.PAdaptFsm.PFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000194 aniStDisabled,
mpagenko3dbcdd22020-07-22 07:38:45 +0000195 fsm.Events{
196
mpagenko1cc3cb42020-07-27 15:24:38 +0000197 {Name: aniEvStart, Src: []string{aniStDisabled}, Dst: aniStStarting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000198
199 //Note: .1p-Mapper and MBPCD might also have multi instances (per T-Cont) - by now only one 1 T-Cont considered!
balaji.nagarajanca025612025-06-23 16:16:06 +0530200 {Name: aniEvPrepareConfig, Src: []string{aniStStarting}, Dst: aniStPrepareConfig},
201 {Name: aniEvStartConfig, Src: []string{aniStPrepareConfig}, Dst: aniStCreatingDot1PMapper},
mpagenkodff5dda2020-08-28 11:52:01 +0000202 {Name: aniEvRxDot1pmapCResp, Src: []string{aniStCreatingDot1PMapper}, Dst: aniStCreatingMBPCD},
mpagenko1cc3cb42020-07-27 15:24:38 +0000203 {Name: aniEvRxMbpcdResp, Src: []string{aniStCreatingMBPCD}, Dst: aniStSettingTconts},
204 {Name: aniEvRxTcontsResp, Src: []string{aniStSettingTconts}, Dst: aniStCreatingGemNCTPs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000205 // the creatingGemNCTPs state is used for multi ME config if required for all configured/available GemPorts
mpagenko1cc3cb42020-07-27 15:24:38 +0000206 {Name: aniEvRxGemntcpsResp, Src: []string{aniStCreatingGemNCTPs}, Dst: aniStCreatingGemIWs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000207 // the creatingGemIWs state is used for multi ME config if required for all configured/available GemPorts
mpagenko1cc3cb42020-07-27 15:24:38 +0000208 {Name: aniEvRxGemiwsResp, Src: []string{aniStCreatingGemIWs}, Dst: aniStSettingPQs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000209 // the settingPQs state is used for multi ME config if required for all configured/available upstream PriorityQueues
mpagenko1cc3cb42020-07-27 15:24:38 +0000210 {Name: aniEvRxPrioqsResp, Src: []string{aniStSettingPQs}, Dst: aniStSettingDot1PMapper},
mpagenkodff5dda2020-08-28 11:52:01 +0000211 {Name: aniEvRxDot1pmapSResp, Src: []string{aniStSettingDot1PMapper}, Dst: aniStConfigDone},
mpagenko3dbcdd22020-07-22 07:38:45 +0000212
mpagenko8b07c1b2020-11-26 10:36:31 +0000213 //for removing Gem related resources
214 {Name: aniEvRemGemiw, Src: []string{aniStConfigDone}, Dst: aniStRemovingGemIW},
Girish Gowdra26a40922021-01-29 17:14:34 -0800215 {Name: aniEvWaitFlowRem, Src: []string{aniStRemovingGemIW}, Dst: aniStWaitingFlowRem},
216 {Name: aniEvFlowRemDone, Src: []string{aniStWaitingFlowRem}, Dst: aniStRemovingGemIW},
mpagenko8b07c1b2020-11-26 10:36:31 +0000217 {Name: aniEvRxRemGemiwResp, Src: []string{aniStRemovingGemIW}, Dst: aniStRemovingGemNCTP},
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300218 {Name: aniEvRxRemGemntpResp, Src: []string{aniStRemovingGemNCTP}, Dst: aniStRemovingTD},
Mahir Gunyel9545be22021-07-04 15:53:16 -0700219 {Name: aniEvRxRemTdResp, Src: []string{aniStRemovingTD}, Dst: aniStRemDot1PMapper},
220 {Name: aniEvRemGemDone, Src: []string{aniStRemDot1PMapper}, Dst: aniStConfigDone},
221 {Name: aniEvRxRem1pMapperResp, Src: []string{aniStRemDot1PMapper}, Dst: aniStRemAniBPCD},
222 {Name: aniEvRxRemAniBPCDResp, Src: []string{aniStRemAniBPCD}, Dst: aniStRemoveDone},
mpagenko8b07c1b2020-11-26 10:36:31 +0000223
224 //for removing TCONT related resources
225 {Name: aniEvRemTcontPath, Src: []string{aniStConfigDone}, Dst: aniStResetTcont},
Mahir Gunyel9545be22021-07-04 15:53:16 -0700226 {Name: aniEvRxResetTcontResp, Src: []string{aniStResetTcont}, Dst: aniStConfigDone},
mpagenko8b07c1b2020-11-26 10:36:31 +0000227
228 {Name: aniEvTimeoutSimple, Src: []string{aniStCreatingDot1PMapper, aniStCreatingMBPCD, aniStSettingTconts, aniStSettingDot1PMapper,
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300229 aniStRemovingGemIW, aniStRemovingGemNCTP, aniStRemovingTD,
mpagenko8b07c1b2020-11-26 10:36:31 +0000230 aniStResetTcont, aniStRemDot1PMapper, aniStRemAniBPCD, aniStRemoveDone}, Dst: aniStStarting},
mpagenko1cc3cb42020-07-27 15:24:38 +0000231 {Name: aniEvTimeoutMids, Src: []string{
232 aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs}, Dst: aniStStarting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000233
mpagenko1cc3cb42020-07-27 15:24:38 +0000234 // exceptional treatment for all states except aniStResetting
balaji.nagarajanca025612025-06-23 16:16:06 +0530235 {Name: aniEvReset, Src: []string{aniStStarting, aniStPrepareConfig, aniStCreatingDot1PMapper, aniStCreatingMBPCD,
mpagenko1cc3cb42020-07-27 15:24:38 +0000236 aniStSettingTconts, aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs, aniStSettingDot1PMapper,
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300237 aniStConfigDone, aniStRemovingGemIW, aniStWaitingFlowRem, aniStRemovingGemNCTP, aniStRemovingTD,
mpagenko8b07c1b2020-11-26 10:36:31 +0000238 aniStResetTcont, aniStRemDot1PMapper, aniStRemAniBPCD, aniStRemoveDone}, Dst: aniStResetting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000239 // the only way to get to resource-cleared disabled state again is via "resseting"
mpagenko1cc3cb42020-07-27 15:24:38 +0000240 {Name: aniEvRestart, Src: []string{aniStResetting}, Dst: aniStDisabled},
balaji.nagarajanca025612025-06-23 16:16:06 +0530241 {Name: aniEvSkipOmciConfig, Src: []string{aniStStarting, aniStPrepareConfig}, Dst: aniStConfigDone},
mpagenko3dbcdd22020-07-22 07:38:45 +0000242 },
243
244 fsm.Callbacks{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000245 "enter_state": func(e *fsm.Event) { instFsm.PAdaptFsm.LogFsmStateChange(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000246 ("enter_" + aniStStarting): func(e *fsm.Event) { instFsm.enterConfigStartingState(ctx, e) },
balaji.nagarajanca025612025-06-23 16:16:06 +0530247 ("enter_" + aniStPrepareConfig): func(e *fsm.Event) { instFsm.prepareAndEnterConfigState(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000248 ("enter_" + aniStCreatingDot1PMapper): func(e *fsm.Event) { instFsm.enterCreatingDot1PMapper(ctx, e) },
249 ("enter_" + aniStCreatingMBPCD): func(e *fsm.Event) { instFsm.enterCreatingMBPCD(ctx, e) },
250 ("enter_" + aniStSettingTconts): func(e *fsm.Event) { instFsm.enterSettingTconts(ctx, e) },
251 ("enter_" + aniStCreatingGemNCTPs): func(e *fsm.Event) { instFsm.enterCreatingGemNCTPs(ctx, e) },
252 ("enter_" + aniStCreatingGemIWs): func(e *fsm.Event) { instFsm.enterCreatingGemIWs(ctx, e) },
253 ("enter_" + aniStSettingPQs): func(e *fsm.Event) { instFsm.enterSettingPQs(ctx, e) },
254 ("enter_" + aniStSettingDot1PMapper): func(e *fsm.Event) { instFsm.enterSettingDot1PMapper(ctx, e) },
255 ("enter_" + aniStConfigDone): func(e *fsm.Event) { instFsm.enterAniConfigDone(ctx, e) },
256 ("enter_" + aniStRemovingGemIW): func(e *fsm.Event) { instFsm.enterRemovingGemIW(ctx, e) },
mpagenkobb47bc22021-04-20 13:29:09 +0000257 ("enter_" + aniStWaitingFlowRem): func(e *fsm.Event) { instFsm.enterWaitingFlowRem(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000258 ("enter_" + aniStRemovingGemNCTP): func(e *fsm.Event) { instFsm.enterRemovingGemNCTP(ctx, e) },
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300259 ("enter_" + aniStRemovingTD): func(e *fsm.Event) { instFsm.enterRemovingTD(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000260 ("enter_" + aniStResetTcont): func(e *fsm.Event) { instFsm.enterResettingTcont(ctx, e) },
261 ("enter_" + aniStRemDot1PMapper): func(e *fsm.Event) { instFsm.enterRemoving1pMapper(ctx, e) },
262 ("enter_" + aniStRemAniBPCD): func(e *fsm.Event) { instFsm.enterRemovingAniBPCD(ctx, e) },
263 ("enter_" + aniStRemoveDone): func(e *fsm.Event) { instFsm.enterAniRemoveDone(ctx, e) },
264 ("enter_" + aniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(ctx, e) },
265 ("enter_" + aniStDisabled): func(e *fsm.Event) { instFsm.enterDisabledState(ctx, e) },
mpagenko3dbcdd22020-07-22 07:38:45 +0000266 },
267 )
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000268 if instFsm.PAdaptFsm.PFsm == nil {
269 logger.Errorw(ctx, "UniPonAniConfigFsm's Base FSM could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000270 "device-id": instFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000271 return nil
272 }
273
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000274 logger.Debugw(ctx, "UniPonAniConfigFsm created", log.Fields{"device-id": instFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000275 return instFsm
276}
277
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530278// setFsmCompleteChannel sets the requested channel and channel result for transfer on success
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000279func (oFsm *UniPonAniConfigFsm) setFsmCompleteChannel(aChSuccess chan<- uint8, aProcStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000280 oFsm.chSuccess = aChSuccess
281 oFsm.procStep = aProcStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000282 oFsm.setChanSet(true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000283}
284
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530285// CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000286func (oFsm *UniPonAniConfigFsm) CancelProcessing(ctx context.Context) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530287 logger.Info(ctx, "CancelProcessing entered", log.Fields{"device-id": oFsm.deviceID})
mpagenko73143992021-04-09 15:17:10 +0000288 //early indication about started reset processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000289 oFsm.pUniTechProf.setProfileResetting(ctx, oFsm.pOnuUniPort.UniID, oFsm.techProfileID, true)
mpagenko7d6bb022021-03-11 15:07:55 +0000290 //mutex protection is required for possible concurrent access to FSM members
mpagenkocf48e452021-04-23 09:23:00 +0000291 oFsm.mutexIsAwaitingResponse.Lock()
292 oFsm.isCanceled = true
mpagenko7d6bb022021-03-11 15:07:55 +0000293 if oFsm.isAwaitingResponse {
mpagenkocf48e452021-04-23 09:23:00 +0000294 //attention: for an unbuffered channel the sender is blocked until the value is received (processed)!
295 // accordingly the mutex must be released before sending to channel here (mutex acquired in receiver)
296 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko7d6bb022021-03-11 15:07:55 +0000297 //use channel to indicate that the response waiting shall be aborted
298 oFsm.omciMIdsResponseReceived <- false
mpagenkocf48e452021-04-23 09:23:00 +0000299 } else {
300 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko7d6bb022021-03-11 15:07:55 +0000301 }
mpagenkocf48e452021-04-23 09:23:00 +0000302
303 oFsm.mutexIsAwaitingResponse.Lock()
mpagenkobb47bc22021-04-20 13:29:09 +0000304 if oFsm.isWaitingForFlowDelete {
mpagenkocf48e452021-04-23 09:23:00 +0000305 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenkobb47bc22021-04-20 13:29:09 +0000306 //use channel to indicate that the response waiting shall be aborted
307 oFsm.waitFlowDeleteChannel <- false
mpagenkocf48e452021-04-23 09:23:00 +0000308 } else {
309 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenkobb47bc22021-04-20 13:29:09 +0000310 }
mpagenkocf48e452021-04-23 09:23:00 +0000311
mpagenko7d6bb022021-03-11 15:07:55 +0000312 // 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 +0000313 PAdaptFsm := oFsm.PAdaptFsm
314 if PAdaptFsm != nil {
mpagenko7d6bb022021-03-11 15:07:55 +0000315 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
balaji.nagarajanca025612025-06-23 16:16:06 +0530316 if PAdaptFsm.PFsm != nil {
317 _ = PAdaptFsm.PFsm.Event(aniEvReset)
318 }
mpagenko7d6bb022021-03-11 15:07:55 +0000319 }
mpagenko73143992021-04-09 15:17:10 +0000320
mpagenko45cc6a32021-07-23 10:06:57 +0000321 // possible access conflicts on internal data by next needed data clearance
322 // are avoided by using mutexTPState also from within clearAniSideConfig
323 // do not try to lock TpProcMutex here as done in previous code version
324 // as it may result in deadlock situations (as observed at soft-reboot handling where
325 // TpProcMutex is already locked by some ongoing TechProfile config/removal processing
mpagenko73143992021-04-09 15:17:10 +0000326 //remove all TechProf related internal data to allow for new configuration
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000327 oFsm.pUniTechProf.clearAniSideConfig(ctx, oFsm.pOnuUniPort.UniID, oFsm.techProfileID)
mpagenko7d6bb022021-03-11 15:07:55 +0000328}
329
balaji.nagarajanca025612025-06-23 16:16:06 +0530330//nolint:gocyclo
331func (oFsm *UniPonAniConfigFsm) prepareAndEnterConfigState(ctx context.Context, _ *fsm.Event) {
332 logger.Info(ctx, "UniPonAniConfigFsm prepareAndEnterConfigState start", log.Fields{
333 "device-id": oFsm.deviceID})
334 aPAFsm := oFsm.PAdaptFsm
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000335 if aPAFsm != nil && aPAFsm.PFsm != nil {
Mahir Gunyel6781f962021-05-16 23:30:08 -0700336 var err error
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000337 oFsm.mapperSP0ID, err = cmn.GenerateIeeMaperServiceProfileEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.techProfileID))
Mahir Gunyel6781f962021-05-16 23:30:08 -0700338 if err != nil {
339 logger.Errorw(ctx, "error generating maper id", log.Fields{"device-id": oFsm.deviceID,
340 "techProfileID": oFsm.techProfileID, "error": err})
341 return
342 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000343 oFsm.macBPCD0ID, err = cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.techProfileID))
Mahir Gunyel6781f962021-05-16 23:30:08 -0700344 if err != nil {
345 logger.Errorw(ctx, "error generating mbpcd id", log.Fields{"device-id": oFsm.deviceID,
346 "techProfileID": oFsm.techProfileID, "error": err})
347 return
348 }
349 logger.Debugw(ctx, "generated ids for ani config", log.Fields{"mapperSP0ID": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
350 "macBPCD0ID": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16), "device-id": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000351 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "techProfileID": oFsm.techProfileID})
352 if oFsm.pOnuDeviceEntry == nil {
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700353 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": oFsm.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800354 return
Himani Chawla26e555c2020-08-31 12:30:20 +0530355 }
bseenivaeba8eb12024-12-13 11:54:28 +0530356 // Access critical state with lock
357 oFsm.pUniTechProf.mutexTPState.RLock()
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +0530358 // Set T-Cont in device irrespective of whether it is stored in onu-adapter or not
359 tcontInstID, _, err := oFsm.pOnuDeviceEntry.AllocateFreeTcont(ctx, oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700360 if err != nil {
361 logger.Errorw(ctx, "No TCont instances found", log.Fields{"device-id": oFsm.deviceID, "err": err})
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700362 //reset the state machine to enable usage on subsequent requests
bseenivaeba8eb12024-12-13 11:54:28 +0530363 oFsm.pUniTechProf.mutexTPState.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000364 _ = aPAFsm.PFsm.Event(aniEvReset)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700365 return
366 }
367 oFsm.tcont0ID = tcontInstID
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700368 logger.Debugw(ctx, "used-tcont-instance-id", log.Fields{"tcont-inst-id": oFsm.tcont0ID,
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +0530369 "alloc-id": oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID,
370 "device-id": oFsm.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800371
mpagenko8b07c1b2020-11-26 10:36:31 +0000372 oFsm.alloc0ID = oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID
373 mapGemPortParams := oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].mapGemPortParams
mpagenko3ce9fa02021-07-28 13:26:54 +0000374 oFsm.pUniTechProf.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800375
Himani Chawla26e555c2020-08-31 12:30:20 +0530376 //for all TechProfile set GemIndices
Girish Gowdra041dcb32020-11-16 16:54:30 -0800377 for _, gemEntry := range mapGemPortParams {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300378 loGemPortAttribs := ponAniGemPortAttribs{}
379
Himani Chawla26e555c2020-08-31 12:30:20 +0530380 //collect all GemConfigData in a separate Fsm related slice (needed also to avoid mix-up with unsorted mapPonAniConfig)
381
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000382 if queueInstKeys := oFsm.pOnuDB.GetSortedInstKeys(ctx, me.PriorityQueueClassID); len(queueInstKeys) > 0 {
Himani Chawla26e555c2020-08-31 12:30:20 +0530383
384 loGemPortAttribs.gemPortID = gemEntry.gemPortID
385 // MibDb usage: upstream PrioQueue.RelatedPort = xxxxyyyy with xxxx=TCont.Entity(incl. slot) and yyyy=prio
386 // i.e.: search PrioQueue list with xxxx=actual T-Cont.Entity,
387 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == yyyy (expect 0..7)
388 usQrelPortMask := uint32((((uint32)(oFsm.tcont0ID)) << 16) + uint32(gemEntry.prioQueueIndex))
389
390 // MibDb usage: downstream PrioQueue.RelatedPort = xxyyzzzz with xx=slot, yy=UniPort and zzzz=prio
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000391 // i.e.: search PrioQueue list with yy=actual pOnuUniPort.UniID,
Himani Chawla26e555c2020-08-31 12:30:20 +0530392 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == zzzz (expect 0..7)
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +0000393 // Note: As we do not maintain any slot numbering, slot number will be excluded from search pattern.
Himani Chawla26e555c2020-08-31 12:30:20 +0530394 // Furthermore OMCI Onu port-Id is expected to start with 1 (not 0).
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000395 dsQrelPortMask := uint32((((uint32)(oFsm.pOnuUniPort.UniID + 1)) << 16) + uint32(gemEntry.prioQueueIndex))
Himani Chawla26e555c2020-08-31 12:30:20 +0530396
397 usQueueFound := false
398 dsQueueFound := false
399 for _, mgmtEntityID := range queueInstKeys {
400 if meAttributes := oFsm.pOnuDB.GetMe(me.PriorityQueueClassID, mgmtEntityID); meAttributes != nil {
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000401 returnVal := meAttributes[me.PriorityQueue_RelatedPort]
Himani Chawla26e555c2020-08-31 12:30:20 +0530402 if returnVal != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000403 if relatedPort, err := oFsm.pOnuDB.GetUint32Attrib(returnVal); err == nil {
Himani Chawla26e555c2020-08-31 12:30:20 +0530404 if relatedPort == usQrelPortMask {
405 loGemPortAttribs.upQueueID = mgmtEntityID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000406 logger.Debugw(ctx, "UpQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
mpagenko01e726e2020-10-23 09:45:29 +0000407 "upQueueID": strconv.FormatInt(int64(loGemPortAttribs.upQueueID), 16), "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530408 usQueueFound = true
409 } else if (relatedPort&0xFFFFFF) == dsQrelPortMask && mgmtEntityID < 0x8000 {
410 loGemPortAttribs.downQueueID = mgmtEntityID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000411 logger.Debugw(ctx, "DownQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
mpagenko01e726e2020-10-23 09:45:29 +0000412 "downQueueID": strconv.FormatInt(int64(loGemPortAttribs.downQueueID), 16), "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530413 dsQueueFound = true
414 }
415 if usQueueFound && dsQueueFound {
416 break
417 }
418 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000419 logger.Warnw(ctx, "Could not convert attribute value", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530420 }
421 } else {
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000422 logger.Warnw(ctx, "PrioQueue.RelatedPort not found in meAttributes:", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530423 }
424 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000425 logger.Warnw(ctx, "No attributes available in DB:", log.Fields{"meClassID": me.PriorityQueueClassID,
mpagenko01e726e2020-10-23 09:45:29 +0000426 "mgmtEntityID": mgmtEntityID, "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530427 }
428 }
429 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000430 logger.Warnw(ctx, "No PriorityQueue instances found", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530431 }
432 loGemPortAttribs.direction = gemEntry.direction
433 loGemPortAttribs.qosPolicy = gemEntry.queueSchedPolicy
434 loGemPortAttribs.weight = gemEntry.queueWeight
435 loGemPortAttribs.pbitString = gemEntry.pbitString
ozgecanetsia82b91a62021-05-21 18:54:49 +0300436
ozgecanetsia4b232302020-11-11 10:58:10 +0300437 if gemEntry.isMulticast {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300438 //TODO this might effectively ignore the for loop starting at line 316
439 loGemPortAttribs.gemPortID = gemEntry.multicastGemPortID
ozgecanetsia4b232302020-11-11 10:58:10 +0300440 loGemPortAttribs.isMulticast = true
441 loGemPortAttribs.multicastGemID = gemEntry.multicastGemPortID
442 loGemPortAttribs.staticACL = gemEntry.staticACL
443 loGemPortAttribs.dynamicACL = gemEntry.dynamicACL
Himani Chawla26e555c2020-08-31 12:30:20 +0530444
dbainbri4d3a0dc2020-12-02 00:33:42 +0000445 logger.Debugw(ctx, "Multicast GemPort attributes:", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300446 "gemPortID": loGemPortAttribs.gemPortID,
447 "isMulticast": loGemPortAttribs.isMulticast,
448 "multicastGemID": loGemPortAttribs.multicastGemID,
449 "staticACL": loGemPortAttribs.staticACL,
450 "dynamicACL": loGemPortAttribs.dynamicACL,
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000451 "device-id": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300452 })
453
454 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000455 logger.Debugw(ctx, "Upstream GemPort attributes:", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300456 "gemPortID": loGemPortAttribs.gemPortID,
457 "upQueueID": loGemPortAttribs.upQueueID,
458 "downQueueID": loGemPortAttribs.downQueueID,
459 "pbitString": loGemPortAttribs.pbitString,
460 "prioQueueIndex": gemEntry.prioQueueIndex,
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000461 "device-id": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300462 })
463 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530464
465 oFsm.gemPortAttribsSlice = append(oFsm.gemPortAttribsSlice, loGemPortAttribs)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530466 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
467 meParams := me.ParamData{
468 EntityID: loGemPortAttribs.gemPortID,
469 Attributes: me.AttributeValueMap{
470 me.GemPortNetworkCtp_PortId: loGemPortAttribs.gemPortID,
471 me.GemPortNetworkCtp_TContPointer: oFsm.tcont0ID,
472 me.GemPortNetworkCtp_Direction: loGemPortAttribs.direction,
473 me.GemPortNetworkCtp_TrafficManagementPointerForUpstream: loGemPortAttribs.upQueueID,
474 me.GemPortNetworkCtp_PriorityQueuePointerForDownStream: loGemPortAttribs.downQueueID,
475 },
476 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530477 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpClassID, loGemPortAttribs.gemPortID, meParams.Attributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530478 var meAttributes me.AttributeValueMap //dummy , anyways we are not going to use the values.
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530479 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID, loGemPortAttribs.gemPortID, meAttributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530480
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530481 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemInterworkingTerminationPointClassID, loGemPortAttribs.gemPortID, meAttributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530482
483 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530484 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000485 if !oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
balaji.nagarajanca025612025-06-23 16:16:06 +0530486 //let the state machine run forward from here directly
487 if oFsm.PAdaptFsm != nil {
488 go func(aPAFsm *cmn.AdapterFsm) {
489 if aPAFsm != nil && aPAFsm.PFsm != nil {
490 _ = aPAFsm.PFsm.Event(aniEvStartConfig)
491 }
492 }(oFsm.PAdaptFsm)
493
494 }
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000495 } else {
496 logger.Debugw(ctx, "reconciling - skip omci-config of ANI side ", log.Fields{"device-id": oFsm.deviceID})
balaji.nagarajanca025612025-06-23 16:16:06 +0530497 //let the state machine run forward from here directly
498 if oFsm.PAdaptFsm != nil {
499 go func(aPAFsm *cmn.AdapterFsm) {
500 if aPAFsm != nil && aPAFsm.PFsm != nil {
501 _ = aPAFsm.PFsm.Event(aniEvSkipOmciConfig)
502 }
503 }(oFsm.PAdaptFsm)
504
505 }
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000506 }
balaji.nagarajanca025612025-06-23 16:16:06 +0530507 logger.Info(ctx, "UniPonAniConfigFsm prepareAndEnterConfigState end", log.Fields{
508 "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530509 }
510}
511
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530512//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000513func (oFsm *UniPonAniConfigFsm) enterConfigStartingState(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530514 logger.Info(ctx, "UniPonAniConfigFsm start", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000515 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000516 // in case the used channel is not yet defined (can be re-used after restarts)
517 if oFsm.omciMIdsResponseReceived == nil {
518 oFsm.omciMIdsResponseReceived = make(chan bool)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000519 logger.Debug(ctx, "UniPonAniConfigFsm - OMCI multiInstance RxChannel defined")
mpagenko3dbcdd22020-07-22 07:38:45 +0000520 } else {
521 // as we may 're-use' this instance of FSM and the connected channel
522 // make sure there is no 'lingering' request in the already existing channel:
523 // (simple loop sufficient as we are the only receiver)
524 for len(oFsm.omciMIdsResponseReceived) > 0 {
525 <-oFsm.omciMIdsResponseReceived
526 }
527 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000528 //ensure internal slices are empty (which might be set from previous run) - release memory
529 oFsm.gemPortAttribsSlice = nil
mpagenkocf48e452021-04-23 09:23:00 +0000530 oFsm.mutexIsAwaitingResponse.Lock()
531 //reset the canceled state possibly existing from previous reset
532 oFsm.isCanceled = false
533 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000534
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000535 // start go routine for processing of ANI config messages
dbainbri4d3a0dc2020-12-02 00:33:42 +0000536 go oFsm.processOmciAniMessages(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000537
538 //let the state machine run forward from here directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000539 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000540 if pConfigAniStateAFsm != nil {
541 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
balaji.nagarajanca025612025-06-23 16:16:06 +0530542 go func(aPAFsm *cmn.AdapterFsm) {
543 if aPAFsm != nil && aPAFsm.PFsm != nil {
544 _ = aPAFsm.PFsm.Event(aniEvPrepareConfig)
545 }
546 }(pConfigAniStateAFsm)
mpagenko3dbcdd22020-07-22 07:38:45 +0000547
mpagenko3dbcdd22020-07-22 07:38:45 +0000548 }
549}
550
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530551//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000552func (oFsm *UniPonAniConfigFsm) enterCreatingDot1PMapper(ctx context.Context, e *fsm.Event) {
553 logger.Debugw(ctx, "UniPonAniConfigFsm Tx Create::Dot1PMapper", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000554 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000555 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000556 oFsm.requestEventOffset = 0 //0 offset for last config request activity
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000557 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000558 meInstance, err := oFsm.pOmciCC.SendCreateDot1PMapper(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
559 oFsm.mapperSP0ID, oFsm.PAdaptFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300560 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000561 logger.Errorw(ctx, "Dot1PMapper create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300562 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000563 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300564 if pConfigAniStateAFsm != nil {
565 oFsm.mutexPLastTxMeInstance.Unlock()
566 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000567 go func(aPAFsm *cmn.AdapterFsm) {
568 if aPAFsm != nil && aPAFsm.PFsm != nil {
569 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300570 }
571 }(pConfigAniStateAFsm)
572 return
573 }
574 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000575 //accept also nil as (error) return value for writing to LastTx
576 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000577 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300578 oFsm.mutexPLastTxMeInstance.Unlock()
579
mpagenko3dbcdd22020-07-22 07:38:45 +0000580}
581
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530582//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000583func (oFsm *UniPonAniConfigFsm) enterCreatingMBPCD(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530584 logger.Info(ctx, "Creating Tx MAC Bridge Port Config Data", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000585 "EntitytId": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16),
586 "TPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000587 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
588 bridgePtr := cmn.MacBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.MacBpNo) //cmp also omci_cc.go::sendCreateMBServiceProfile
bseeniva5f32c452025-07-18 17:30:41 +0530589 // generate unique MacBpNo from tech profile ID for ANI side
590 macBpNo, macBpNoErr := cmn.GenerateANISideMBPCDPortNo(uint16(oFsm.techProfileID))
591 if macBpNoErr != nil {
592 logger.Warn(ctx, "Failed to generate MAC bridge port number, Will set the port-number to 0xFF", log.Fields{
593 "device-id": oFsm.deviceID,
594 "uni-id": oFsm.pOnuUniPort.UniID,
595 "error": macBpNoErr,
596 })
597 macBpNo = 0xFF
598 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000599 meParams := me.ParamData{
600 EntityID: oFsm.macBPCD0ID,
601 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000602 me.MacBridgePortConfigurationData_BridgeIdPointer: bridgePtr,
bseeniva5f32c452025-07-18 17:30:41 +0530603 me.MacBridgePortConfigurationData_PortNum: uint8(macBpNo), //fixed unique ANI side indication
604 me.MacBridgePortConfigurationData_TpType: 3, //for .1PMapper
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000605 me.MacBridgePortConfigurationData_TpPointer: oFsm.mapperSP0ID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000606 },
607 }
bseeniva5f32c452025-07-18 17:30:41 +0530608
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000609 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000610 meInstance, err := oFsm.pOmciCC.SendCreateMBPConfigDataVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
611 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300612 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000613 logger.Errorw(ctx, "MBPConfigDataVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300614 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000615 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300616 if pConfigAniStateAFsm != nil {
617 oFsm.mutexPLastTxMeInstance.Unlock()
618 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000619 go func(aPAFsm *cmn.AdapterFsm) {
620 if aPAFsm != nil && aPAFsm.PFsm != nil {
621 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300622 }
623 }(pConfigAniStateAFsm)
624 return
625 }
626 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000627 //accept also nil as (error) return value for writing to LastTx
628 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000629 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300630 oFsm.mutexPLastTxMeInstance.Unlock()
631
mpagenko3dbcdd22020-07-22 07:38:45 +0000632}
633
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530634//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000635func (oFsm *UniPonAniConfigFsm) enterSettingTconts(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530636 logger.Info(ctx, "Tx Setting Tcont ", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000637 "EntitytId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
638 "AllocId": strconv.FormatInt(int64(oFsm.alloc0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000639 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700640 "tcontExist": oFsm.tcontSetBefore})
641 //If tcont was set before, then no need to set it again. Let state machine to proceed.
642 if oFsm.tcontSetBefore {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000643 go func(aPAFsm *cmn.AdapterFsm) {
644 if aPAFsm != nil && aPAFsm.PFsm != nil {
645 _ = aPAFsm.PFsm.Event(aniEvRxTcontsResp)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700646 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000647 }(oFsm.PAdaptFsm)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700648 return
649 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000650 meParams := me.ParamData{
651 EntityID: oFsm.tcont0ID,
652 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000653 me.TCont_AllocId: oFsm.alloc0ID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000654 },
655 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000656 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000657 meInstance, err := oFsm.pOmciCC.SendSetTcontVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
658 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300659 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000660 logger.Errorw(ctx, "TcontVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300661 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000662 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300663 if pConfigAniStateAFsm != nil {
664 oFsm.mutexPLastTxMeInstance.Unlock()
665 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000666 go func(aPAFsm *cmn.AdapterFsm) {
667 if aPAFsm != nil && aPAFsm.PFsm != nil {
668 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300669 }
670 }(pConfigAniStateAFsm)
671 return
672 }
673 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000674 //accept also nil as (error) return value for writing to LastTx
675 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000676 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300677 oFsm.mutexPLastTxMeInstance.Unlock()
678
mpagenko3dbcdd22020-07-22 07:38:45 +0000679}
680
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530681//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000682func (oFsm *UniPonAniConfigFsm) enterCreatingGemNCTPs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530683 logger.Info(ctx, "UniPonAniConfigFsm - start creating GemNWCtp loop", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000684 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000685 go oFsm.performCreatingGemNCTPs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000686}
687
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530688//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000689func (oFsm *UniPonAniConfigFsm) enterCreatingGemIWs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530690 logger.Info(ctx, "UniPonAniConfigFsm - start creating GemIwTP loop", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000691 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000692 go oFsm.performCreatingGemIWs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000693}
694
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000695func (oFsm *UniPonAniConfigFsm) enterSettingPQs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530696 logger.Info(ctx, "UniPonAniConfigFsm - start setting PrioQueue loop", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000697 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000698 go oFsm.performSettingPQs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000699}
700
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000701func (oFsm *UniPonAniConfigFsm) enterSettingDot1PMapper(ctx context.Context, e *fsm.Event) {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300702
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530703 logger.Info(ctx, "UniPonAniConfigFsm Tx Set::.1pMapper with all PBits set", log.Fields{"EntitytId": 0x8042, /*cmp above*/
mpagenko8b07c1b2020-11-26 10:36:31 +0000704 "toGemIw": 1024, /* cmp above */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000705 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000706
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530707 logger.Info(ctx, "UniPonAniConfigFsm Tx Set::1pMapper", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000708 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +0000709 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000710
mpagenko3dbcdd22020-07-22 07:38:45 +0000711 meParams := me.ParamData{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000712 EntityID: oFsm.mapperSP0ID,
Himani Chawla4d908332020-08-31 12:30:20 +0530713 Attributes: make(me.AttributeValueMap),
mpagenko3dbcdd22020-07-22 07:38:45 +0000714 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000715
716 //assign the GemPorts according to the configured Prio
717 var loPrioGemPortArray [8]uint16
718 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300719 if gemPortAttribs.isMulticast {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000720 logger.Debugw(ctx, "UniPonAniConfigFsm Port is Multicast, ignoring .1pMapper", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300721 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
722 "prioString": gemPortAttribs.pbitString})
723 continue
724 }
725 if gemPortAttribs.pbitString == "" {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000726 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString empty string error", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300727 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
728 "prioString": gemPortAttribs.pbitString})
729 continue
730 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000731 for i := 0; i < 8; i++ {
732 // "lenOfPbitMap(8) - i + 1" will give i-th pbit value from LSB position in the pbit map string
733 if prio, err := strconv.Atoi(string(gemPortAttribs.pbitString[7-i])); err == nil {
734 if prio == 1 { // Check this p-bit is set
735 if loPrioGemPortArray[i] == 0 {
736 loPrioGemPortArray[i] = gemPortAttribs.gemPortID //gemPortId=EntityID and unique
737 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000738 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString not unique", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000739 "device-id": oFsm.deviceID, "IgnoredGemPort": gemPortAttribs.gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000740 "SetGemPort": loPrioGemPortArray[i]})
741 }
742 }
743 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000744 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString evaluation error", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000745 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000746 "prioString": gemPortAttribs.pbitString, "position": i})
747 }
748
749 }
750 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300751
ozgecanetsia4b232302020-11-11 10:58:10 +0300752 var foundIwPtr = false
Himani Chawla4d908332020-08-31 12:30:20 +0530753 for index, value := range loPrioGemPortArray {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300754 meAttribute := fmt.Sprintf("InterworkTpPointerForPBitPriority%d", index)
Himani Chawla4d908332020-08-31 12:30:20 +0530755 if value != 0 {
756 foundIwPtr = true
Himani Chawla4d908332020-08-31 12:30:20 +0530757 meParams.Attributes[meAttribute] = value
dbainbri4d3a0dc2020-12-02 00:33:42 +0000758 logger.Debugw(ctx, "UniPonAniConfigFsm Set::1pMapper", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000759 "for Prio": index,
760 "IwPtr": strconv.FormatInt(int64(value), 16),
761 "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300762 } else {
763 // The null pointer 0xFFFF specifies that frames with the associated priority are to be discarded.
mpagenko8b5fdd22020-12-17 17:58:32 +0000764 // setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting
765 // but except for processing effort does not really harm - left to keep changes low
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300766 meParams.Attributes[meAttribute] = 0xffff
Himani Chawla4d908332020-08-31 12:30:20 +0530767 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000768 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300769 // The TP type value 0 also indicates bridging mapping, and the TP pointer should be set to 0xFFFF
mpagenko8b5fdd22020-12-17 17:58:32 +0000770 // setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting
771 // but except for processing effort does not really harm - left to keep changes low
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000772 meParams.Attributes[me.Ieee8021PMapperServiceProfile_TpPointer] = 0xffff
Himani Chawla4d908332020-08-31 12:30:20 +0530773
774 if !foundIwPtr {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530775 logger.Warn(ctx, "UniPonAniConfigFsm no GemIwPtr found for .1pMapper - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000776 "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300777 //TODO With multicast is possible that no upstream gem ports are not present in the tech profile,
778 // 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 +0000779 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000780 //pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300781 //if pConfigAniStateAFsm != nil {
782 // // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000783 // go func(aPAFsm *cmn.AdapterFsm) {
784 // if aPAFsm != nil && aPAFsm.PFsm != nil {
785 // _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300786 // }
787 // }(pConfigAniStateAFsm)
788 //}
789 //Moving forward the FSM as if the response was received correctly.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000790 pConfigAniStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000791 if pConfigAniStateAFsm != nil {
792 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000793 go func(aPAFsm *cmn.AdapterFsm) {
794 if aPAFsm != nil && aPAFsm.PFsm != nil {
795 _ = aPAFsm.PFsm.Event(aniEvRxDot1pmapSResp)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000796 }
797 }(pConfigAniStateAFsm)
798 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300799 } else {
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000800 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000801 meInstance, err := oFsm.pOmciCC.SendSetDot1PMapperVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(), true,
802 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300803 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000804 logger.Errorw(ctx, "Dot1PMapperVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300805 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000806 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300807 if pConfigAniStateAFsm != nil {
808 oFsm.mutexPLastTxMeInstance.Unlock()
809 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000810 go func(aPAFsm *cmn.AdapterFsm) {
811 if aPAFsm != nil && aPAFsm.PFsm != nil {
812 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300813 }
814 }(pConfigAniStateAFsm)
815 return
816 }
817 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300818 //accept also nil as (error) return value for writing to LastTx
819 // - this avoids misinterpretation of new received OMCI messages
820 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300821 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000822 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000823}
824
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000825func (oFsm *UniPonAniConfigFsm) enterAniConfigDone(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530826 logger.Info(ctx, "UniPonAniConfigFsm ani config done", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000827 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenko01e726e2020-10-23 09:45:29 +0000828 //store that the UNI related techProfile processing is done for the given Profile and Uni
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000829 oFsm.pUniTechProf.setConfigDone(oFsm.pOnuUniPort.UniID, oFsm.techProfileID, true)
830 if !oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000831 //use DeviceHandler event notification directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000832 oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset)))
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000833 //if techProfile processing is done it must be checked, if some prior/parallel flow configuration is pending
834 // but only in case the techProfile was configured (not deleted)
835 if oFsm.requestEventOffset == 0 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000836 go oFsm.pDeviceHandler.VerifyUniVlanConfigRequest(ctx, oFsm.pOnuUniPort, oFsm.techProfileID)
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000837 }
838 } else {
839 logger.Debugw(ctx, "reconciling - skip AniConfigDone processing", log.Fields{"device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000840 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000841 if oFsm.isChanSet() {
mpagenko01e726e2020-10-23 09:45:29 +0000842 // indicate processing done to the caller
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000843 logger.Debugw(ctx, "UniPonAniConfigFsm processingDone on channel", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000844 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
845 oFsm.chSuccess <- oFsm.procStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000846 oFsm.setChanSet(false) //reset the internal channel state
mpagenko3dbcdd22020-07-22 07:38:45 +0000847 }
mpagenko01e726e2020-10-23 09:45:29 +0000848
849 //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 +0000850}
851
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530852//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000853func (oFsm *UniPonAniConfigFsm) enterRemovingGemIW(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +0000854 // no need to protect access to oFsm.waitFlowDeleteChannel, only used in synchronized state entries
855 // or CancelProcessing() that uses separate isWaitingForFlowDelete to write to the channel
mpagenkobb47bc22021-04-20 13:29:09 +0000856 //flush the waitFlowDeleteChannel - possibly already/still set by some previous activity
857 select {
858 case <-oFsm.waitFlowDeleteChannel:
859 logger.Debug(ctx, "flushed waitFlowDeleteChannel")
860 default:
861 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000862
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000863 uniVlanConfigFsm := oFsm.pDeviceHandler.GetUniVlanConfigFsm(oFsm.pOnuUniPort.UniID)
864 if uniVlanConfigFsm != nil {
mpagenko3ce9fa02021-07-28 13:26:54 +0000865 // ensure mutexTPState not locked before calling some VlanConfigFsm activity (that might already be pending on it)
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000866 if uniVlanConfigFsm.IsFlowRemovePending(ctx, oFsm.waitFlowDeleteChannel) {
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000867 logger.Debugw(ctx, "flow remove pending - wait before processing gem port delete",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000868 log.Fields{"device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000869 // 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 +0000870 pConfigAniStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000871 if pConfigAniStateAFsm != nil {
872 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000873 go func(aPAFsm *cmn.AdapterFsm) {
874 if aPAFsm != nil && aPAFsm.PFsm != nil {
875 _ = aPAFsm.PFsm.Event(aniEvWaitFlowRem)
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000876 }
877 }(pConfigAniStateAFsm)
878 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000879 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 +0000880 }
881 return
Girish Gowdra26a40922021-01-29 17:14:34 -0800882 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000883 } else {
884 logger.Debugw(ctx, "uni vlan config doesn't exist - no flow remove could be pending",
885 log.Fields{"device-id": oFsm.deviceID, "techProfile-id": oFsm.techProfileID})
Girish Gowdra26a40922021-01-29 17:14:34 -0800886 }
887
mpagenko3ce9fa02021-07-28 13:26:54 +0000888 oFsm.pUniTechProf.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000889 // get the related GemPort entity Id from pUniTechProf, OMCI Gem* entityID is set to be equal to GemPortId!
mpagenko8b07c1b2020-11-26 10:36:31 +0000890 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +0000891 oFsm.pUniTechProf.mutexTPState.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000892 logger.Debugw(ctx, "UniPonAniConfigFsm - start removing one GemIwTP", log.Fields{
893 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko8b07c1b2020-11-26 10:36:31 +0000894 "GemIwTp-entity-id": loGemPortID})
895 oFsm.requestEventOffset = 1 //offset 1 to indicate last activity = remove
896
897 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000898 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000899 meInstance, err := oFsm.pOmciCC.SendDeleteGemIWTP(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
900 oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300901 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000902 logger.Errorw(ctx, "GemIWTP delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300903 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000904 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300905 if pConfigAniStateAFsm != nil {
906 oFsm.mutexPLastTxMeInstance.Unlock()
907 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000908 go func(aPAFsm *cmn.AdapterFsm) {
909 if aPAFsm != nil && aPAFsm.PFsm != nil {
910 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300911 }
912 }(pConfigAniStateAFsm)
913 return
914 }
915 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000916 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300917 oFsm.mutexPLastTxMeInstance.Unlock()
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530918 logger.Infow(ctx, "Deleting GemIWTP at the ONU DB ", log.Fields{"device-id": oFsm.deviceID, "GEMID": loGemPortID})
919 oFsm.pOnuDB.DeleteMe(me.GemInterworkingTerminationPointClassID, loGemPortID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000920}
921
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530922//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000923func (oFsm *UniPonAniConfigFsm) enterWaitingFlowRem(ctx context.Context, e *fsm.Event) {
mpagenkobb47bc22021-04-20 13:29:09 +0000924 oFsm.mutexIsAwaitingResponse.Lock()
925 oFsm.isWaitingForFlowDelete = true
926 oFsm.mutexIsAwaitingResponse.Unlock()
927 select {
928 // maybe be also some outside cancel (but no context modeled for the moment ...)
929 // case <-ctx.Done():
930 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000931 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 +0000932 logger.Warnw(ctx, "UniPonAniConfigFsm WaitingFlowRem timeout", log.Fields{
933 "for device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000934 oFsm.mutexIsAwaitingResponse.Lock()
935 oFsm.isWaitingForFlowDelete = false
936 oFsm.mutexIsAwaitingResponse.Unlock()
937 //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 +0000938 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000939 if pConfigAniStateAFsm != nil {
940 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000941 go func(aPAFsm *cmn.AdapterFsm) {
942 if aPAFsm != nil && aPAFsm.PFsm != nil {
943 _ = aPAFsm.PFsm.Event(aniEvFlowRemDone)
mpagenkobb47bc22021-04-20 13:29:09 +0000944 }
945 }(pConfigAniStateAFsm)
946 } else {
947 logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000948 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000949 }
950 return
951
952 case success := <-oFsm.waitFlowDeleteChannel:
953 if success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000954 logger.Debugw(ctx, "UniPonAniConfigFsm flow removed info received", log.Fields{
955 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000956 oFsm.mutexIsAwaitingResponse.Lock()
957 oFsm.isWaitingForFlowDelete = false
958 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000959 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000960 if pConfigAniStateAFsm != nil {
961 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000962 go func(aPAFsm *cmn.AdapterFsm) {
963 if aPAFsm != nil && aPAFsm.PFsm != nil {
964 _ = aPAFsm.PFsm.Event(aniEvFlowRemDone)
mpagenkobb47bc22021-04-20 13:29:09 +0000965 }
966 }(pConfigAniStateAFsm)
967 } else {
968 logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000969 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000970 }
971 return
972 }
973 // waiting was aborted (probably on external request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000974 logger.Debugw(ctx, "UniPonAniConfigFsm WaitingFlowRem aborted", log.Fields{
975 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000976 oFsm.mutexIsAwaitingResponse.Lock()
977 oFsm.isWaitingForFlowDelete = false
978 oFsm.mutexIsAwaitingResponse.Unlock()
979 //to be sure we can just generate the reset-event to ensure leaving this state towards 'reset'
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000980 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000981 if pConfigAniStateAFsm != nil {
982 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000983 go func(aPAFsm *cmn.AdapterFsm) {
984 if aPAFsm != nil && aPAFsm.PFsm != nil {
985 _ = aPAFsm.PFsm.Event(aniEvReset)
mpagenkobb47bc22021-04-20 13:29:09 +0000986 }
987 }(pConfigAniStateAFsm)
988 }
989 return
990 }
991}
992
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530993//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000994func (oFsm *UniPonAniConfigFsm) enterRemovingGemNCTP(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +0000995 oFsm.pUniTechProf.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000996 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +0000997 oFsm.pUniTechProf.mutexTPState.RUnlock()
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530998 logger.Info(ctx, "UniPonAniConfigFsm - start removing one GemNCTP", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000999 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko8b07c1b2020-11-26 10:36:31 +00001000 "GemNCTP-entity-id": loGemPortID})
1001 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001002 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001003 meInstance, err := oFsm.pOmciCC.SendDeleteGemNCTP(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1004 oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001005 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001006 logger.Errorw(ctx, "GemNCTP delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001007 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001008 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001009 if pConfigAniStateAFsm != nil {
1010 oFsm.mutexPLastTxMeInstance.Unlock()
1011 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001012 go func(aPAFsm *cmn.AdapterFsm) {
1013 if aPAFsm != nil && aPAFsm.PFsm != nil {
1014 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001015 }
1016 }(pConfigAniStateAFsm)
1017 return
1018 }
1019 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001020 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001021 oFsm.mutexPLastTxMeInstance.Unlock()
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301022 oFsm.pOnuDB.DeleteMe(me.GemPortNetworkCtpClassID, loGemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001023 // Mark the gem port to be removed for Performance History monitoring
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001024 OnuMetricsManager := oFsm.pDeviceHandler.GetOnuMetricsManager()
1025 if OnuMetricsManager != nil {
1026 OnuMetricsManager.RemoveGemPortForPerfMonitoring(ctx, loGemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001027 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001028}
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301029
1030//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001031func (oFsm *UniPonAniConfigFsm) enterRemovingTD(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +00001032 oFsm.pUniTechProf.mutexTPState.RLock()
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001033 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +00001034 oFsm.pUniTechProf.mutexTPState.RUnlock()
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301035 logger.Info(ctx, "UniPonAniConfigFsm - start removing Traffic Descriptor", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001036 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001037 "TD-entity-id": loGemPortID})
1038
1039 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001040 meInstance, err := oFsm.pOmciCC.SendDeleteTD(log.WithSpanFromContext(context.TODO(), ctx),
1041 oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001042
1043 if err != nil {
1044 logger.Errorw(ctx, "TD delete failed - proceed fsm",
1045 log.Fields{"device-id": oFsm.deviceID, "gemPortID": loGemPortID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001046 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001047 if pConfigAniStateAFsm != nil {
1048 oFsm.mutexPLastTxMeInstance.Unlock()
1049 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001050 go func(aPAFsm *cmn.AdapterFsm) {
1051 if aPAFsm != nil && aPAFsm.PFsm != nil {
1052 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001053 }
1054 }(pConfigAniStateAFsm)
1055 return
1056 }
1057 }
1058 oFsm.pLastTxMeInstance = meInstance
1059 oFsm.mutexPLastTxMeInstance.Unlock()
1060}
mpagenko8b07c1b2020-11-26 10:36:31 +00001061
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301062//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001063func (oFsm *UniPonAniConfigFsm) enterResettingTcont(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301064 logger.Info(ctx, "UniPonAniConfigFsm - start resetting the TCont", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001065 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001066
1067 oFsm.requestEventOffset = 1 //offset 1 for last remove activity
1068 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
1069 meParams := me.ParamData{
1070 EntityID: oFsm.tcont0ID,
1071 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001072 me.TCont_AllocId: cmn.UnusedTcontAllocID,
mpagenko8b07c1b2020-11-26 10:36:31 +00001073 },
1074 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001075 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001076 meInstance, err := oFsm.pOmciCC.SendSetTcontVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1077 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001078 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001079 logger.Errorw(ctx, "TcontVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001080 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001081 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001082 if pConfigAniStateAFsm != nil {
1083 oFsm.mutexPLastTxMeInstance.Unlock()
1084 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001085 go func(aPAFsm *cmn.AdapterFsm) {
1086 if aPAFsm != nil && aPAFsm.PFsm != nil {
1087 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001088 }
1089 }(pConfigAniStateAFsm)
1090 return
1091 }
1092 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001093 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001094 oFsm.mutexPLastTxMeInstance.Unlock()
1095
mpagenko8b07c1b2020-11-26 10:36:31 +00001096}
1097
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301098//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001099func (oFsm *UniPonAniConfigFsm) enterRemoving1pMapper(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301100 logger.Info(ctx, "UniPonAniConfigFsm - start deleting the .1pMapper", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001101 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
bseenivaeba8eb12024-12-13 11:54:28 +05301102 var mapGemPortParams map[uint16]*gemPortParamStruct
Mahir Gunyel9545be22021-07-04 15:53:16 -07001103 unicastGemCount := 0
bseenivaeba8eb12024-12-13 11:54:28 +05301104 oFsm.pUniTechProf.mutexTPState.RLock()
1105 if _, ok := oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey]; ok {
1106 mapGemPortParams = oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].mapGemPortParams
1107 } else {
1108 logger.Warnw(ctx, "GemPortParams not found in mapPonAniConfig", log.Fields{"device-id": oFsm.deviceID,
1109 "uni-id": oFsm.pOnuUniPort.UniID})
1110 }
1111 oFsm.pUniTechProf.mutexTPState.RUnlock()
Mahir Gunyel9545be22021-07-04 15:53:16 -07001112 for _, gemEntry := range mapGemPortParams {
1113 if !gemEntry.isMulticast {
1114 unicastGemCount++
1115 }
1116 }
1117 if unicastGemCount > 1 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001118 logger.Debugw(ctx, "UniPonAniConfigFsm - Not the last gem in fsm. Skip the rest", log.Fields{
1119 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "unicast-gem-count": unicastGemCount, "gem-count": len(mapGemPortParams)})
1120 pConfigAniStateAFsm := oFsm.PAdaptFsm
Mahir Gunyel9545be22021-07-04 15:53:16 -07001121 if pConfigAniStateAFsm != nil {
1122 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001123 go func(aPAFsm *cmn.AdapterFsm) {
1124 if aPAFsm != nil && aPAFsm.PFsm != nil {
1125 _ = aPAFsm.PFsm.Event(aniEvRemGemDone)
Mahir Gunyel9545be22021-07-04 15:53:16 -07001126 }
1127 }(pConfigAniStateAFsm)
1128 return
1129 }
1130 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001131 logger.Debugw(ctx, "UniPonAniConfigFsm - Last gem in fsm. Continue with Mapper removal", log.Fields{
1132 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "unicast-gem-count": unicastGemCount, "gem-count": len(mapGemPortParams)})
mpagenko8b07c1b2020-11-26 10:36:31 +00001133
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001134 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001135 meInstance, err := oFsm.pOmciCC.SendDeleteDot1PMapper(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1136 oFsm.PAdaptFsm.CommChan, oFsm.mapperSP0ID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001137 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001138 logger.Errorw(ctx, "Dot1Mapper delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001139 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001140 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001141 if pConfigAniStateAFsm != nil {
1142 oFsm.mutexPLastTxMeInstance.Unlock()
1143 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001144 go func(aPAFsm *cmn.AdapterFsm) {
1145 if aPAFsm != nil && aPAFsm.PFsm != nil {
1146 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001147 }
1148 }(pConfigAniStateAFsm)
1149 return
1150 }
1151 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001152 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001153 oFsm.mutexPLastTxMeInstance.Unlock()
1154
mpagenko8b07c1b2020-11-26 10:36:31 +00001155}
1156
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301157//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001158func (oFsm *UniPonAniConfigFsm) enterRemovingAniBPCD(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301159 logger.Info(ctx, "UniPonAniConfigFsm - start deleting the ANI MBCD", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001160 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001161
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001162 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001163 meInstance, err := oFsm.pOmciCC.SendDeleteMBPConfigData(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1164 oFsm.PAdaptFsm.CommChan, oFsm.macBPCD0ID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001165 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001166 logger.Errorw(ctx, "MBPConfigData delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001167 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001168 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001169 if pConfigAniStateAFsm != nil {
1170 oFsm.mutexPLastTxMeInstance.Unlock()
1171 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001172 go func(aPAFsm *cmn.AdapterFsm) {
1173 if aPAFsm != nil && aPAFsm.PFsm != nil {
1174 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001175 }
1176 }(pConfigAniStateAFsm)
1177 return
1178 }
1179 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001180 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001181 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +00001182}
1183
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001184func (oFsm *UniPonAniConfigFsm) enterAniRemoveDone(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301185 logger.Info(ctx, "UniPonAniConfigFsm ani removal done", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001186 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001187 //use DeviceHandler event notification directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001188 oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset)))
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001189 if oFsm.isChanSet() {
mpagenko8b07c1b2020-11-26 10:36:31 +00001190 // indicate processing done to the caller
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001191 logger.Debugw(ctx, "UniPonAniConfigFsm processingDone on channel", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +00001192 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
1193 oFsm.chSuccess <- oFsm.procStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001194 oFsm.setChanSet(false) //reset the internal channel state
mpagenko8b07c1b2020-11-26 10:36:31 +00001195 }
1196
1197 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001198 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko8b07c1b2020-11-26 10:36:31 +00001199 if pConfigAniStateAFsm != nil {
1200 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001201 go func(aPAFsm *cmn.AdapterFsm) {
1202 if aPAFsm != nil && aPAFsm.PFsm != nil {
1203 _ = aPAFsm.PFsm.Event(aniEvReset)
mpagenko8b07c1b2020-11-26 10:36:31 +00001204 }
1205 }(pConfigAniStateAFsm)
1206 }
1207}
1208
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001209func (oFsm *UniPonAniConfigFsm) enterResettingState(ctx context.Context, e *fsm.Event) {
1210 logger.Debugw(ctx, "UniPonAniConfigFsm resetting", log.Fields{
1211 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001212
mpagenko45cc6a32021-07-23 10:06:57 +00001213 if oFsm.isChanSet() {
1214 // indicate processing error to the caller (in case there was still some open request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001215 logger.Debugw(ctx, "UniPonAniConfigFsm processingError on channel", log.Fields{
mpagenko45cc6a32021-07-23 10:06:57 +00001216 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
1217 //use non-blocking channel send to avoid blocking because of non-existing receiver
1218 // (even though the channel is checked on 'set', the outside receiver channel might (theoretically) already be deleted)
1219 select {
1220 case oFsm.chSuccess <- 0:
1221 default:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001222 logger.Debugw(ctx, "UniPonAniConfigFsm processingError not send on channel (no receiver)", log.Fields{
mpagenko45cc6a32021-07-23 10:06:57 +00001223 "device-id": oFsm.deviceID})
1224 }
1225 oFsm.setChanSet(false) //reset the internal channel state
1226 }
1227
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001228 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko3dbcdd22020-07-22 07:38:45 +00001229 if pConfigAniStateAFsm != nil {
1230 // abort running message processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001231 fsmAbortMsg := cmn.Message{
1232 Type: cmn.TestMsg,
1233 Data: cmn.TestMessage{
1234 TestMessageVal: cmn.AbortMessageProcessing,
mpagenko3dbcdd22020-07-22 07:38:45 +00001235 },
1236 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001237 pConfigAniStateAFsm.CommChan <- fsmAbortMsg
mpagenko3dbcdd22020-07-22 07:38:45 +00001238
1239 //try to restart the FSM to 'disabled', decouple event transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001240 go func(aPAFsm *cmn.AdapterFsm) {
1241 if aPAFsm != nil && aPAFsm.PFsm != nil {
1242 _ = aPAFsm.PFsm.Event(aniEvRestart)
mpagenko3dbcdd22020-07-22 07:38:45 +00001243 }
1244 }(pConfigAniStateAFsm)
Akash Soni3de0e062024-12-11 16:37:26 +05301245 logger.Warnf(ctx, "calling HandleAniConfigFSMFailure resetting", log.Fields{
1246 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
1247 oFsm.pDeviceHandler.HandleAniConfigFSMFailure(ctx, oFsm.pOnuUniPort.UniID)
mpagenko3dbcdd22020-07-22 07:38:45 +00001248 }
1249}
1250
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301251//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001252func (oFsm *UniPonAniConfigFsm) enterDisabledState(ctx context.Context, e *fsm.Event) {
1253 logger.Debugw(ctx, "UniPonAniConfigFsm enters disabled state", log.Fields{
1254 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001255 oFsm.mutexPLastTxMeInstance.Lock()
1256 defer oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00001257 oFsm.pLastTxMeInstance = nil
mpagenko1cc3cb42020-07-27 15:24:38 +00001258}
1259
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001260func (oFsm *UniPonAniConfigFsm) processOmciAniMessages(ctx context.Context) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301261 logger.Info(ctx, "Start UniPonAniConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001262loop:
1263 for {
mpagenko3dbcdd22020-07-22 07:38:45 +00001264 // case <-ctx.Done():
mpagenko01e726e2020-10-23 09:45:29 +00001265 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001266 // break loop
bseenivaeba8eb12024-12-13 11:54:28 +05301267 select {
1268 case message, ok := <-oFsm.PAdaptFsm.CommChan:
1269 if !ok {
1270 logger.Warn(ctx, "UniPonAniConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID})
1271 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
1272 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +00001273 break loop
1274 }
bseenivaeba8eb12024-12-13 11:54:28 +05301275 logger.Debugw(ctx, "UniPonAniConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID})
1276
1277 switch message.Type {
1278 case cmn.TestMsg:
1279 msg, _ := message.Data.(cmn.TestMessage)
1280 if msg.TestMessageVal == cmn.AbortMessageProcessing {
1281 logger.Infow(ctx, "UniPonAniConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID})
1282 break loop
1283 }
1284 logger.Warnw(ctx, "UniPonAniConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal})
1285 case cmn.OMCI:
1286 msg, _ := message.Data.(cmn.OmciMessage)
1287 oFsm.handleOmciAniConfigMessage(ctx, msg)
1288 default:
1289 logger.Warn(ctx, "UniPonAniConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID,
1290 "message.Type": message.Type})
1291 }
1292 case _, ok := <-oFsm.pDeviceHandler.GetDeviceDeleteCommChan(ctx):
1293 if !ok {
1294 logger.Warnw(ctx, "Device deletion channel closed", log.Fields{"device-id": oFsm.deviceID})
1295 }
1296 break loop
Himani Chawla4d908332020-08-31 12:30:20 +05301297 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001298
Himani Chawla4d908332020-08-31 12:30:20 +05301299 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001300 logger.Infow(ctx, "End UniPonAniConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301301}
1302
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001303func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigCreateResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +05301304 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse)
1305 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001306 logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001307 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301308 return
1309 }
1310 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
1311 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001312 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001313 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301314 return
1315 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001316 logger.Debugw(ctx, "CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenkofc4f56e2020-11-04 17:17:49 +00001317 if msgObj.Result == me.Success || msgObj.Result == me.InstanceExists {
1318 //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 +00001319 oFsm.mutexPLastTxMeInstance.RLock()
1320 if oFsm.pLastTxMeInstance != nil {
1321 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1322 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1323 // maybe we can use just the same eventName for different state transitions like "forward"
1324 // - might be checked, but so far I go for sure and have to inspect the concrete state events ...
1325 switch oFsm.pLastTxMeInstance.GetName() {
1326 case "Ieee8021PMapperServiceProfile":
1327 { // let the FSM proceed ...
1328 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001329 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxDot1pmapCResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001330 }
1331 case "MacBridgePortConfigurationData":
1332 { // let the FSM proceed ...
1333 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001334 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxMbpcdResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001335 }
1336 case "GemPortNetworkCtp", "GemInterworkingTerminationPoint", "MulticastGemInterworkingTerminationPoint":
1337 { // let aniConfig Multi-Id processing proceed by stopping the wait function
1338 oFsm.mutexPLastTxMeInstance.RUnlock()
1339 oFsm.omciMIdsResponseReceived <- true
1340 }
1341 default:
1342 {
1343 oFsm.mutexPLastTxMeInstance.RUnlock()
1344 logger.Warnw(ctx, "Unsupported ME name received!",
1345 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1346 }
mpagenkofc4f56e2020-11-04 17:17:49 +00001347 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001348 } else {
1349 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenkofc4f56e2020-11-04 17:17:49 +00001350 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001351 } else {
1352 oFsm.mutexPLastTxMeInstance.RUnlock()
1353 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +00001354 }
1355 } else {
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001356 logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?",
1357 log.Fields{"Error": msgObj.Result, "device-id": oFsm.deviceID})
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001358 // possibly force FSM into abort or ignore some errors for some messages?
1359 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1360 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
Himani Chawla4d908332020-08-31 12:30:20 +05301361 return
1362 }
Himani Chawla4d908332020-08-31 12:30:20 +05301363}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001364func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigSetFailResponseMessage(ctx context.Context, msgObj *omci.SetResponse) {
Mahir Gunyel01034b62021-06-29 11:25:09 -07001365 //If TCONT fails, then we need to revert the allocated TCONT in DB.
1366 //Because FSMs are running sequentially, we don't expect the same TCONT hit by another tech-profile FSM while this FSM is running.
1367 oFsm.mutexPLastTxMeInstance.RLock()
1368 defer oFsm.mutexPLastTxMeInstance.RUnlock()
1369 if oFsm.pLastTxMeInstance != nil && msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1370 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1371 switch oFsm.pLastTxMeInstance.GetName() {
1372 case "TCont":
1373 //If this is for TCONT creation(requestEventOffset=0) and this is the first allocation of TCONT(so noone else is using the same TCONT)
1374 //We should revert DB
bseenivaeba8eb12024-12-13 11:54:28 +05301375 oFsm.pUniTechProf.mutexTPState.RLock()
Mahir Gunyel01034b62021-06-29 11:25:09 -07001376 if oFsm.requestEventOffset == 0 && !oFsm.tcontSetBefore && oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey] != nil {
1377 logger.Debugw(ctx, "UniPonAniConfigFsm TCONT creation failed on device. Freeing alloc id", log.Fields{"device-id": oFsm.deviceID,
1378 "alloc-id": oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID, "uni-tp": oFsm.uniTpKey})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001379 if oFsm.pOnuDeviceEntry != nil {
1380 oFsm.pOnuDeviceEntry.FreeTcont(ctx, oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID)
Mahir Gunyel01034b62021-06-29 11:25:09 -07001381 } else {
1382 logger.Warnw(ctx, "Unable to get device entry! couldn't free tcont",
1383 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1384 }
1385 }
bseenivaeba8eb12024-12-13 11:54:28 +05301386 oFsm.pUniTechProf.mutexTPState.RUnlock()
Mahir Gunyel01034b62021-06-29 11:25:09 -07001387 default:
1388 logger.Warnw(ctx, "Unsupported ME name received with error!",
1389 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "result": msgObj.Result, "device-id": oFsm.deviceID})
1390 }
1391 }
1392}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001393func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigSetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +05301394 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
1395 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001396 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be detected for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001397 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301398 return
1399 }
1400 msgObj, msgOk := msgLayer.(*omci.SetResponse)
1401 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001402 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be assigned for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001403 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301404 return
1405 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001406 logger.Debugw(ctx, "UniPonAniConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +05301407 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001408 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci SetResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00001409 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001410 // possibly force FSM into abort or ignore some errors for some messages?
1411 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1412 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
Mahir Gunyel01034b62021-06-29 11:25:09 -07001413 oFsm.handleOmciAniConfigSetFailResponseMessage(ctx, msgObj)
Himani Chawla4d908332020-08-31 12:30:20 +05301414 return
1415 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001416 oFsm.mutexPLastTxMeInstance.RLock()
1417 if oFsm.pLastTxMeInstance != nil {
1418 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1419 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1420 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
1421 // if, then something like:
1422 //oFsm.pOnuDB.StoreMe(msgObj)
Himani Chawla4d908332020-08-31 12:30:20 +05301423
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001424 switch oFsm.pLastTxMeInstance.GetName() {
1425 case "TCont":
1426 { // let the FSM proceed ...
1427 oFsm.mutexPLastTxMeInstance.RUnlock()
1428 if oFsm.requestEventOffset == 0 { //from TCont config request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001429 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxTcontsResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001430 } else { // from T-Cont reset request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001431 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxResetTcontResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001432 }
1433 }
1434 case "PriorityQueue", "MulticastGemInterworkingTerminationPoint":
1435 { // let the PrioQueue init proceed by stopping the wait function
1436 oFsm.mutexPLastTxMeInstance.RUnlock()
1437 oFsm.omciMIdsResponseReceived <- true
1438 }
1439 case "Ieee8021PMapperServiceProfile":
1440 { // let the FSM proceed ...
1441 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001442 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxDot1pmapSResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001443 }
1444 default:
1445 {
1446 oFsm.mutexPLastTxMeInstance.RUnlock()
1447 logger.Warnw(ctx, "Unsupported ME name received!",
1448 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001449 }
Himani Chawla4d908332020-08-31 12:30:20 +05301450 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001451 } else {
1452 oFsm.mutexPLastTxMeInstance.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +05301453 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001454 } else {
1455 oFsm.mutexPLastTxMeInstance.RUnlock()
1456 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301457 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001458}
1459
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001460func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigDeleteResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
mpagenko8b07c1b2020-11-26 10:36:31 +00001461 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeDeleteResponse)
1462 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001463 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be detected for DeleteResponse",
mpagenko8b07c1b2020-11-26 10:36:31 +00001464 log.Fields{"device-id": oFsm.deviceID})
1465 return
1466 }
1467 msgObj, msgOk := msgLayer.(*omci.DeleteResponse)
1468 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001469 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be assigned for DeleteResponse",
mpagenko8b07c1b2020-11-26 10:36:31 +00001470 log.Fields{"device-id": oFsm.deviceID})
1471 return
1472 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001473 logger.Debugw(ctx, "UniPonAniConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
Akash Soni8eff4632024-12-11 13:41:46 +05301474 if msgObj.Result == me.UnknownInstance {
1475 logger.Warnw(ctx, "UniPonAniConfigFsm - Unknow Instance",
1476 log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj, "Error": msgObj.Result})
1477 } else if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001478 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci DeleteResponse Error",
mpagenko8b07c1b2020-11-26 10:36:31 +00001479 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
1480 //TODO: - later: possibly force FSM into abort or ignore some errors for some messages?
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001481 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1482 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
mpagenko8b07c1b2020-11-26 10:36:31 +00001483 return
1484 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001485 oFsm.mutexPLastTxMeInstance.RLock()
1486 if oFsm.pLastTxMeInstance != nil {
1487 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1488 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1489 //remove ME from DB //TODO??? obviously the Python code does not store/remove the config ...
1490 // if, then something like: oFsm.pOnuDB.XyyMe(msgObj)
mpagenko8b07c1b2020-11-26 10:36:31 +00001491
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001492 switch oFsm.pLastTxMeInstance.GetName() {
1493 case "GemInterworkingTerminationPoint":
1494 { // let the FSM proceed ...
1495 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001496 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemGemiwResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001497 }
1498 case "GemPortNetworkCtp":
1499 { // let the FSM proceed ...
1500 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001501 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemGemntpResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001502 }
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001503 case "TrafficDescriptor":
1504 { // let the FSM proceed ...
1505 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001506 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemTdResp)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001507 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001508 case "Ieee8021PMapperServiceProfile":
1509 { // let the FSM proceed ...
1510 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001511 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRem1pMapperResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001512 }
1513 case "MacBridgePortConfigurationData":
1514 { // this is the last event of the T-Cont cleanup procedure, FSM may be reset here
1515 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001516 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemAniBPCDResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001517 }
1518 default:
1519 {
1520 oFsm.mutexPLastTxMeInstance.RUnlock()
1521 logger.Warnw(ctx, "Unsupported ME name received!",
1522 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1523 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001524 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001525 } else {
1526 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko8b07c1b2020-11-26 10:36:31 +00001527 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001528 } else {
1529 oFsm.mutexPLastTxMeInstance.RUnlock()
1530 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001531 }
1532}
1533
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001534func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001535 logger.Debugw(ctx, "Rx OMCI UniPonAniConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001536 "msgType": msg.OmciMsg.MessageType})
1537
1538 switch msg.OmciMsg.MessageType {
1539 case omci.CreateResponseType:
1540 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001541 oFsm.handleOmciAniConfigCreateResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301542
mpagenko3dbcdd22020-07-22 07:38:45 +00001543 } //CreateResponseType
1544 case omci.SetResponseType:
1545 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001546 oFsm.handleOmciAniConfigSetResponseMessage(ctx, msg)
mpagenko3dbcdd22020-07-22 07:38:45 +00001547
mpagenko3dbcdd22020-07-22 07:38:45 +00001548 } //SetResponseType
mpagenko8b07c1b2020-11-26 10:36:31 +00001549 case omci.DeleteResponseType:
1550 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001551 oFsm.handleOmciAniConfigDeleteResponseMessage(ctx, msg)
mpagenko8b07c1b2020-11-26 10:36:31 +00001552
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001553 } //DeleteResponseType
mpagenko3dbcdd22020-07-22 07:38:45 +00001554 default:
1555 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001556 logger.Errorw(ctx, "UniPonAniConfigFsm - Rx OMCI unhandled MsgType",
mpagenko01e726e2020-10-23 09:45:29 +00001557 log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001558 return
1559 }
1560 }
1561}
1562
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001563func (oFsm *UniPonAniConfigFsm) performCreatingGemNCTPs(ctx context.Context) {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001564 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
1565 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301566 logger.Info(ctx, "UniPonAniConfigFsm Tx Create::GemNWCtp", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001567 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
1568 "TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001569 "device-id": oFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001570 meParams := me.ParamData{
1571 EntityID: gemPortAttribs.gemPortID, //unique, same as PortId
1572 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001573 me.GemPortNetworkCtp_PortId: gemPortAttribs.gemPortID,
1574 me.GemPortNetworkCtp_TContPointer: oFsm.tcont0ID,
1575 me.GemPortNetworkCtp_Direction: gemPortAttribs.direction,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001576 //ONU-G.TrafficManagementOption dependency ->PrioQueue or TCont
1577 // TODO!! verify dependency and QueueId in case of Multi-GemPort setup!
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001578 me.GemPortNetworkCtp_TrafficManagementPointerForUpstream: gemPortAttribs.upQueueID, //might be different in wrr-only Setup - tcont0ID
1579 me.GemPortNetworkCtp_PriorityQueuePointerForDownStream: gemPortAttribs.downQueueID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001580 },
1581 }
Holger Hildebrandtc408f492022-07-14 08:39:24 +00001582 if oFsm.techProfileType == cTechProfileTypeXgsPon {
1583 meParams.Attributes[me.GemPortNetworkCtp_EncryptionKeyRing] = GemEncryptKeyRingUnicastDownstreamOnly
1584 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001585 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001586 meInstance, err := oFsm.pOmciCC.SendCreateGemNCTPVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1587 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001588 if err != nil {
1589 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001590 logger.Errorw(ctx, "GemNCTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001591 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001592 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001593 return
1594 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001595 //accept also nil as (error) return value for writing to LastTx
1596 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001597 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001598 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001599 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001600 err = oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001601 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001602 logger.Errorw(ctx, "GemNWCtp create failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001603 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001604 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001605 return
1606 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301607 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpClassID, gemPortAttribs.gemPortID, meParams.Attributes)
Girish Gowdra50e56422021-06-01 16:46:04 -07001608 // Mark the gem port to be added for Performance History monitoring
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001609 OnuMetricsManager := oFsm.pDeviceHandler.GetOnuMetricsManager()
1610 if OnuMetricsManager != nil {
1611 OnuMetricsManager.AddGemPortForPerfMonitoring(ctx, gemPortAttribs.gemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001612 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001613 } //for all GemPorts of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +00001614
1615 // if Config has been done for all GemPort instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001616 logger.Debugw(ctx, "GemNWCtp create loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001617 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxGemntcpsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001618}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001619func (oFsm *UniPonAniConfigFsm) hasMulticastGem(ctx context.Context) bool {
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001620 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
1621 if gemPortAttribs.isMulticast {
1622 logger.Debugw(ctx, "Found multicast gem", log.Fields{"device-id": oFsm.deviceID})
1623 return true
1624 }
1625 }
1626 return false
1627}
mpagenko3dbcdd22020-07-22 07:38:45 +00001628
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001629func (oFsm *UniPonAniConfigFsm) performCreatingGemIWs(ctx context.Context) {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001630 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
1631 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301632 logger.Info(ctx, "UniPonAniConfigFsm Tx Create::GemIwTp", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001633 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
1634 "SPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001635 "device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001636
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301637 var meParams me.ParamData
ozgecanetsia4b232302020-11-11 10:58:10 +03001638 //TODO if the port has only downstream direction the isMulticast flag can be removed.
1639 if gemPortAttribs.isMulticast {
ozgecanetsia4b232302020-11-11 10:58:10 +03001640
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301641 meParams = me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001642 EntityID: gemPortAttribs.multicastGemID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001643 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001644 me.MulticastGemInterworkingTerminationPoint_GemPortNetworkCtpConnectivityPointer: gemPortAttribs.multicastGemID,
1645 me.MulticastGemInterworkingTerminationPoint_InterworkingOption: 0, // Don't Care
1646 me.MulticastGemInterworkingTerminationPoint_ServiceProfilePointer: 0, // Don't Care
1647 me.MulticastGemInterworkingTerminationPoint_GalProfilePointer: cmn.GalEthernetEID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001648 },
1649 }
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001650 if oFsm.pUniTechProf.multicastConfiguredForOtherUniTps(ctx, oFsm.uniTpKey) {
1651 logger.Debugw(ctx, "MulticastGemInterworkingTP already exist", log.Fields{"device-id": oFsm.deviceID, "multicast-gem-id": gemPortAttribs.multicastGemID})
1652 continue
1653 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001654 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001655 meInstance, err := oFsm.pOmciCC.SendCreateMulticastGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(),
1656 true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001657 if err != nil {
1658 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001659 logger.Errorw(ctx, "MulticastGemIWTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001660 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001661 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001662 return
1663
1664 }
ozgecanetsia4b232302020-11-11 10:58:10 +03001665 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001666 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001667 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001668 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001669 if err != nil {
ozgecanetsiab36ed572021-04-01 10:38:48 +03001670 logger.Errorw(ctx, "MulticastGemIWTP create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001671 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001672 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001673 return
1674 }
1675 ipv4MulticastTable := make([]uint8, 12)
1676 //Gem Port ID
1677 binary.BigEndian.PutUint16(ipv4MulticastTable[0:], gemPortAttribs.multicastGemID)
1678 //Secondary Key
1679 binary.BigEndian.PutUint16(ipv4MulticastTable[2:], 0)
1680 // Multicast IP range start This is the 224.0.0.1 address
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001681 binary.BigEndian.PutUint32(ipv4MulticastTable[4:], cmn.IPToInt32(net.IPv4(224, 0, 0, 0)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001682 // MulticastIp range stop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001683 binary.BigEndian.PutUint32(ipv4MulticastTable[8:], cmn.IPToInt32(net.IPv4(239, 255, 255, 255)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001684
1685 meIPV4MCTableParams := me.ParamData{
1686 EntityID: gemPortAttribs.multicastGemID,
1687 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001688 me.MulticastGemInterworkingTerminationPoint_Ipv4MulticastAddressTable: ipv4MulticastTable,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001689 },
1690 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001691 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001692 meIPV4MCTableInstance, err := oFsm.pOmciCC.SendSetMulticastGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(),
1693 true, oFsm.PAdaptFsm.CommChan, meIPV4MCTableParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001694 if err != nil {
1695 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001696 logger.Errorw(ctx, "MulticastGemIWTPVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001697 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001698 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001699 return
1700 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001701 oFsm.pLastTxMeInstance = meIPV4MCTableInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001702 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia4b232302020-11-11 10:58:10 +03001703
1704 } else {
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301705 meParams = me.ParamData{
ozgecanetsia4b232302020-11-11 10:58:10 +03001706 EntityID: gemPortAttribs.gemPortID,
1707 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001708 me.GemInterworkingTerminationPoint_GemPortNetworkCtpConnectivityPointer: gemPortAttribs.gemPortID, //same as EntityID, see above
1709 me.GemInterworkingTerminationPoint_InterworkingOption: 5, //fixed model:: G.998 .1pMapper
1710 me.GemInterworkingTerminationPoint_ServiceProfilePointer: oFsm.mapperSP0ID,
1711 me.GemInterworkingTerminationPoint_InterworkingTerminationPointPointer: 0, //not used with .1PMapper Mac bridge
1712 me.GemInterworkingTerminationPoint_GalProfilePointer: cmn.GalEthernetEID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001713 },
1714 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001715 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001716 meInstance, err := oFsm.pOmciCC.SendCreateGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1717 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001718 if err != nil {
1719 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001720 logger.Errorw(ctx, "GEMIWTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001721 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001722 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001723 return
1724 }
ozgecanetsia4b232302020-11-11 10:58:10 +03001725 //accept also nil as (error) return value for writing to LastTx
1726 // - this avoids misinterpretation of new received OMCI messages
1727 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001728 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia4b232302020-11-11 10:58:10 +03001729 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001730 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001731 err := oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001732 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001733 logger.Errorw(ctx, "GemTP create failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001734 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001735 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001736 return
1737 }
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301738 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 +05301739 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemInterworkingTerminationPointClassID, gemPortAttribs.gemPortID, meParams.Attributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301740
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001741 } //for all GemPort's of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +00001742
1743 // if Config has been done for all GemPort instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001744 logger.Debugw(ctx, "GemIwTp create loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001745 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxGemiwsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001746}
1747
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001748func (oFsm *UniPonAniConfigFsm) performSettingPQs(ctx context.Context) {
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001749 //If upstream PQs were set before, then no need to set them again. Let state machine to proceed.
1750 if oFsm.tcontSetBefore {
1751 logger.Debugw(ctx, "No need to set PQs again.", log.Fields{
1752 "device-id": oFsm.deviceID, "tcont": oFsm.alloc0ID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001753 "uni-id": oFsm.pOnuUniPort.UniID,
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001754 "techProfile-id": oFsm.techProfileID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001755 go func(aPAFsm *cmn.AdapterFsm) {
1756 if aPAFsm != nil && aPAFsm.PFsm != nil {
1757 _ = aPAFsm.PFsm.Event(aniEvRxPrioqsResp)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001758 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001759 }(oFsm.PAdaptFsm)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001760 return
1761 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001762 const cu16StrictPrioWeight uint16 = 0xFFFF
1763 //find all upstream PrioQueues related to this T-Cont
1764 loQueueMap := ordered_map.NewOrderedMap()
1765 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001766 if gemPortAttribs.isMulticast {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001767 logger.Debugw(ctx, "UniPonAniConfigFsm Port is Multicast, ignoring PQs", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001768 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
1769 "prioString": gemPortAttribs.pbitString})
1770 continue
1771 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001772 if gemPortAttribs.qosPolicy == "WRR" {
Himani Chawla4d908332020-08-31 12:30:20 +05301773 if _, ok := loQueueMap.Get(gemPortAttribs.upQueueID); !ok {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001774 //key does not yet exist
1775 loQueueMap.Set(gemPortAttribs.upQueueID, uint16(gemPortAttribs.weight))
1776 }
1777 } else {
1778 loQueueMap.Set(gemPortAttribs.upQueueID, cu16StrictPrioWeight) //use invalid weight value to indicate SP
1779 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001780 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001781
Girish Gowdra09e5f212021-09-30 16:28:36 -07001782 trafficSchedPtrSetSupported := false
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001783 loOnu2g := oFsm.pOnuDB.GetMe(me.Onu2GClassID, cmn.Onu2gMeID)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001784 if loOnu2g == nil {
1785 logger.Errorw(ctx, "onu2g is nil, cannot read qos configuration flexibility parameter",
1786 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001787 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001788 return
1789 }
1790 returnVal := loOnu2g["QualityOfServiceQosConfigurationFlexibility"]
1791 if returnVal != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001792 if qosCfgFlexParam, err := oFsm.pOnuDB.GetUint16Attrib(returnVal); err == nil {
Girish Gowdra09e5f212021-09-30 16:28:36 -07001793 trafficSchedPtrSetSupported = qosCfgFlexParam&bitTrafficSchedulerPtrSetPermitted == bitTrafficSchedulerPtrSetPermitted
1794 logger.Debugw(ctx, "trafficSchedPtrSetSupported set",
1795 log.Fields{"qosCfgFlexParam": qosCfgFlexParam, "trafficSchedPtrSetSupported": trafficSchedPtrSetSupported})
1796 } else {
1797 logger.Errorw(ctx, "Cannot extract qos configuration flexibility parameter",
1798 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001799 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001800 return
1801 }
1802 } else {
1803 logger.Errorw(ctx, "Cannot read qos configuration flexibility parameter",
1804 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001805 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001806 return
1807 }
1808
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001809 //TODO: assumption here is that ONU data uses SP setting in the T-Cont and WRR in the TrafficScheduler
1810 // if that is not the case, the reverse case could be checked and reacted accordingly or if the
1811 // complete chain is not valid, then some error should be thrown and configuration can be aborted
1812 // or even be finished without correct SP/WRR setting
1813
1814 //TODO: search for the (WRR)trafficScheduler related to the T-Cont of this queue
1815 //By now assume fixed value 0x8000, which is the only announce BBSIM TrafficScheduler,
1816 // even though its T-Cont seems to be wrong ...
1817 loTrafficSchedulerEID := 0x8000
1818 //for all found queues
1819 iter := loQueueMap.IterFunc()
1820 for kv, ok := iter(); ok; kv, ok = iter() {
1821 queueIndex := (kv.Key).(uint16)
1822 meParams := me.ParamData{
1823 EntityID: queueIndex,
Himani Chawla4d908332020-08-31 12:30:20 +05301824 Attributes: make(me.AttributeValueMap),
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001825 }
Girish Gowdra09e5f212021-09-30 16:28:36 -07001826 if trafficSchedPtrSetSupported {
1827 if (kv.Value).(uint16) == cu16StrictPrioWeight {
1828 //StrictPrio indication
1829 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio", log.Fields{
1830 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1831 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001832 meParams.Attributes[me.PriorityQueue_TrafficSchedulerPointer] = 0 //ensure T-Cont defined StrictPrio scheduling
Girish Gowdra09e5f212021-09-30 16:28:36 -07001833 } else {
1834 //WRR indication
1835 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to WRR", log.Fields{
1836 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1837 "Weight": kv.Value,
1838 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001839 meParams.Attributes[me.PriorityQueue_TrafficSchedulerPointer] = loTrafficSchedulerEID //ensure assignment of the relevant trafficScheduler
1840 meParams.Attributes[me.PriorityQueue_Weight] = uint8(kv.Value.(uint16))
Girish Gowdra09e5f212021-09-30 16:28:36 -07001841 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001842 } else {
Girish Gowdra09e5f212021-09-30 16:28:36 -07001843 // setting Traffic Scheduler (TS) pointer is not supported unless we point to another TS that points to the same TCONT.
1844 // 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.
1845 // 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.
1846 if (kv.Value).(uint16) == cu16StrictPrioWeight { // SP case, nothing to be done. Proceed to the next queue
1847 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio, traffic sched ptr set unsupported", log.Fields{
1848 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1849 "device-id": oFsm.deviceID})
1850 continue
1851 }
1852 // WRR case, update weight.
1853 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to WRR, traffic sched ptr set unsupported", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001854 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1855 "Weight": kv.Value,
mpagenko01e726e2020-10-23 09:45:29 +00001856 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001857 meParams.Attributes[me.PriorityQueue_Weight] = uint8(kv.Value.(uint16))
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001858 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001859 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001860 meInstance, err := oFsm.pOmciCC.SendSetPrioQueueVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1861 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001862 if err != nil {
1863 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001864 logger.Errorw(ctx, "PrioQueueVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001865 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001866 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001867 return
1868 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001869 //accept also nil as (error) return value for writing to LastTx
1870 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001871 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001872 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001873
1874 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001875 err = oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001876 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001877 logger.Errorw(ctx, "PrioQueue set failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001878 log.Fields{"device-id": oFsm.deviceID, "QueueId": strconv.FormatInt(int64(queueIndex), 16)})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001879 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001880 return
1881 }
1882
1883 //TODO: In case of WRR setting of the GemPort/PrioQueue it might further be necessary to
1884 // write the assigned trafficScheduler with the requested Prio to be considered in the StrictPrio scheduling
1885 // of the (next upstream) assigned T-Cont, which is f(prioQueue[priority]) - in relation to other SP prioQueues
1886 // not yet done because of BBSIM TrafficScheduler issues (and not done in py code as well)
1887
1888 } //for all upstream prioQueues
mpagenko3dbcdd22020-07-22 07:38:45 +00001889
1890 // if Config has been done for all PrioQueue instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001891 logger.Debugw(ctx, "PrioQueue set loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001892 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxPrioqsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001893}
1894
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001895func (oFsm *UniPonAniConfigFsm) waitforOmciResponse(ctx context.Context) error {
mpagenko7d6bb022021-03-11 15:07:55 +00001896 oFsm.mutexIsAwaitingResponse.Lock()
mpagenkocf48e452021-04-23 09:23:00 +00001897 if oFsm.isCanceled {
1898 // FSM already canceled before entering wait
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001899 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 +00001900 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001901 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenkocf48e452021-04-23 09:23:00 +00001902 }
mpagenko7d6bb022021-03-11 15:07:55 +00001903 oFsm.isAwaitingResponse = true
1904 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko3dbcdd22020-07-22 07:38:45 +00001905 select {
Himani Chawla4d908332020-08-31 12:30:20 +05301906 // maybe be also some outside cancel (but no context modeled for the moment ...)
mpagenko3dbcdd22020-07-22 07:38:45 +00001907 // case <-ctx.Done():
mpagenko01e726e2020-10-23 09:45:29 +00001908 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +00001909 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 +00001910 logger.Warnw(ctx, "UniPonAniConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001911 oFsm.mutexIsAwaitingResponse.Lock()
1912 oFsm.isAwaitingResponse = false
1913 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001914 oFsm.mutexPLastTxMeInstance.RLock()
1915 if oFsm.pLastTxMeInstance != nil {
1916 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureTimeout, oFsm.pLastTxMeInstance.GetClassID(),
1917 oFsm.pLastTxMeInstance.GetEntityID(), oFsm.pLastTxMeInstance.GetClassID().String(), 0)
1918 }
1919 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00001920 return fmt.Errorf("uniPonAniConfigFsm multi entity timeout %s", oFsm.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +00001921 case success := <-oFsm.omciMIdsResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +05301922 if success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001923 logger.Debugw(ctx, "UniPonAniConfigFsm multi entity response received", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001924 oFsm.mutexIsAwaitingResponse.Lock()
1925 oFsm.isAwaitingResponse = false
1926 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko3dbcdd22020-07-22 07:38:45 +00001927 return nil
1928 }
mpagenko7d6bb022021-03-11 15:07:55 +00001929 // waiting was aborted (probably on external request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001930 logger.Debugw(ctx, "UniPonAniConfigFsm wait-for-multi-entity-response aborted", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001931 oFsm.mutexIsAwaitingResponse.Lock()
1932 oFsm.isAwaitingResponse = false
1933 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001934 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenko3dbcdd22020-07-22 07:38:45 +00001935 }
1936}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001937
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001938func (oFsm *UniPonAniConfigFsm) setChanSet(flagValue bool) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001939 oFsm.mutexChanSet.Lock()
1940 oFsm.chanSet = flagValue
1941 oFsm.mutexChanSet.Unlock()
1942}
1943
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001944func (oFsm *UniPonAniConfigFsm) isChanSet() bool {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001945 oFsm.mutexChanSet.RLock()
1946 flagValue := oFsm.chanSet
1947 oFsm.mutexChanSet.RUnlock()
1948 return flagValue
1949}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001950
1951// PrepareForGarbageCollection - remove references to prepare for garbage collection
1952func (oFsm *UniPonAniConfigFsm) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301953 logger.Info(ctx, "prepare for garbage collection", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001954 oFsm.pDeviceHandler = nil
1955 oFsm.pOnuDeviceEntry = nil
1956 oFsm.pOmciCC = nil
1957}