blob: 758c220a8021954031886d5fb94e7e0d571aa88c [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()
bseeniva7d9f8d22025-08-13 11:29:45 +0530364 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
365 go func(aPAFsm *cmn.AdapterFsm) {
366 if aPAFsm != nil && aPAFsm.PFsm != nil {
367 _ = aPAFsm.PFsm.Event(aniEvReset)
368 }
369 }(oFsm.PAdaptFsm)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700370 return
371 }
372 oFsm.tcont0ID = tcontInstID
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700373 logger.Debugw(ctx, "used-tcont-instance-id", log.Fields{"tcont-inst-id": oFsm.tcont0ID,
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +0530374 "alloc-id": oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID,
375 "device-id": oFsm.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800376
mpagenko8b07c1b2020-11-26 10:36:31 +0000377 oFsm.alloc0ID = oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID
378 mapGemPortParams := oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].mapGemPortParams
mpagenko3ce9fa02021-07-28 13:26:54 +0000379 oFsm.pUniTechProf.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800380
Himani Chawla26e555c2020-08-31 12:30:20 +0530381 //for all TechProfile set GemIndices
Girish Gowdra041dcb32020-11-16 16:54:30 -0800382 for _, gemEntry := range mapGemPortParams {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300383 loGemPortAttribs := ponAniGemPortAttribs{}
384
Himani Chawla26e555c2020-08-31 12:30:20 +0530385 //collect all GemConfigData in a separate Fsm related slice (needed also to avoid mix-up with unsorted mapPonAniConfig)
386
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000387 if queueInstKeys := oFsm.pOnuDB.GetSortedInstKeys(ctx, me.PriorityQueueClassID); len(queueInstKeys) > 0 {
Himani Chawla26e555c2020-08-31 12:30:20 +0530388
389 loGemPortAttribs.gemPortID = gemEntry.gemPortID
390 // MibDb usage: upstream PrioQueue.RelatedPort = xxxxyyyy with xxxx=TCont.Entity(incl. slot) and yyyy=prio
391 // i.e.: search PrioQueue list with xxxx=actual T-Cont.Entity,
392 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == yyyy (expect 0..7)
393 usQrelPortMask := uint32((((uint32)(oFsm.tcont0ID)) << 16) + uint32(gemEntry.prioQueueIndex))
394
395 // MibDb usage: downstream PrioQueue.RelatedPort = xxyyzzzz with xx=slot, yy=UniPort and zzzz=prio
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000396 // i.e.: search PrioQueue list with yy=actual pOnuUniPort.UniID,
Himani Chawla26e555c2020-08-31 12:30:20 +0530397 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == zzzz (expect 0..7)
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +0000398 // Note: As we do not maintain any slot numbering, slot number will be excluded from search pattern.
Himani Chawla26e555c2020-08-31 12:30:20 +0530399 // Furthermore OMCI Onu port-Id is expected to start with 1 (not 0).
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000400 dsQrelPortMask := uint32((((uint32)(oFsm.pOnuUniPort.UniID + 1)) << 16) + uint32(gemEntry.prioQueueIndex))
Himani Chawla26e555c2020-08-31 12:30:20 +0530401
402 usQueueFound := false
403 dsQueueFound := false
404 for _, mgmtEntityID := range queueInstKeys {
405 if meAttributes := oFsm.pOnuDB.GetMe(me.PriorityQueueClassID, mgmtEntityID); meAttributes != nil {
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000406 returnVal := meAttributes[me.PriorityQueue_RelatedPort]
Himani Chawla26e555c2020-08-31 12:30:20 +0530407 if returnVal != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000408 if relatedPort, err := oFsm.pOnuDB.GetUint32Attrib(returnVal); err == nil {
Himani Chawla26e555c2020-08-31 12:30:20 +0530409 if relatedPort == usQrelPortMask {
410 loGemPortAttribs.upQueueID = mgmtEntityID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000411 logger.Debugw(ctx, "UpQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
mpagenko01e726e2020-10-23 09:45:29 +0000412 "upQueueID": strconv.FormatInt(int64(loGemPortAttribs.upQueueID), 16), "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530413 usQueueFound = true
414 } else if (relatedPort&0xFFFFFF) == dsQrelPortMask && mgmtEntityID < 0x8000 {
415 loGemPortAttribs.downQueueID = mgmtEntityID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000416 logger.Debugw(ctx, "DownQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
mpagenko01e726e2020-10-23 09:45:29 +0000417 "downQueueID": strconv.FormatInt(int64(loGemPortAttribs.downQueueID), 16), "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530418 dsQueueFound = true
419 }
420 if usQueueFound && dsQueueFound {
421 break
422 }
423 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000424 logger.Warnw(ctx, "Could not convert attribute value", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530425 }
426 } else {
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000427 logger.Warnw(ctx, "PrioQueue.RelatedPort not found in meAttributes:", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530428 }
429 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000430 logger.Warnw(ctx, "No attributes available in DB:", log.Fields{"meClassID": me.PriorityQueueClassID,
mpagenko01e726e2020-10-23 09:45:29 +0000431 "mgmtEntityID": mgmtEntityID, "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530432 }
433 }
434 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000435 logger.Warnw(ctx, "No PriorityQueue instances found", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530436 }
437 loGemPortAttribs.direction = gemEntry.direction
438 loGemPortAttribs.qosPolicy = gemEntry.queueSchedPolicy
439 loGemPortAttribs.weight = gemEntry.queueWeight
440 loGemPortAttribs.pbitString = gemEntry.pbitString
ozgecanetsia82b91a62021-05-21 18:54:49 +0300441
ozgecanetsia4b232302020-11-11 10:58:10 +0300442 if gemEntry.isMulticast {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300443 //TODO this might effectively ignore the for loop starting at line 316
444 loGemPortAttribs.gemPortID = gemEntry.multicastGemPortID
ozgecanetsia4b232302020-11-11 10:58:10 +0300445 loGemPortAttribs.isMulticast = true
446 loGemPortAttribs.multicastGemID = gemEntry.multicastGemPortID
447 loGemPortAttribs.staticACL = gemEntry.staticACL
448 loGemPortAttribs.dynamicACL = gemEntry.dynamicACL
Himani Chawla26e555c2020-08-31 12:30:20 +0530449
dbainbri4d3a0dc2020-12-02 00:33:42 +0000450 logger.Debugw(ctx, "Multicast GemPort attributes:", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300451 "gemPortID": loGemPortAttribs.gemPortID,
452 "isMulticast": loGemPortAttribs.isMulticast,
453 "multicastGemID": loGemPortAttribs.multicastGemID,
454 "staticACL": loGemPortAttribs.staticACL,
455 "dynamicACL": loGemPortAttribs.dynamicACL,
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000456 "device-id": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300457 })
458
459 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000460 logger.Debugw(ctx, "Upstream GemPort attributes:", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300461 "gemPortID": loGemPortAttribs.gemPortID,
462 "upQueueID": loGemPortAttribs.upQueueID,
463 "downQueueID": loGemPortAttribs.downQueueID,
464 "pbitString": loGemPortAttribs.pbitString,
465 "prioQueueIndex": gemEntry.prioQueueIndex,
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000466 "device-id": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300467 })
468 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530469
470 oFsm.gemPortAttribsSlice = append(oFsm.gemPortAttribsSlice, loGemPortAttribs)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530471 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
472 meParams := me.ParamData{
473 EntityID: loGemPortAttribs.gemPortID,
474 Attributes: me.AttributeValueMap{
475 me.GemPortNetworkCtp_PortId: loGemPortAttribs.gemPortID,
476 me.GemPortNetworkCtp_TContPointer: oFsm.tcont0ID,
477 me.GemPortNetworkCtp_Direction: loGemPortAttribs.direction,
478 me.GemPortNetworkCtp_TrafficManagementPointerForUpstream: loGemPortAttribs.upQueueID,
479 me.GemPortNetworkCtp_PriorityQueuePointerForDownStream: loGemPortAttribs.downQueueID,
480 },
481 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530482 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpClassID, loGemPortAttribs.gemPortID, meParams.Attributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530483 var meAttributes me.AttributeValueMap //dummy , anyways we are not going to use the values.
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530484 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID, loGemPortAttribs.gemPortID, meAttributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530485
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530486 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemInterworkingTerminationPointClassID, loGemPortAttribs.gemPortID, meAttributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530487
488 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530489 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000490 if !oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
balaji.nagarajanca025612025-06-23 16:16:06 +0530491 //let the state machine run forward from here directly
492 if oFsm.PAdaptFsm != nil {
493 go func(aPAFsm *cmn.AdapterFsm) {
494 if aPAFsm != nil && aPAFsm.PFsm != nil {
495 _ = aPAFsm.PFsm.Event(aniEvStartConfig)
496 }
497 }(oFsm.PAdaptFsm)
498
499 }
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000500 } else {
501 logger.Debugw(ctx, "reconciling - skip omci-config of ANI side ", log.Fields{"device-id": oFsm.deviceID})
balaji.nagarajanca025612025-06-23 16:16:06 +0530502 //let the state machine run forward from here directly
503 if oFsm.PAdaptFsm != nil {
504 go func(aPAFsm *cmn.AdapterFsm) {
505 if aPAFsm != nil && aPAFsm.PFsm != nil {
506 _ = aPAFsm.PFsm.Event(aniEvSkipOmciConfig)
507 }
508 }(oFsm.PAdaptFsm)
509
510 }
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000511 }
balaji.nagarajanca025612025-06-23 16:16:06 +0530512 logger.Info(ctx, "UniPonAniConfigFsm prepareAndEnterConfigState end", log.Fields{
513 "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530514 }
515}
516
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530517//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000518func (oFsm *UniPonAniConfigFsm) enterConfigStartingState(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530519 logger.Info(ctx, "UniPonAniConfigFsm start", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000520 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000521 // in case the used channel is not yet defined (can be re-used after restarts)
522 if oFsm.omciMIdsResponseReceived == nil {
523 oFsm.omciMIdsResponseReceived = make(chan bool)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000524 logger.Debug(ctx, "UniPonAniConfigFsm - OMCI multiInstance RxChannel defined")
mpagenko3dbcdd22020-07-22 07:38:45 +0000525 } else {
526 // as we may 're-use' this instance of FSM and the connected channel
527 // make sure there is no 'lingering' request in the already existing channel:
528 // (simple loop sufficient as we are the only receiver)
529 for len(oFsm.omciMIdsResponseReceived) > 0 {
530 <-oFsm.omciMIdsResponseReceived
531 }
532 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000533 //ensure internal slices are empty (which might be set from previous run) - release memory
534 oFsm.gemPortAttribsSlice = nil
mpagenkocf48e452021-04-23 09:23:00 +0000535 oFsm.mutexIsAwaitingResponse.Lock()
536 //reset the canceled state possibly existing from previous reset
537 oFsm.isCanceled = false
538 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000539
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000540 // start go routine for processing of ANI config messages
dbainbri4d3a0dc2020-12-02 00:33:42 +0000541 go oFsm.processOmciAniMessages(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000542
543 //let the state machine run forward from here directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000544 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000545 if pConfigAniStateAFsm != nil {
546 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
balaji.nagarajanca025612025-06-23 16:16:06 +0530547 go func(aPAFsm *cmn.AdapterFsm) {
548 if aPAFsm != nil && aPAFsm.PFsm != nil {
549 _ = aPAFsm.PFsm.Event(aniEvPrepareConfig)
550 }
551 }(pConfigAniStateAFsm)
mpagenko3dbcdd22020-07-22 07:38:45 +0000552
mpagenko3dbcdd22020-07-22 07:38:45 +0000553 }
554}
555
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530556//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000557func (oFsm *UniPonAniConfigFsm) enterCreatingDot1PMapper(ctx context.Context, e *fsm.Event) {
558 logger.Debugw(ctx, "UniPonAniConfigFsm Tx Create::Dot1PMapper", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000559 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000560 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000561 oFsm.requestEventOffset = 0 //0 offset for last config request activity
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000562 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000563 meInstance, err := oFsm.pOmciCC.SendCreateDot1PMapper(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
564 oFsm.mapperSP0ID, oFsm.PAdaptFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300565 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000566 logger.Errorw(ctx, "Dot1PMapper create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300567 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000568 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300569 if pConfigAniStateAFsm != nil {
570 oFsm.mutexPLastTxMeInstance.Unlock()
571 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000572 go func(aPAFsm *cmn.AdapterFsm) {
573 if aPAFsm != nil && aPAFsm.PFsm != nil {
574 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300575 }
576 }(pConfigAniStateAFsm)
577 return
578 }
579 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000580 //accept also nil as (error) return value for writing to LastTx
581 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000582 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300583 oFsm.mutexPLastTxMeInstance.Unlock()
584
mpagenko3dbcdd22020-07-22 07:38:45 +0000585}
586
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530587//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000588func (oFsm *UniPonAniConfigFsm) enterCreatingMBPCD(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530589 logger.Info(ctx, "Creating Tx MAC Bridge Port Config Data", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000590 "EntitytId": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16),
591 "TPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000592 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
593 bridgePtr := cmn.MacBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.MacBpNo) //cmp also omci_cc.go::sendCreateMBServiceProfile
bseeniva5f32c452025-07-18 17:30:41 +0530594 // generate unique MacBpNo from tech profile ID for ANI side
595 macBpNo, macBpNoErr := cmn.GenerateANISideMBPCDPortNo(uint16(oFsm.techProfileID))
596 if macBpNoErr != nil {
597 logger.Warn(ctx, "Failed to generate MAC bridge port number, Will set the port-number to 0xFF", log.Fields{
598 "device-id": oFsm.deviceID,
599 "uni-id": oFsm.pOnuUniPort.UniID,
600 "error": macBpNoErr,
601 })
602 macBpNo = 0xFF
603 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000604 meParams := me.ParamData{
605 EntityID: oFsm.macBPCD0ID,
606 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000607 me.MacBridgePortConfigurationData_BridgeIdPointer: bridgePtr,
bseeniva5f32c452025-07-18 17:30:41 +0530608 me.MacBridgePortConfigurationData_PortNum: uint8(macBpNo), //fixed unique ANI side indication
609 me.MacBridgePortConfigurationData_TpType: 3, //for .1PMapper
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000610 me.MacBridgePortConfigurationData_TpPointer: oFsm.mapperSP0ID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000611 },
612 }
bseeniva5f32c452025-07-18 17:30:41 +0530613
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000614 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000615 meInstance, err := oFsm.pOmciCC.SendCreateMBPConfigDataVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
616 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300617 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000618 logger.Errorw(ctx, "MBPConfigDataVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300619 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000620 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300621 if pConfigAniStateAFsm != nil {
622 oFsm.mutexPLastTxMeInstance.Unlock()
623 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000624 go func(aPAFsm *cmn.AdapterFsm) {
625 if aPAFsm != nil && aPAFsm.PFsm != nil {
626 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300627 }
628 }(pConfigAniStateAFsm)
629 return
630 }
631 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000632 //accept also nil as (error) return value for writing to LastTx
633 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000634 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300635 oFsm.mutexPLastTxMeInstance.Unlock()
636
mpagenko3dbcdd22020-07-22 07:38:45 +0000637}
638
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530639//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000640func (oFsm *UniPonAniConfigFsm) enterSettingTconts(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530641 logger.Info(ctx, "Tx Setting Tcont ", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000642 "EntitytId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
643 "AllocId": strconv.FormatInt(int64(oFsm.alloc0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000644 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700645 "tcontExist": oFsm.tcontSetBefore})
646 //If tcont was set before, then no need to set it again. Let state machine to proceed.
647 if oFsm.tcontSetBefore {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000648 go func(aPAFsm *cmn.AdapterFsm) {
649 if aPAFsm != nil && aPAFsm.PFsm != nil {
650 _ = aPAFsm.PFsm.Event(aniEvRxTcontsResp)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700651 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000652 }(oFsm.PAdaptFsm)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700653 return
654 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000655 meParams := me.ParamData{
656 EntityID: oFsm.tcont0ID,
657 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000658 me.TCont_AllocId: oFsm.alloc0ID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000659 },
660 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000661 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000662 meInstance, err := oFsm.pOmciCC.SendSetTcontVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
663 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300664 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000665 logger.Errorw(ctx, "TcontVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300666 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000667 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300668 if pConfigAniStateAFsm != nil {
669 oFsm.mutexPLastTxMeInstance.Unlock()
670 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000671 go func(aPAFsm *cmn.AdapterFsm) {
672 if aPAFsm != nil && aPAFsm.PFsm != nil {
673 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300674 }
675 }(pConfigAniStateAFsm)
676 return
677 }
678 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000679 //accept also nil as (error) return value for writing to LastTx
680 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000681 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300682 oFsm.mutexPLastTxMeInstance.Unlock()
683
mpagenko3dbcdd22020-07-22 07:38:45 +0000684}
685
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530686//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000687func (oFsm *UniPonAniConfigFsm) enterCreatingGemNCTPs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530688 logger.Info(ctx, "UniPonAniConfigFsm - start creating GemNWCtp loop", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000689 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000690 go oFsm.performCreatingGemNCTPs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000691}
692
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530693//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000694func (oFsm *UniPonAniConfigFsm) enterCreatingGemIWs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530695 logger.Info(ctx, "UniPonAniConfigFsm - start creating GemIwTP loop", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000696 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000697 go oFsm.performCreatingGemIWs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000698}
699
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000700func (oFsm *UniPonAniConfigFsm) enterSettingPQs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530701 logger.Info(ctx, "UniPonAniConfigFsm - start setting PrioQueue loop", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000702 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000703 go oFsm.performSettingPQs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000704}
705
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000706func (oFsm *UniPonAniConfigFsm) enterSettingDot1PMapper(ctx context.Context, e *fsm.Event) {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300707
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530708 logger.Info(ctx, "UniPonAniConfigFsm Tx Set::.1pMapper with all PBits set", log.Fields{"EntitytId": 0x8042, /*cmp above*/
mpagenko8b07c1b2020-11-26 10:36:31 +0000709 "toGemIw": 1024, /* cmp above */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000710 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000711
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530712 logger.Info(ctx, "UniPonAniConfigFsm Tx Set::1pMapper", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000713 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +0000714 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000715
mpagenko3dbcdd22020-07-22 07:38:45 +0000716 meParams := me.ParamData{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000717 EntityID: oFsm.mapperSP0ID,
Himani Chawla4d908332020-08-31 12:30:20 +0530718 Attributes: make(me.AttributeValueMap),
mpagenko3dbcdd22020-07-22 07:38:45 +0000719 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000720
721 //assign the GemPorts according to the configured Prio
722 var loPrioGemPortArray [8]uint16
723 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300724 if gemPortAttribs.isMulticast {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000725 logger.Debugw(ctx, "UniPonAniConfigFsm Port is Multicast, ignoring .1pMapper", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300726 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
727 "prioString": gemPortAttribs.pbitString})
728 continue
729 }
730 if gemPortAttribs.pbitString == "" {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000731 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString empty string error", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300732 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
733 "prioString": gemPortAttribs.pbitString})
734 continue
735 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000736 for i := 0; i < 8; i++ {
737 // "lenOfPbitMap(8) - i + 1" will give i-th pbit value from LSB position in the pbit map string
738 if prio, err := strconv.Atoi(string(gemPortAttribs.pbitString[7-i])); err == nil {
739 if prio == 1 { // Check this p-bit is set
740 if loPrioGemPortArray[i] == 0 {
741 loPrioGemPortArray[i] = gemPortAttribs.gemPortID //gemPortId=EntityID and unique
742 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000743 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString not unique", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000744 "device-id": oFsm.deviceID, "IgnoredGemPort": gemPortAttribs.gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000745 "SetGemPort": loPrioGemPortArray[i]})
746 }
747 }
748 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000749 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString evaluation error", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000750 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000751 "prioString": gemPortAttribs.pbitString, "position": i})
752 }
753
754 }
755 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300756
ozgecanetsia4b232302020-11-11 10:58:10 +0300757 var foundIwPtr = false
Himani Chawla4d908332020-08-31 12:30:20 +0530758 for index, value := range loPrioGemPortArray {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300759 meAttribute := fmt.Sprintf("InterworkTpPointerForPBitPriority%d", index)
Himani Chawla4d908332020-08-31 12:30:20 +0530760 if value != 0 {
761 foundIwPtr = true
Himani Chawla4d908332020-08-31 12:30:20 +0530762 meParams.Attributes[meAttribute] = value
dbainbri4d3a0dc2020-12-02 00:33:42 +0000763 logger.Debugw(ctx, "UniPonAniConfigFsm Set::1pMapper", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000764 "for Prio": index,
765 "IwPtr": strconv.FormatInt(int64(value), 16),
766 "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300767 } else {
768 // The null pointer 0xFFFF specifies that frames with the associated priority are to be discarded.
mpagenko8b5fdd22020-12-17 17:58:32 +0000769 // setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting
770 // but except for processing effort does not really harm - left to keep changes low
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300771 meParams.Attributes[meAttribute] = 0xffff
Himani Chawla4d908332020-08-31 12:30:20 +0530772 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000773 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300774 // The TP type value 0 also indicates bridging mapping, and the TP pointer should be set to 0xFFFF
mpagenko8b5fdd22020-12-17 17:58:32 +0000775 // setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting
776 // but except for processing effort does not really harm - left to keep changes low
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000777 meParams.Attributes[me.Ieee8021PMapperServiceProfile_TpPointer] = 0xffff
Himani Chawla4d908332020-08-31 12:30:20 +0530778
779 if !foundIwPtr {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530780 logger.Warn(ctx, "UniPonAniConfigFsm no GemIwPtr found for .1pMapper - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000781 "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300782 //TODO With multicast is possible that no upstream gem ports are not present in the tech profile,
783 // 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 +0000784 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000785 //pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300786 //if pConfigAniStateAFsm != nil {
787 // // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000788 // go func(aPAFsm *cmn.AdapterFsm) {
789 // if aPAFsm != nil && aPAFsm.PFsm != nil {
790 // _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300791 // }
792 // }(pConfigAniStateAFsm)
793 //}
794 //Moving forward the FSM as if the response was received correctly.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000795 pConfigAniStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000796 if pConfigAniStateAFsm != nil {
797 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000798 go func(aPAFsm *cmn.AdapterFsm) {
799 if aPAFsm != nil && aPAFsm.PFsm != nil {
800 _ = aPAFsm.PFsm.Event(aniEvRxDot1pmapSResp)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000801 }
802 }(pConfigAniStateAFsm)
803 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300804 } else {
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000805 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000806 meInstance, err := oFsm.pOmciCC.SendSetDot1PMapperVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(), true,
807 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300808 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000809 logger.Errorw(ctx, "Dot1PMapperVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300810 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000811 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300812 if pConfigAniStateAFsm != nil {
813 oFsm.mutexPLastTxMeInstance.Unlock()
814 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000815 go func(aPAFsm *cmn.AdapterFsm) {
816 if aPAFsm != nil && aPAFsm.PFsm != nil {
817 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300818 }
819 }(pConfigAniStateAFsm)
820 return
821 }
822 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300823 //accept also nil as (error) return value for writing to LastTx
824 // - this avoids misinterpretation of new received OMCI messages
825 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300826 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000827 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000828}
829
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000830func (oFsm *UniPonAniConfigFsm) enterAniConfigDone(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530831 logger.Info(ctx, "UniPonAniConfigFsm ani config done", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000832 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenko01e726e2020-10-23 09:45:29 +0000833 //store that the UNI related techProfile processing is done for the given Profile and Uni
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000834 oFsm.pUniTechProf.setConfigDone(oFsm.pOnuUniPort.UniID, oFsm.techProfileID, true)
835 if !oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000836 //use DeviceHandler event notification directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000837 oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset)))
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000838 //if techProfile processing is done it must be checked, if some prior/parallel flow configuration is pending
839 // but only in case the techProfile was configured (not deleted)
840 if oFsm.requestEventOffset == 0 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000841 go oFsm.pDeviceHandler.VerifyUniVlanConfigRequest(ctx, oFsm.pOnuUniPort, oFsm.techProfileID)
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000842 }
843 } else {
844 logger.Debugw(ctx, "reconciling - skip AniConfigDone processing", log.Fields{"device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000845 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000846 if oFsm.isChanSet() {
mpagenko01e726e2020-10-23 09:45:29 +0000847 // indicate processing done to the caller
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000848 logger.Debugw(ctx, "UniPonAniConfigFsm processingDone on channel", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000849 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
850 oFsm.chSuccess <- oFsm.procStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000851 oFsm.setChanSet(false) //reset the internal channel state
mpagenko3dbcdd22020-07-22 07:38:45 +0000852 }
mpagenko01e726e2020-10-23 09:45:29 +0000853
854 //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 +0000855}
856
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530857//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000858func (oFsm *UniPonAniConfigFsm) enterRemovingGemIW(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +0000859 // no need to protect access to oFsm.waitFlowDeleteChannel, only used in synchronized state entries
860 // or CancelProcessing() that uses separate isWaitingForFlowDelete to write to the channel
mpagenkobb47bc22021-04-20 13:29:09 +0000861 //flush the waitFlowDeleteChannel - possibly already/still set by some previous activity
862 select {
863 case <-oFsm.waitFlowDeleteChannel:
864 logger.Debug(ctx, "flushed waitFlowDeleteChannel")
865 default:
866 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000867
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000868 uniVlanConfigFsm := oFsm.pDeviceHandler.GetUniVlanConfigFsm(oFsm.pOnuUniPort.UniID)
869 if uniVlanConfigFsm != nil {
mpagenko3ce9fa02021-07-28 13:26:54 +0000870 // ensure mutexTPState not locked before calling some VlanConfigFsm activity (that might already be pending on it)
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000871 if uniVlanConfigFsm.IsFlowRemovePending(ctx, oFsm.waitFlowDeleteChannel) {
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000872 logger.Debugw(ctx, "flow remove pending - wait before processing gem port delete",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000873 log.Fields{"device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000874 // 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 +0000875 pConfigAniStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000876 if pConfigAniStateAFsm != nil {
877 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000878 go func(aPAFsm *cmn.AdapterFsm) {
879 if aPAFsm != nil && aPAFsm.PFsm != nil {
880 _ = aPAFsm.PFsm.Event(aniEvWaitFlowRem)
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000881 }
882 }(pConfigAniStateAFsm)
883 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000884 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 +0000885 }
886 return
Girish Gowdra26a40922021-01-29 17:14:34 -0800887 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000888 } else {
889 logger.Debugw(ctx, "uni vlan config doesn't exist - no flow remove could be pending",
890 log.Fields{"device-id": oFsm.deviceID, "techProfile-id": oFsm.techProfileID})
Girish Gowdra26a40922021-01-29 17:14:34 -0800891 }
892
mpagenko3ce9fa02021-07-28 13:26:54 +0000893 oFsm.pUniTechProf.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000894 // get the related GemPort entity Id from pUniTechProf, OMCI Gem* entityID is set to be equal to GemPortId!
mpagenko8b07c1b2020-11-26 10:36:31 +0000895 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +0000896 oFsm.pUniTechProf.mutexTPState.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000897 logger.Debugw(ctx, "UniPonAniConfigFsm - start removing one GemIwTP", log.Fields{
898 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko8b07c1b2020-11-26 10:36:31 +0000899 "GemIwTp-entity-id": loGemPortID})
900 oFsm.requestEventOffset = 1 //offset 1 to indicate last activity = remove
901
902 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000903 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000904 meInstance, err := oFsm.pOmciCC.SendDeleteGemIWTP(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
905 oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300906 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000907 logger.Errorw(ctx, "GemIWTP delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300908 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000909 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300910 if pConfigAniStateAFsm != nil {
911 oFsm.mutexPLastTxMeInstance.Unlock()
912 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000913 go func(aPAFsm *cmn.AdapterFsm) {
914 if aPAFsm != nil && aPAFsm.PFsm != nil {
915 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300916 }
917 }(pConfigAniStateAFsm)
918 return
919 }
920 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000921 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300922 oFsm.mutexPLastTxMeInstance.Unlock()
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530923 logger.Infow(ctx, "Deleting GemIWTP at the ONU DB ", log.Fields{"device-id": oFsm.deviceID, "GEMID": loGemPortID})
924 oFsm.pOnuDB.DeleteMe(me.GemInterworkingTerminationPointClassID, loGemPortID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000925}
926
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530927//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000928func (oFsm *UniPonAniConfigFsm) enterWaitingFlowRem(ctx context.Context, e *fsm.Event) {
mpagenkobb47bc22021-04-20 13:29:09 +0000929 oFsm.mutexIsAwaitingResponse.Lock()
930 oFsm.isWaitingForFlowDelete = true
931 oFsm.mutexIsAwaitingResponse.Unlock()
932 select {
933 // maybe be also some outside cancel (but no context modeled for the moment ...)
934 // case <-ctx.Done():
935 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000936 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 +0000937 logger.Warnw(ctx, "UniPonAniConfigFsm WaitingFlowRem timeout", log.Fields{
938 "for device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000939 oFsm.mutexIsAwaitingResponse.Lock()
940 oFsm.isWaitingForFlowDelete = false
941 oFsm.mutexIsAwaitingResponse.Unlock()
942 //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 +0000943 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000944 if pConfigAniStateAFsm != nil {
945 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000946 go func(aPAFsm *cmn.AdapterFsm) {
947 if aPAFsm != nil && aPAFsm.PFsm != nil {
948 _ = aPAFsm.PFsm.Event(aniEvFlowRemDone)
mpagenkobb47bc22021-04-20 13:29:09 +0000949 }
950 }(pConfigAniStateAFsm)
951 } else {
952 logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000953 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000954 }
955 return
956
957 case success := <-oFsm.waitFlowDeleteChannel:
958 if success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000959 logger.Debugw(ctx, "UniPonAniConfigFsm flow removed info received", log.Fields{
960 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000961 oFsm.mutexIsAwaitingResponse.Lock()
962 oFsm.isWaitingForFlowDelete = false
963 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000964 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000965 if pConfigAniStateAFsm != nil {
966 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000967 go func(aPAFsm *cmn.AdapterFsm) {
968 if aPAFsm != nil && aPAFsm.PFsm != nil {
969 _ = aPAFsm.PFsm.Event(aniEvFlowRemDone)
mpagenkobb47bc22021-04-20 13:29:09 +0000970 }
971 }(pConfigAniStateAFsm)
972 } else {
973 logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000974 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000975 }
976 return
977 }
978 // waiting was aborted (probably on external request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000979 logger.Debugw(ctx, "UniPonAniConfigFsm WaitingFlowRem aborted", log.Fields{
980 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000981 oFsm.mutexIsAwaitingResponse.Lock()
982 oFsm.isWaitingForFlowDelete = false
983 oFsm.mutexIsAwaitingResponse.Unlock()
984 //to be sure we can just generate the reset-event to ensure leaving this state towards 'reset'
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000985 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000986 if pConfigAniStateAFsm != nil {
987 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000988 go func(aPAFsm *cmn.AdapterFsm) {
989 if aPAFsm != nil && aPAFsm.PFsm != nil {
990 _ = aPAFsm.PFsm.Event(aniEvReset)
mpagenkobb47bc22021-04-20 13:29:09 +0000991 }
992 }(pConfigAniStateAFsm)
993 }
994 return
995 }
996}
997
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530998//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000999func (oFsm *UniPonAniConfigFsm) enterRemovingGemNCTP(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +00001000 oFsm.pUniTechProf.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +00001001 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +00001002 oFsm.pUniTechProf.mutexTPState.RUnlock()
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301003 logger.Info(ctx, "UniPonAniConfigFsm - start removing one GemNCTP", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001004 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko8b07c1b2020-11-26 10:36:31 +00001005 "GemNCTP-entity-id": loGemPortID})
1006 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001007 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001008 meInstance, err := oFsm.pOmciCC.SendDeleteGemNCTP(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1009 oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001010 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001011 logger.Errorw(ctx, "GemNCTP delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001012 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001013 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001014 if pConfigAniStateAFsm != nil {
1015 oFsm.mutexPLastTxMeInstance.Unlock()
1016 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001017 go func(aPAFsm *cmn.AdapterFsm) {
1018 if aPAFsm != nil && aPAFsm.PFsm != nil {
1019 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001020 }
1021 }(pConfigAniStateAFsm)
1022 return
1023 }
1024 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001025 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001026 oFsm.mutexPLastTxMeInstance.Unlock()
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301027 oFsm.pOnuDB.DeleteMe(me.GemPortNetworkCtpClassID, loGemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001028 // Mark the gem port to be removed for Performance History monitoring
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001029 OnuMetricsManager := oFsm.pDeviceHandler.GetOnuMetricsManager()
1030 if OnuMetricsManager != nil {
1031 OnuMetricsManager.RemoveGemPortForPerfMonitoring(ctx, loGemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001032 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001033}
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301034
1035//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001036func (oFsm *UniPonAniConfigFsm) enterRemovingTD(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +00001037 oFsm.pUniTechProf.mutexTPState.RLock()
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001038 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +00001039 oFsm.pUniTechProf.mutexTPState.RUnlock()
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301040 logger.Info(ctx, "UniPonAniConfigFsm - start removing Traffic Descriptor", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001041 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001042 "TD-entity-id": loGemPortID})
1043
1044 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001045 meInstance, err := oFsm.pOmciCC.SendDeleteTD(log.WithSpanFromContext(context.TODO(), ctx),
1046 oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001047
1048 if err != nil {
1049 logger.Errorw(ctx, "TD delete failed - proceed fsm",
1050 log.Fields{"device-id": oFsm.deviceID, "gemPortID": loGemPortID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001051 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001052 if pConfigAniStateAFsm != nil {
1053 oFsm.mutexPLastTxMeInstance.Unlock()
1054 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001055 go func(aPAFsm *cmn.AdapterFsm) {
1056 if aPAFsm != nil && aPAFsm.PFsm != nil {
1057 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001058 }
1059 }(pConfigAniStateAFsm)
1060 return
1061 }
1062 }
1063 oFsm.pLastTxMeInstance = meInstance
1064 oFsm.mutexPLastTxMeInstance.Unlock()
1065}
mpagenko8b07c1b2020-11-26 10:36:31 +00001066
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301067//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001068func (oFsm *UniPonAniConfigFsm) enterResettingTcont(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301069 logger.Info(ctx, "UniPonAniConfigFsm - start resetting the TCont", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001070 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001071
1072 oFsm.requestEventOffset = 1 //offset 1 for last remove activity
1073 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
1074 meParams := me.ParamData{
1075 EntityID: oFsm.tcont0ID,
1076 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001077 me.TCont_AllocId: cmn.UnusedTcontAllocID,
mpagenko8b07c1b2020-11-26 10:36:31 +00001078 },
1079 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001080 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001081 meInstance, err := oFsm.pOmciCC.SendSetTcontVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1082 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001083 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001084 logger.Errorw(ctx, "TcontVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001085 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001086 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001087 if pConfigAniStateAFsm != nil {
1088 oFsm.mutexPLastTxMeInstance.Unlock()
1089 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001090 go func(aPAFsm *cmn.AdapterFsm) {
1091 if aPAFsm != nil && aPAFsm.PFsm != nil {
1092 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001093 }
1094 }(pConfigAniStateAFsm)
1095 return
1096 }
1097 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001098 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001099 oFsm.mutexPLastTxMeInstance.Unlock()
1100
mpagenko8b07c1b2020-11-26 10:36:31 +00001101}
1102
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301103//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001104func (oFsm *UniPonAniConfigFsm) enterRemoving1pMapper(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301105 logger.Info(ctx, "UniPonAniConfigFsm - start deleting the .1pMapper", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001106 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
bseenivaeba8eb12024-12-13 11:54:28 +05301107 var mapGemPortParams map[uint16]*gemPortParamStruct
Mahir Gunyel9545be22021-07-04 15:53:16 -07001108 unicastGemCount := 0
bseenivaeba8eb12024-12-13 11:54:28 +05301109 oFsm.pUniTechProf.mutexTPState.RLock()
1110 if _, ok := oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey]; ok {
1111 mapGemPortParams = oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].mapGemPortParams
1112 } else {
1113 logger.Warnw(ctx, "GemPortParams not found in mapPonAniConfig", log.Fields{"device-id": oFsm.deviceID,
1114 "uni-id": oFsm.pOnuUniPort.UniID})
1115 }
1116 oFsm.pUniTechProf.mutexTPState.RUnlock()
Mahir Gunyel9545be22021-07-04 15:53:16 -07001117 for _, gemEntry := range mapGemPortParams {
1118 if !gemEntry.isMulticast {
1119 unicastGemCount++
1120 }
1121 }
1122 if unicastGemCount > 1 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001123 logger.Debugw(ctx, "UniPonAniConfigFsm - Not the last gem in fsm. Skip the rest", log.Fields{
1124 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "unicast-gem-count": unicastGemCount, "gem-count": len(mapGemPortParams)})
1125 pConfigAniStateAFsm := oFsm.PAdaptFsm
Mahir Gunyel9545be22021-07-04 15:53:16 -07001126 if pConfigAniStateAFsm != nil {
1127 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001128 go func(aPAFsm *cmn.AdapterFsm) {
1129 if aPAFsm != nil && aPAFsm.PFsm != nil {
1130 _ = aPAFsm.PFsm.Event(aniEvRemGemDone)
Mahir Gunyel9545be22021-07-04 15:53:16 -07001131 }
1132 }(pConfigAniStateAFsm)
1133 return
1134 }
1135 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001136 logger.Debugw(ctx, "UniPonAniConfigFsm - Last gem in fsm. Continue with Mapper removal", log.Fields{
1137 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "unicast-gem-count": unicastGemCount, "gem-count": len(mapGemPortParams)})
mpagenko8b07c1b2020-11-26 10:36:31 +00001138
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001139 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001140 meInstance, err := oFsm.pOmciCC.SendDeleteDot1PMapper(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1141 oFsm.PAdaptFsm.CommChan, oFsm.mapperSP0ID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001142 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001143 logger.Errorw(ctx, "Dot1Mapper delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001144 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001145 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001146 if pConfigAniStateAFsm != nil {
1147 oFsm.mutexPLastTxMeInstance.Unlock()
1148 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001149 go func(aPAFsm *cmn.AdapterFsm) {
1150 if aPAFsm != nil && aPAFsm.PFsm != nil {
1151 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001152 }
1153 }(pConfigAniStateAFsm)
1154 return
1155 }
1156 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001157 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001158 oFsm.mutexPLastTxMeInstance.Unlock()
1159
mpagenko8b07c1b2020-11-26 10:36:31 +00001160}
1161
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301162//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001163func (oFsm *UniPonAniConfigFsm) enterRemovingAniBPCD(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301164 logger.Info(ctx, "UniPonAniConfigFsm - start deleting the ANI MBCD", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001165 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001166
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001167 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001168 meInstance, err := oFsm.pOmciCC.SendDeleteMBPConfigData(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1169 oFsm.PAdaptFsm.CommChan, oFsm.macBPCD0ID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001170 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001171 logger.Errorw(ctx, "MBPConfigData delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001172 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001173 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001174 if pConfigAniStateAFsm != nil {
1175 oFsm.mutexPLastTxMeInstance.Unlock()
1176 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001177 go func(aPAFsm *cmn.AdapterFsm) {
1178 if aPAFsm != nil && aPAFsm.PFsm != nil {
1179 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001180 }
1181 }(pConfigAniStateAFsm)
1182 return
1183 }
1184 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001185 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001186 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +00001187}
1188
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001189func (oFsm *UniPonAniConfigFsm) enterAniRemoveDone(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301190 logger.Info(ctx, "UniPonAniConfigFsm ani removal done", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001191 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001192 //use DeviceHandler event notification directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001193 oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset)))
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001194 if oFsm.isChanSet() {
mpagenko8b07c1b2020-11-26 10:36:31 +00001195 // indicate processing done to the caller
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001196 logger.Debugw(ctx, "UniPonAniConfigFsm processingDone on channel", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +00001197 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
1198 oFsm.chSuccess <- oFsm.procStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001199 oFsm.setChanSet(false) //reset the internal channel state
mpagenko8b07c1b2020-11-26 10:36:31 +00001200 }
1201
1202 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001203 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko8b07c1b2020-11-26 10:36:31 +00001204 if pConfigAniStateAFsm != nil {
1205 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001206 go func(aPAFsm *cmn.AdapterFsm) {
1207 if aPAFsm != nil && aPAFsm.PFsm != nil {
1208 _ = aPAFsm.PFsm.Event(aniEvReset)
mpagenko8b07c1b2020-11-26 10:36:31 +00001209 }
1210 }(pConfigAniStateAFsm)
1211 }
1212}
1213
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001214func (oFsm *UniPonAniConfigFsm) enterResettingState(ctx context.Context, e *fsm.Event) {
1215 logger.Debugw(ctx, "UniPonAniConfigFsm resetting", log.Fields{
1216 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001217
mpagenko45cc6a32021-07-23 10:06:57 +00001218 if oFsm.isChanSet() {
1219 // indicate processing error to the caller (in case there was still some open request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001220 logger.Debugw(ctx, "UniPonAniConfigFsm processingError on channel", log.Fields{
mpagenko45cc6a32021-07-23 10:06:57 +00001221 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
1222 //use non-blocking channel send to avoid blocking because of non-existing receiver
1223 // (even though the channel is checked on 'set', the outside receiver channel might (theoretically) already be deleted)
1224 select {
1225 case oFsm.chSuccess <- 0:
1226 default:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001227 logger.Debugw(ctx, "UniPonAniConfigFsm processingError not send on channel (no receiver)", log.Fields{
mpagenko45cc6a32021-07-23 10:06:57 +00001228 "device-id": oFsm.deviceID})
1229 }
1230 oFsm.setChanSet(false) //reset the internal channel state
1231 }
1232
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001233 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko3dbcdd22020-07-22 07:38:45 +00001234 if pConfigAniStateAFsm != nil {
1235 // abort running message processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001236 fsmAbortMsg := cmn.Message{
1237 Type: cmn.TestMsg,
1238 Data: cmn.TestMessage{
1239 TestMessageVal: cmn.AbortMessageProcessing,
mpagenko3dbcdd22020-07-22 07:38:45 +00001240 },
1241 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001242 pConfigAniStateAFsm.CommChan <- fsmAbortMsg
mpagenko3dbcdd22020-07-22 07:38:45 +00001243
1244 //try to restart the FSM to 'disabled', decouple event transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001245 go func(aPAFsm *cmn.AdapterFsm) {
1246 if aPAFsm != nil && aPAFsm.PFsm != nil {
1247 _ = aPAFsm.PFsm.Event(aniEvRestart)
mpagenko3dbcdd22020-07-22 07:38:45 +00001248 }
1249 }(pConfigAniStateAFsm)
Akash Soni3de0e062024-12-11 16:37:26 +05301250 logger.Warnf(ctx, "calling HandleAniConfigFSMFailure resetting", log.Fields{
1251 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
1252 oFsm.pDeviceHandler.HandleAniConfigFSMFailure(ctx, oFsm.pOnuUniPort.UniID)
mpagenko3dbcdd22020-07-22 07:38:45 +00001253 }
1254}
1255
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301256//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001257func (oFsm *UniPonAniConfigFsm) enterDisabledState(ctx context.Context, e *fsm.Event) {
1258 logger.Debugw(ctx, "UniPonAniConfigFsm enters disabled state", log.Fields{
1259 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001260 oFsm.mutexPLastTxMeInstance.Lock()
1261 defer oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00001262 oFsm.pLastTxMeInstance = nil
mpagenko1cc3cb42020-07-27 15:24:38 +00001263}
1264
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001265func (oFsm *UniPonAniConfigFsm) processOmciAniMessages(ctx context.Context) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301266 logger.Info(ctx, "Start UniPonAniConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001267loop:
1268 for {
mpagenko3dbcdd22020-07-22 07:38:45 +00001269 // case <-ctx.Done():
mpagenko01e726e2020-10-23 09:45:29 +00001270 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001271 // break loop
bseenivaeba8eb12024-12-13 11:54:28 +05301272 select {
1273 case message, ok := <-oFsm.PAdaptFsm.CommChan:
1274 if !ok {
1275 logger.Warn(ctx, "UniPonAniConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID})
1276 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
1277 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +00001278 break loop
1279 }
bseenivaeba8eb12024-12-13 11:54:28 +05301280 logger.Debugw(ctx, "UniPonAniConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID})
1281
1282 switch message.Type {
1283 case cmn.TestMsg:
1284 msg, _ := message.Data.(cmn.TestMessage)
1285 if msg.TestMessageVal == cmn.AbortMessageProcessing {
1286 logger.Infow(ctx, "UniPonAniConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID})
1287 break loop
1288 }
1289 logger.Warnw(ctx, "UniPonAniConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal})
1290 case cmn.OMCI:
1291 msg, _ := message.Data.(cmn.OmciMessage)
1292 oFsm.handleOmciAniConfigMessage(ctx, msg)
1293 default:
1294 logger.Warn(ctx, "UniPonAniConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID,
1295 "message.Type": message.Type})
1296 }
1297 case _, ok := <-oFsm.pDeviceHandler.GetDeviceDeleteCommChan(ctx):
1298 if !ok {
1299 logger.Warnw(ctx, "Device deletion channel closed", log.Fields{"device-id": oFsm.deviceID})
1300 }
1301 break loop
Himani Chawla4d908332020-08-31 12:30:20 +05301302 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001303
Himani Chawla4d908332020-08-31 12:30:20 +05301304 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001305 logger.Infow(ctx, "End UniPonAniConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301306}
1307
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001308func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigCreateResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +05301309 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse)
1310 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001311 logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001312 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301313 return
1314 }
1315 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
1316 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001317 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001318 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301319 return
1320 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001321 logger.Debugw(ctx, "CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenkofc4f56e2020-11-04 17:17:49 +00001322 if msgObj.Result == me.Success || msgObj.Result == me.InstanceExists {
1323 //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 +00001324 oFsm.mutexPLastTxMeInstance.RLock()
1325 if oFsm.pLastTxMeInstance != nil {
1326 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1327 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1328 // maybe we can use just the same eventName for different state transitions like "forward"
1329 // - might be checked, but so far I go for sure and have to inspect the concrete state events ...
1330 switch oFsm.pLastTxMeInstance.GetName() {
1331 case "Ieee8021PMapperServiceProfile":
1332 { // let the FSM proceed ...
1333 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001334 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxDot1pmapCResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001335 }
1336 case "MacBridgePortConfigurationData":
1337 { // let the FSM proceed ...
1338 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001339 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxMbpcdResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001340 }
1341 case "GemPortNetworkCtp", "GemInterworkingTerminationPoint", "MulticastGemInterworkingTerminationPoint":
1342 { // let aniConfig Multi-Id processing proceed by stopping the wait function
1343 oFsm.mutexPLastTxMeInstance.RUnlock()
1344 oFsm.omciMIdsResponseReceived <- true
1345 }
1346 default:
1347 {
1348 oFsm.mutexPLastTxMeInstance.RUnlock()
1349 logger.Warnw(ctx, "Unsupported ME name received!",
1350 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1351 }
mpagenkofc4f56e2020-11-04 17:17:49 +00001352 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001353 } else {
1354 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenkofc4f56e2020-11-04 17:17:49 +00001355 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001356 } else {
1357 oFsm.mutexPLastTxMeInstance.RUnlock()
1358 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +00001359 }
1360 } else {
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001361 logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?",
1362 log.Fields{"Error": msgObj.Result, "device-id": oFsm.deviceID})
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001363 // possibly force FSM into abort or ignore some errors for some messages?
1364 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1365 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
Himani Chawla4d908332020-08-31 12:30:20 +05301366 return
1367 }
Himani Chawla4d908332020-08-31 12:30:20 +05301368}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001369func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigSetFailResponseMessage(ctx context.Context, msgObj *omci.SetResponse) {
Mahir Gunyel01034b62021-06-29 11:25:09 -07001370 //If TCONT fails, then we need to revert the allocated TCONT in DB.
1371 //Because FSMs are running sequentially, we don't expect the same TCONT hit by another tech-profile FSM while this FSM is running.
1372 oFsm.mutexPLastTxMeInstance.RLock()
1373 defer oFsm.mutexPLastTxMeInstance.RUnlock()
1374 if oFsm.pLastTxMeInstance != nil && msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1375 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1376 switch oFsm.pLastTxMeInstance.GetName() {
1377 case "TCont":
1378 //If this is for TCONT creation(requestEventOffset=0) and this is the first allocation of TCONT(so noone else is using the same TCONT)
1379 //We should revert DB
bseenivaeba8eb12024-12-13 11:54:28 +05301380 oFsm.pUniTechProf.mutexTPState.RLock()
Mahir Gunyel01034b62021-06-29 11:25:09 -07001381 if oFsm.requestEventOffset == 0 && !oFsm.tcontSetBefore && oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey] != nil {
1382 logger.Debugw(ctx, "UniPonAniConfigFsm TCONT creation failed on device. Freeing alloc id", log.Fields{"device-id": oFsm.deviceID,
1383 "alloc-id": oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID, "uni-tp": oFsm.uniTpKey})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001384 if oFsm.pOnuDeviceEntry != nil {
1385 oFsm.pOnuDeviceEntry.FreeTcont(ctx, oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID)
Mahir Gunyel01034b62021-06-29 11:25:09 -07001386 } else {
1387 logger.Warnw(ctx, "Unable to get device entry! couldn't free tcont",
1388 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1389 }
1390 }
bseenivaeba8eb12024-12-13 11:54:28 +05301391 oFsm.pUniTechProf.mutexTPState.RUnlock()
Mahir Gunyel01034b62021-06-29 11:25:09 -07001392 default:
1393 logger.Warnw(ctx, "Unsupported ME name received with error!",
1394 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "result": msgObj.Result, "device-id": oFsm.deviceID})
1395 }
1396 }
1397}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001398func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigSetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +05301399 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
1400 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001401 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be detected for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001402 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301403 return
1404 }
1405 msgObj, msgOk := msgLayer.(*omci.SetResponse)
1406 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001407 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be assigned for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001408 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301409 return
1410 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001411 logger.Debugw(ctx, "UniPonAniConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +05301412 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001413 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci SetResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00001414 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001415 // possibly force FSM into abort or ignore some errors for some messages?
1416 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1417 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
Mahir Gunyel01034b62021-06-29 11:25:09 -07001418 oFsm.handleOmciAniConfigSetFailResponseMessage(ctx, msgObj)
Himani Chawla4d908332020-08-31 12:30:20 +05301419 return
1420 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001421 oFsm.mutexPLastTxMeInstance.RLock()
1422 if oFsm.pLastTxMeInstance != nil {
1423 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1424 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1425 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
1426 // if, then something like:
1427 //oFsm.pOnuDB.StoreMe(msgObj)
Himani Chawla4d908332020-08-31 12:30:20 +05301428
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001429 switch oFsm.pLastTxMeInstance.GetName() {
1430 case "TCont":
1431 { // let the FSM proceed ...
1432 oFsm.mutexPLastTxMeInstance.RUnlock()
1433 if oFsm.requestEventOffset == 0 { //from TCont config request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001434 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxTcontsResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001435 } else { // from T-Cont reset request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001436 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxResetTcontResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001437 }
1438 }
1439 case "PriorityQueue", "MulticastGemInterworkingTerminationPoint":
1440 { // let the PrioQueue init proceed by stopping the wait function
1441 oFsm.mutexPLastTxMeInstance.RUnlock()
1442 oFsm.omciMIdsResponseReceived <- true
1443 }
1444 case "Ieee8021PMapperServiceProfile":
1445 { // let the FSM proceed ...
1446 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001447 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxDot1pmapSResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001448 }
1449 default:
1450 {
1451 oFsm.mutexPLastTxMeInstance.RUnlock()
1452 logger.Warnw(ctx, "Unsupported ME name received!",
1453 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001454 }
Himani Chawla4d908332020-08-31 12:30:20 +05301455 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001456 } else {
1457 oFsm.mutexPLastTxMeInstance.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +05301458 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001459 } else {
1460 oFsm.mutexPLastTxMeInstance.RUnlock()
1461 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301462 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001463}
1464
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001465func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigDeleteResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
mpagenko8b07c1b2020-11-26 10:36:31 +00001466 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeDeleteResponse)
1467 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001468 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be detected for DeleteResponse",
mpagenko8b07c1b2020-11-26 10:36:31 +00001469 log.Fields{"device-id": oFsm.deviceID})
1470 return
1471 }
1472 msgObj, msgOk := msgLayer.(*omci.DeleteResponse)
1473 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001474 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be assigned for DeleteResponse",
mpagenko8b07c1b2020-11-26 10:36:31 +00001475 log.Fields{"device-id": oFsm.deviceID})
1476 return
1477 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001478 logger.Debugw(ctx, "UniPonAniConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
Akash Soni8eff4632024-12-11 13:41:46 +05301479 if msgObj.Result == me.UnknownInstance {
1480 logger.Warnw(ctx, "UniPonAniConfigFsm - Unknow Instance",
1481 log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj, "Error": msgObj.Result})
1482 } else if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001483 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci DeleteResponse Error",
mpagenko8b07c1b2020-11-26 10:36:31 +00001484 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
1485 //TODO: - later: possibly force FSM into abort or ignore some errors for some messages?
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001486 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1487 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
mpagenko8b07c1b2020-11-26 10:36:31 +00001488 return
1489 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001490 oFsm.mutexPLastTxMeInstance.RLock()
1491 if oFsm.pLastTxMeInstance != nil {
1492 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1493 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1494 //remove ME from DB //TODO??? obviously the Python code does not store/remove the config ...
1495 // if, then something like: oFsm.pOnuDB.XyyMe(msgObj)
mpagenko8b07c1b2020-11-26 10:36:31 +00001496
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001497 switch oFsm.pLastTxMeInstance.GetName() {
1498 case "GemInterworkingTerminationPoint":
1499 { // let the FSM proceed ...
1500 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001501 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemGemiwResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001502 }
1503 case "GemPortNetworkCtp":
1504 { // let the FSM proceed ...
1505 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001506 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemGemntpResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001507 }
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001508 case "TrafficDescriptor":
1509 { // let the FSM proceed ...
1510 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001511 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemTdResp)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001512 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001513 case "Ieee8021PMapperServiceProfile":
1514 { // let the FSM proceed ...
1515 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001516 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRem1pMapperResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001517 }
1518 case "MacBridgePortConfigurationData":
1519 { // this is the last event of the T-Cont cleanup procedure, FSM may be reset here
1520 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001521 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemAniBPCDResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001522 }
1523 default:
1524 {
1525 oFsm.mutexPLastTxMeInstance.RUnlock()
1526 logger.Warnw(ctx, "Unsupported ME name received!",
1527 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1528 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001529 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001530 } else {
1531 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko8b07c1b2020-11-26 10:36:31 +00001532 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001533 } else {
1534 oFsm.mutexPLastTxMeInstance.RUnlock()
1535 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001536 }
1537}
1538
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001539func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001540 logger.Debugw(ctx, "Rx OMCI UniPonAniConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001541 "msgType": msg.OmciMsg.MessageType})
1542
1543 switch msg.OmciMsg.MessageType {
1544 case omci.CreateResponseType:
1545 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001546 oFsm.handleOmciAniConfigCreateResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301547
mpagenko3dbcdd22020-07-22 07:38:45 +00001548 } //CreateResponseType
1549 case omci.SetResponseType:
1550 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001551 oFsm.handleOmciAniConfigSetResponseMessage(ctx, msg)
mpagenko3dbcdd22020-07-22 07:38:45 +00001552
mpagenko3dbcdd22020-07-22 07:38:45 +00001553 } //SetResponseType
mpagenko8b07c1b2020-11-26 10:36:31 +00001554 case omci.DeleteResponseType:
1555 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001556 oFsm.handleOmciAniConfigDeleteResponseMessage(ctx, msg)
mpagenko8b07c1b2020-11-26 10:36:31 +00001557
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001558 } //DeleteResponseType
mpagenko3dbcdd22020-07-22 07:38:45 +00001559 default:
1560 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001561 logger.Errorw(ctx, "UniPonAniConfigFsm - Rx OMCI unhandled MsgType",
mpagenko01e726e2020-10-23 09:45:29 +00001562 log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001563 return
1564 }
1565 }
1566}
1567
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001568func (oFsm *UniPonAniConfigFsm) performCreatingGemNCTPs(ctx context.Context) {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001569 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
1570 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301571 logger.Info(ctx, "UniPonAniConfigFsm Tx Create::GemNWCtp", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001572 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
1573 "TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001574 "device-id": oFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001575 meParams := me.ParamData{
1576 EntityID: gemPortAttribs.gemPortID, //unique, same as PortId
1577 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001578 me.GemPortNetworkCtp_PortId: gemPortAttribs.gemPortID,
1579 me.GemPortNetworkCtp_TContPointer: oFsm.tcont0ID,
1580 me.GemPortNetworkCtp_Direction: gemPortAttribs.direction,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001581 //ONU-G.TrafficManagementOption dependency ->PrioQueue or TCont
1582 // TODO!! verify dependency and QueueId in case of Multi-GemPort setup!
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001583 me.GemPortNetworkCtp_TrafficManagementPointerForUpstream: gemPortAttribs.upQueueID, //might be different in wrr-only Setup - tcont0ID
1584 me.GemPortNetworkCtp_PriorityQueuePointerForDownStream: gemPortAttribs.downQueueID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001585 },
1586 }
Holger Hildebrandtc408f492022-07-14 08:39:24 +00001587 if oFsm.techProfileType == cTechProfileTypeXgsPon {
1588 meParams.Attributes[me.GemPortNetworkCtp_EncryptionKeyRing] = GemEncryptKeyRingUnicastDownstreamOnly
1589 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001590 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001591 meInstance, err := oFsm.pOmciCC.SendCreateGemNCTPVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1592 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001593 if err != nil {
1594 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001595 logger.Errorw(ctx, "GemNCTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001596 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001597 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001598 return
1599 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001600 //accept also nil as (error) return value for writing to LastTx
1601 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001602 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001603 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001604 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001605 err = oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001606 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001607 logger.Errorw(ctx, "GemNWCtp create failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001608 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001609 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001610 return
1611 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301612 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpClassID, gemPortAttribs.gemPortID, meParams.Attributes)
Girish Gowdra50e56422021-06-01 16:46:04 -07001613 // Mark the gem port to be added for Performance History monitoring
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001614 OnuMetricsManager := oFsm.pDeviceHandler.GetOnuMetricsManager()
1615 if OnuMetricsManager != nil {
1616 OnuMetricsManager.AddGemPortForPerfMonitoring(ctx, gemPortAttribs.gemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001617 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001618 } //for all GemPorts of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +00001619
1620 // if Config has been done for all GemPort instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001621 logger.Debugw(ctx, "GemNWCtp create loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001622 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxGemntcpsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001623}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001624func (oFsm *UniPonAniConfigFsm) hasMulticastGem(ctx context.Context) bool {
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001625 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
1626 if gemPortAttribs.isMulticast {
1627 logger.Debugw(ctx, "Found multicast gem", log.Fields{"device-id": oFsm.deviceID})
1628 return true
1629 }
1630 }
1631 return false
1632}
mpagenko3dbcdd22020-07-22 07:38:45 +00001633
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001634func (oFsm *UniPonAniConfigFsm) performCreatingGemIWs(ctx context.Context) {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001635 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
1636 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301637 logger.Info(ctx, "UniPonAniConfigFsm Tx Create::GemIwTp", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001638 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
1639 "SPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001640 "device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001641
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301642 var meParams me.ParamData
ozgecanetsia4b232302020-11-11 10:58:10 +03001643 //TODO if the port has only downstream direction the isMulticast flag can be removed.
1644 if gemPortAttribs.isMulticast {
ozgecanetsia4b232302020-11-11 10:58:10 +03001645
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301646 meParams = me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001647 EntityID: gemPortAttribs.multicastGemID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001648 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001649 me.MulticastGemInterworkingTerminationPoint_GemPortNetworkCtpConnectivityPointer: gemPortAttribs.multicastGemID,
1650 me.MulticastGemInterworkingTerminationPoint_InterworkingOption: 0, // Don't Care
1651 me.MulticastGemInterworkingTerminationPoint_ServiceProfilePointer: 0, // Don't Care
1652 me.MulticastGemInterworkingTerminationPoint_GalProfilePointer: cmn.GalEthernetEID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001653 },
1654 }
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001655 if oFsm.pUniTechProf.multicastConfiguredForOtherUniTps(ctx, oFsm.uniTpKey) {
1656 logger.Debugw(ctx, "MulticastGemInterworkingTP already exist", log.Fields{"device-id": oFsm.deviceID, "multicast-gem-id": gemPortAttribs.multicastGemID})
1657 continue
1658 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001659 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001660 meInstance, err := oFsm.pOmciCC.SendCreateMulticastGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(),
1661 true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001662 if err != nil {
1663 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001664 logger.Errorw(ctx, "MulticastGemIWTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001665 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001666 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001667 return
1668
1669 }
ozgecanetsia4b232302020-11-11 10:58:10 +03001670 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001671 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001672 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001673 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001674 if err != nil {
ozgecanetsiab36ed572021-04-01 10:38:48 +03001675 logger.Errorw(ctx, "MulticastGemIWTP create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001676 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001677 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001678 return
1679 }
1680 ipv4MulticastTable := make([]uint8, 12)
1681 //Gem Port ID
1682 binary.BigEndian.PutUint16(ipv4MulticastTable[0:], gemPortAttribs.multicastGemID)
1683 //Secondary Key
1684 binary.BigEndian.PutUint16(ipv4MulticastTable[2:], 0)
1685 // Multicast IP range start This is the 224.0.0.1 address
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001686 binary.BigEndian.PutUint32(ipv4MulticastTable[4:], cmn.IPToInt32(net.IPv4(224, 0, 0, 0)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001687 // MulticastIp range stop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001688 binary.BigEndian.PutUint32(ipv4MulticastTable[8:], cmn.IPToInt32(net.IPv4(239, 255, 255, 255)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001689
1690 meIPV4MCTableParams := me.ParamData{
1691 EntityID: gemPortAttribs.multicastGemID,
1692 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001693 me.MulticastGemInterworkingTerminationPoint_Ipv4MulticastAddressTable: ipv4MulticastTable,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001694 },
1695 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001696 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001697 meIPV4MCTableInstance, err := oFsm.pOmciCC.SendSetMulticastGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(),
1698 true, oFsm.PAdaptFsm.CommChan, meIPV4MCTableParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001699 if err != nil {
1700 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001701 logger.Errorw(ctx, "MulticastGemIWTPVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001702 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001703 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001704 return
1705 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001706 oFsm.pLastTxMeInstance = meIPV4MCTableInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001707 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia4b232302020-11-11 10:58:10 +03001708
1709 } else {
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301710 meParams = me.ParamData{
ozgecanetsia4b232302020-11-11 10:58:10 +03001711 EntityID: gemPortAttribs.gemPortID,
1712 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001713 me.GemInterworkingTerminationPoint_GemPortNetworkCtpConnectivityPointer: gemPortAttribs.gemPortID, //same as EntityID, see above
1714 me.GemInterworkingTerminationPoint_InterworkingOption: 5, //fixed model:: G.998 .1pMapper
1715 me.GemInterworkingTerminationPoint_ServiceProfilePointer: oFsm.mapperSP0ID,
1716 me.GemInterworkingTerminationPoint_InterworkingTerminationPointPointer: 0, //not used with .1PMapper Mac bridge
1717 me.GemInterworkingTerminationPoint_GalProfilePointer: cmn.GalEthernetEID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001718 },
1719 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001720 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001721 meInstance, err := oFsm.pOmciCC.SendCreateGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1722 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001723 if err != nil {
1724 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001725 logger.Errorw(ctx, "GEMIWTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001726 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001727 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001728 return
1729 }
ozgecanetsia4b232302020-11-11 10:58:10 +03001730 //accept also nil as (error) return value for writing to LastTx
1731 // - this avoids misinterpretation of new received OMCI messages
1732 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001733 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia4b232302020-11-11 10:58:10 +03001734 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001735 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001736 err := oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001737 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001738 logger.Errorw(ctx, "GemTP create failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001739 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001740 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001741 return
1742 }
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301743 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 +05301744 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemInterworkingTerminationPointClassID, gemPortAttribs.gemPortID, meParams.Attributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301745
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001746 } //for all GemPort's of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +00001747
1748 // if Config has been done for all GemPort instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001749 logger.Debugw(ctx, "GemIwTp create loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001750 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxGemiwsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001751}
1752
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001753func (oFsm *UniPonAniConfigFsm) performSettingPQs(ctx context.Context) {
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001754 //If upstream PQs were set before, then no need to set them again. Let state machine to proceed.
1755 if oFsm.tcontSetBefore {
1756 logger.Debugw(ctx, "No need to set PQs again.", log.Fields{
1757 "device-id": oFsm.deviceID, "tcont": oFsm.alloc0ID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001758 "uni-id": oFsm.pOnuUniPort.UniID,
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001759 "techProfile-id": oFsm.techProfileID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001760 go func(aPAFsm *cmn.AdapterFsm) {
1761 if aPAFsm != nil && aPAFsm.PFsm != nil {
1762 _ = aPAFsm.PFsm.Event(aniEvRxPrioqsResp)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001763 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001764 }(oFsm.PAdaptFsm)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001765 return
1766 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001767 const cu16StrictPrioWeight uint16 = 0xFFFF
1768 //find all upstream PrioQueues related to this T-Cont
1769 loQueueMap := ordered_map.NewOrderedMap()
1770 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001771 if gemPortAttribs.isMulticast {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001772 logger.Debugw(ctx, "UniPonAniConfigFsm Port is Multicast, ignoring PQs", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001773 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
1774 "prioString": gemPortAttribs.pbitString})
1775 continue
1776 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001777 if gemPortAttribs.qosPolicy == "WRR" {
Himani Chawla4d908332020-08-31 12:30:20 +05301778 if _, ok := loQueueMap.Get(gemPortAttribs.upQueueID); !ok {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001779 //key does not yet exist
1780 loQueueMap.Set(gemPortAttribs.upQueueID, uint16(gemPortAttribs.weight))
1781 }
1782 } else {
1783 loQueueMap.Set(gemPortAttribs.upQueueID, cu16StrictPrioWeight) //use invalid weight value to indicate SP
1784 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001785 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001786
Girish Gowdra09e5f212021-09-30 16:28:36 -07001787 trafficSchedPtrSetSupported := false
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001788 loOnu2g := oFsm.pOnuDB.GetMe(me.Onu2GClassID, cmn.Onu2gMeID)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001789 if loOnu2g == nil {
1790 logger.Errorw(ctx, "onu2g is nil, cannot read qos configuration flexibility parameter",
1791 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001792 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001793 return
1794 }
1795 returnVal := loOnu2g["QualityOfServiceQosConfigurationFlexibility"]
1796 if returnVal != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001797 if qosCfgFlexParam, err := oFsm.pOnuDB.GetUint16Attrib(returnVal); err == nil {
Girish Gowdra09e5f212021-09-30 16:28:36 -07001798 trafficSchedPtrSetSupported = qosCfgFlexParam&bitTrafficSchedulerPtrSetPermitted == bitTrafficSchedulerPtrSetPermitted
1799 logger.Debugw(ctx, "trafficSchedPtrSetSupported set",
1800 log.Fields{"qosCfgFlexParam": qosCfgFlexParam, "trafficSchedPtrSetSupported": trafficSchedPtrSetSupported})
1801 } else {
1802 logger.Errorw(ctx, "Cannot extract qos configuration flexibility parameter",
1803 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001804 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001805 return
1806 }
1807 } else {
1808 logger.Errorw(ctx, "Cannot read qos configuration flexibility parameter",
1809 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001810 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001811 return
1812 }
1813
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001814 //TODO: assumption here is that ONU data uses SP setting in the T-Cont and WRR in the TrafficScheduler
1815 // if that is not the case, the reverse case could be checked and reacted accordingly or if the
1816 // complete chain is not valid, then some error should be thrown and configuration can be aborted
1817 // or even be finished without correct SP/WRR setting
1818
1819 //TODO: search for the (WRR)trafficScheduler related to the T-Cont of this queue
1820 //By now assume fixed value 0x8000, which is the only announce BBSIM TrafficScheduler,
1821 // even though its T-Cont seems to be wrong ...
1822 loTrafficSchedulerEID := 0x8000
1823 //for all found queues
1824 iter := loQueueMap.IterFunc()
1825 for kv, ok := iter(); ok; kv, ok = iter() {
1826 queueIndex := (kv.Key).(uint16)
1827 meParams := me.ParamData{
1828 EntityID: queueIndex,
Himani Chawla4d908332020-08-31 12:30:20 +05301829 Attributes: make(me.AttributeValueMap),
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001830 }
Girish Gowdra09e5f212021-09-30 16:28:36 -07001831 if trafficSchedPtrSetSupported {
1832 if (kv.Value).(uint16) == cu16StrictPrioWeight {
1833 //StrictPrio indication
1834 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio", log.Fields{
1835 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1836 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001837 meParams.Attributes[me.PriorityQueue_TrafficSchedulerPointer] = 0 //ensure T-Cont defined StrictPrio scheduling
Girish Gowdra09e5f212021-09-30 16:28:36 -07001838 } else {
1839 //WRR indication
1840 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to WRR", log.Fields{
1841 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1842 "Weight": kv.Value,
1843 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001844 meParams.Attributes[me.PriorityQueue_TrafficSchedulerPointer] = loTrafficSchedulerEID //ensure assignment of the relevant trafficScheduler
1845 meParams.Attributes[me.PriorityQueue_Weight] = uint8(kv.Value.(uint16))
Girish Gowdra09e5f212021-09-30 16:28:36 -07001846 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001847 } else {
Girish Gowdra09e5f212021-09-30 16:28:36 -07001848 // setting Traffic Scheduler (TS) pointer is not supported unless we point to another TS that points to the same TCONT.
1849 // 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.
1850 // 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.
1851 if (kv.Value).(uint16) == cu16StrictPrioWeight { // SP case, nothing to be done. Proceed to the next queue
1852 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio, traffic sched ptr set unsupported", log.Fields{
1853 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1854 "device-id": oFsm.deviceID})
1855 continue
1856 }
1857 // WRR case, update weight.
1858 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to WRR, traffic sched ptr set unsupported", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001859 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1860 "Weight": kv.Value,
mpagenko01e726e2020-10-23 09:45:29 +00001861 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001862 meParams.Attributes[me.PriorityQueue_Weight] = uint8(kv.Value.(uint16))
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001863 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001864 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001865 meInstance, err := oFsm.pOmciCC.SendSetPrioQueueVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1866 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001867 if err != nil {
1868 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001869 logger.Errorw(ctx, "PrioQueueVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001870 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001871 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001872 return
1873 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001874 //accept also nil as (error) return value for writing to LastTx
1875 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001876 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001877 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001878
1879 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001880 err = oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001881 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001882 logger.Errorw(ctx, "PrioQueue set failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001883 log.Fields{"device-id": oFsm.deviceID, "QueueId": strconv.FormatInt(int64(queueIndex), 16)})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001884 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001885 return
1886 }
1887
1888 //TODO: In case of WRR setting of the GemPort/PrioQueue it might further be necessary to
1889 // write the assigned trafficScheduler with the requested Prio to be considered in the StrictPrio scheduling
1890 // of the (next upstream) assigned T-Cont, which is f(prioQueue[priority]) - in relation to other SP prioQueues
1891 // not yet done because of BBSIM TrafficScheduler issues (and not done in py code as well)
1892
1893 } //for all upstream prioQueues
mpagenko3dbcdd22020-07-22 07:38:45 +00001894
1895 // if Config has been done for all PrioQueue instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001896 logger.Debugw(ctx, "PrioQueue set loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001897 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxPrioqsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001898}
1899
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001900func (oFsm *UniPonAniConfigFsm) waitforOmciResponse(ctx context.Context) error {
mpagenko7d6bb022021-03-11 15:07:55 +00001901 oFsm.mutexIsAwaitingResponse.Lock()
mpagenkocf48e452021-04-23 09:23:00 +00001902 if oFsm.isCanceled {
1903 // FSM already canceled before entering wait
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001904 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 +00001905 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001906 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenkocf48e452021-04-23 09:23:00 +00001907 }
mpagenko7d6bb022021-03-11 15:07:55 +00001908 oFsm.isAwaitingResponse = true
1909 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko3dbcdd22020-07-22 07:38:45 +00001910 select {
Himani Chawla4d908332020-08-31 12:30:20 +05301911 // maybe be also some outside cancel (but no context modeled for the moment ...)
mpagenko3dbcdd22020-07-22 07:38:45 +00001912 // case <-ctx.Done():
mpagenko01e726e2020-10-23 09:45:29 +00001913 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +00001914 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 +00001915 logger.Warnw(ctx, "UniPonAniConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001916 oFsm.mutexIsAwaitingResponse.Lock()
1917 oFsm.isAwaitingResponse = false
1918 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001919 oFsm.mutexPLastTxMeInstance.RLock()
1920 if oFsm.pLastTxMeInstance != nil {
1921 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureTimeout, oFsm.pLastTxMeInstance.GetClassID(),
1922 oFsm.pLastTxMeInstance.GetEntityID(), oFsm.pLastTxMeInstance.GetClassID().String(), 0)
1923 }
1924 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00001925 return fmt.Errorf("uniPonAniConfigFsm multi entity timeout %s", oFsm.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +00001926 case success := <-oFsm.omciMIdsResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +05301927 if success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001928 logger.Debugw(ctx, "UniPonAniConfigFsm multi entity response received", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001929 oFsm.mutexIsAwaitingResponse.Lock()
1930 oFsm.isAwaitingResponse = false
1931 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko3dbcdd22020-07-22 07:38:45 +00001932 return nil
1933 }
mpagenko7d6bb022021-03-11 15:07:55 +00001934 // waiting was aborted (probably on external request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001935 logger.Debugw(ctx, "UniPonAniConfigFsm wait-for-multi-entity-response aborted", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001936 oFsm.mutexIsAwaitingResponse.Lock()
1937 oFsm.isAwaitingResponse = false
1938 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001939 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenko3dbcdd22020-07-22 07:38:45 +00001940 }
1941}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001942
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001943func (oFsm *UniPonAniConfigFsm) setChanSet(flagValue bool) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001944 oFsm.mutexChanSet.Lock()
1945 oFsm.chanSet = flagValue
1946 oFsm.mutexChanSet.Unlock()
1947}
1948
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001949func (oFsm *UniPonAniConfigFsm) isChanSet() bool {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001950 oFsm.mutexChanSet.RLock()
1951 flagValue := oFsm.chanSet
1952 oFsm.mutexChanSet.RUnlock()
1953 return flagValue
1954}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001955
1956// PrepareForGarbageCollection - remove references to prepare for garbage collection
1957func (oFsm *UniPonAniConfigFsm) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301958 logger.Info(ctx, "prepare for garbage collection", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001959 oFsm.pDeviceHandler = nil
1960 oFsm.pOnuDeviceEntry = nil
1961 oFsm.pOmciCC = nil
1962}