blob: 4968d78e51e996fabfa511aea206d34863c177fc [file] [log] [blame]
mpagenko3dbcdd22020-07-22 07:38:45 +00001/*
Joey Armstrong89c812c2024-01-12 19:00:20 -05002 * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors
mpagenko3dbcdd22020-07-22 07:38:45 +00003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
praneeth kumar nalmas3947c582023-12-13 15:38:50 +053017// Package avcfg provides anig and vlan configuration functionality
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000018package avcfg
mpagenko3dbcdd22020-07-22 07:38:45 +000019
20import (
21 "context"
ozgecanetsia4b232302020-11-11 10:58:10 +030022 "encoding/binary"
Himani Chawla4d908332020-08-31 12:30:20 +053023 "fmt"
ozgecanetsia4b232302020-11-11 10:58:10 +030024 "net"
mpagenko3dbcdd22020-07-22 07:38:45 +000025 "strconv"
mpagenko7d6bb022021-03-11 15:07:55 +000026 "sync"
mpagenko3dbcdd22020-07-22 07:38:45 +000027 "time"
28
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000029 "github.com/cevaris/ordered_map"
mpagenko3dbcdd22020-07-22 07:38:45 +000030 "github.com/looplab/fsm"
mpagenko836a1fd2021-11-01 16:12:42 +000031 "github.com/opencord/omci-lib-go/v2"
32 me "github.com/opencord/omci-lib-go/v2/generated"
khenaidoo7d3c5582021-08-11 18:09:44 -040033 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000034
khenaidoo7d3c5582021-08-11 18:09:44 -040035 //ic "github.com/opencord/voltha-protos/v5/go/inter_container"
36 //"github.com/opencord/voltha-protos/v5/go/openflow_13"
37 //"github.com/opencord/voltha-protos/v5/go/voltha"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000038 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
39 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb"
mpagenko3dbcdd22020-07-22 07:38:45 +000040)
41
mpagenko1cc3cb42020-07-27 15:24:38 +000042const (
43 // events of config PON ANI port FSM
mpagenko8b07c1b2020-11-26 10:36:31 +000044 aniEvStart = "aniEvStart"
balaji.nagarajanca025612025-06-23 16:16:06 +053045 aniEvPrepareConfig = "aniEvPrepareConfig"
mpagenko8b07c1b2020-11-26 10:36:31 +000046 aniEvStartConfig = "aniEvStartConfig"
47 aniEvRxDot1pmapCResp = "aniEvRxDot1pmapCResp"
48 aniEvRxMbpcdResp = "aniEvRxMbpcdResp"
49 aniEvRxTcontsResp = "aniEvRxTcontsResp"
50 aniEvRxGemntcpsResp = "aniEvRxGemntcpsResp"
51 aniEvRxGemiwsResp = "aniEvRxGemiwsResp"
52 aniEvRxPrioqsResp = "aniEvRxPrioqsResp"
53 aniEvRxDot1pmapSResp = "aniEvRxDot1pmapSResp"
54 aniEvRemGemiw = "aniEvRemGemiw"
Girish Gowdra26a40922021-01-29 17:14:34 -080055 aniEvWaitFlowRem = "aniEvWaitFlowRem"
56 aniEvFlowRemDone = "aniEvFlowRemDone"
mpagenko8b07c1b2020-11-26 10:36:31 +000057 aniEvRxRemGemiwResp = "aniEvRxRemGemiwResp"
58 aniEvRxRemGemntpResp = "aniEvRxRemGemntpResp"
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +030059 aniEvRxRemTdResp = "aniEvRxRemTdResp"
mpagenko8b07c1b2020-11-26 10:36:31 +000060 aniEvRemTcontPath = "aniEvRemTcontPath"
61 aniEvRxResetTcontResp = "aniEvRxResetTcontResp"
62 aniEvRxRem1pMapperResp = "aniEvRxRem1pMapperResp"
63 aniEvRxRemAniBPCDResp = "aniEvRxRemAniBPCDResp"
64 aniEvTimeoutSimple = "aniEvTimeoutSimple"
65 aniEvTimeoutMids = "aniEvTimeoutMids"
66 aniEvReset = "aniEvReset"
67 aniEvRestart = "aniEvRestart"
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +000068 aniEvSkipOmciConfig = "aniEvSkipOmciConfig"
Mahir Gunyel9545be22021-07-04 15:53:16 -070069 aniEvRemGemDone = "aniEvRemGemDone"
mpagenko1cc3cb42020-07-27 15:24:38 +000070)
71const (
72 // states of config PON ANI port FSM
73 aniStDisabled = "aniStDisabled"
74 aniStStarting = "aniStStarting"
balaji.nagarajanca025612025-06-23 16:16:06 +053075 aniStPrepareConfig = "aniStPrepareConfig"
mpagenko1cc3cb42020-07-27 15:24:38 +000076 aniStCreatingDot1PMapper = "aniStCreatingDot1PMapper"
77 aniStCreatingMBPCD = "aniStCreatingMBPCD"
78 aniStSettingTconts = "aniStSettingTconts"
79 aniStCreatingGemNCTPs = "aniStCreatingGemNCTPs"
80 aniStCreatingGemIWs = "aniStCreatingGemIWs"
81 aniStSettingPQs = "aniStSettingPQs"
82 aniStSettingDot1PMapper = "aniStSettingDot1PMapper"
83 aniStConfigDone = "aniStConfigDone"
mpagenko8b07c1b2020-11-26 10:36:31 +000084 aniStRemovingGemIW = "aniStRemovingGemIW"
Girish Gowdra26a40922021-01-29 17:14:34 -080085 aniStWaitingFlowRem = "aniStWaitingFlowRem"
mpagenko8b07c1b2020-11-26 10:36:31 +000086 aniStRemovingGemNCTP = "aniStRemovingGemNCTP"
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +030087 aniStRemovingTD = "aniStRemovingTD"
mpagenko8b07c1b2020-11-26 10:36:31 +000088 aniStResetTcont = "aniStResetTcont"
89 aniStRemDot1PMapper = "aniStRemDot1PMapper"
90 aniStRemAniBPCD = "aniStRemAniBPCD"
91 aniStRemoveDone = "aniStRemoveDone"
mpagenko1cc3cb42020-07-27 15:24:38 +000092 aniStResetting = "aniStResetting"
93)
94
Girish Gowdra09e5f212021-09-30 16:28:36 -070095const (
96 bitTrafficSchedulerPtrSetPermitted = 0x0002 // Refer section 9.1.2 ONU-2G, table for "Quality of service (QoS) configuration flexibility" IE
97)
Holger Hildebrandtc408f492022-07-14 08:39:24 +000098const cTechProfileTypeXgsPon = "XGS-PON"
99
100// definitions as per G.988
101// Gem Encryption Key Ring
102const (
103 // No encryption. The downstream key index is ignored, and upstream traffic is transmitted with key index 0.
104 GemEncryptKeyRingNoEncrypt = 0
105 // Unicast payload encryption in both directions. Keys are generated by the ONU and transmitted to the OLT via the PLOAM channel.
106 GemEncryptKeyRingUnicastPayload = 1
107 // Broadcast (multicast) encryption. Keys are generated by the OLT and distributed via the OMCI.
108 GemEncryptKeyRingBroadcastMulticast = 2
109 // Unicast encryption, downstream only. Keys are generated by the ONU and transmitted to the OLT via the PLOAM channel.
110 GemEncryptKeyRingUnicastDownstreamOnly = 3
111)
Girish Gowdra09e5f212021-09-30 16:28:36 -0700112
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000113// CAniFsmIdleState - TODO: add comment
114const CAniFsmIdleState = aniStConfigDone
115
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000116type ponAniGemPortAttribs struct {
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530117 qosPolicy string
118 pbitString string
119 staticACL string
120 dynamicACL string
ozgecanetsia4b232302020-11-11 10:58:10 +0300121 gemPortID uint16
122 upQueueID uint16
123 downQueueID uint16
ozgecanetsia4b232302020-11-11 10:58:10 +0300124 multicastGemID uint16
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530125 direction uint8
126 weight uint8
127 isMulticast bool
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000128}
129
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530130// UniPonAniConfigFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000131type UniPonAniConfigFsm struct {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000132 pDeviceHandler cmn.IdeviceHandler
133 pOnuDeviceEntry cmn.IonuDeviceEntry
134 pOmciCC *cmn.OmciCC
135 pOnuUniPort *cmn.OnuUniPort
136 pUniTechProf *OnuUniTechProf
137 pOnuDB *devdb.OnuDeviceDB
Himani Chawla4d908332020-08-31 12:30:20 +0530138 omciMIdsResponseReceived chan bool //separate channel needed for checking multiInstance OMCI message responses
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000139 PAdaptFsm *cmn.AdapterFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000140 chSuccess chan<- uint8
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530141 pLastTxMeInstance *me.ManagedEntity
142 waitFlowDeleteChannel chan bool
143 deviceID string
144 techProfileType string
145 gemPortAttribsSlice []ponAniGemPortAttribs
146 requestEvent cmn.OnuDeviceEvent
147 mutexIsAwaitingResponse sync.RWMutex
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000148 mutexChanSet sync.RWMutex
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530149 mutexPLastTxMeInstance sync.RWMutex
mpagenko3dbcdd22020-07-22 07:38:45 +0000150 mapperSP0ID uint16
151 macBPCD0ID uint16
152 tcont0ID uint16
153 alloc0ID uint16
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530154 uniTpKey uniTP
155 techProfileID uint8
156 isCanceled bool
157 isAwaitingResponse bool
158 procStep uint8
159 chanSet bool
mpagenko8b07c1b2020-11-26 10:36:31 +0000160 requestEventOffset uint8 //used to indicate ConfigDone or Removed using successor (enum)
mpagenkobb47bc22021-04-20 13:29:09 +0000161 isWaitingForFlowDelete bool
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700162 tcontSetBefore bool
mpagenko3dbcdd22020-07-22 07:38:45 +0000163}
164
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530165// NewUniPonAniConfigFsm is the 'constructor' for the state machine to config the PON ANI ports of ONU UNI ports via OMCI
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000166func NewUniPonAniConfigFsm(ctx context.Context, apDevOmciCC *cmn.OmciCC, apUniPort *cmn.OnuUniPort, apUniTechProf *OnuUniTechProf,
Holger Hildebrandtc408f492022-07-14 08:39:24 +0000167 apOnuDB *devdb.OnuDeviceDB, aTechProfileID uint8, aTechProfileType string, aRequestEvent cmn.OnuDeviceEvent, aName string,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000168 apDeviceHandler cmn.IdeviceHandler, apOnuDeviceEntry cmn.IonuDeviceEntry, aCommChannel chan cmn.Message) *UniPonAniConfigFsm {
169 instFsm := &UniPonAniConfigFsm{
170 pDeviceHandler: apDeviceHandler,
171 pOnuDeviceEntry: apOnuDeviceEntry,
172 deviceID: apDeviceHandler.GetDeviceID(),
173 pOmciCC: apDevOmciCC,
174 pOnuUniPort: apUniPort,
175 pUniTechProf: apUniTechProf,
176 pOnuDB: apOnuDB,
177 techProfileID: aTechProfileID,
Holger Hildebrandtc408f492022-07-14 08:39:24 +0000178 techProfileType: aTechProfileType,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000179 requestEvent: aRequestEvent,
180 chanSet: false,
181 tcontSetBefore: false,
mpagenko3dbcdd22020-07-22 07:38:45 +0000182 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000183 instFsm.uniTpKey = uniTP{uniID: apUniPort.UniID, tpID: aTechProfileID}
mpagenkobb47bc22021-04-20 13:29:09 +0000184 instFsm.waitFlowDeleteChannel = make(chan bool)
mpagenko8b07c1b2020-11-26 10:36:31 +0000185
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000186 instFsm.PAdaptFsm = cmn.NewAdapterFsm(aName, instFsm.deviceID, aCommChannel)
187 if instFsm.PAdaptFsm == nil {
188 logger.Errorw(ctx, "UniPonAniConfigFsm's cmn.AdapterFsm could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000189 "device-id": instFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000190 return nil
191 }
192
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000193 instFsm.PAdaptFsm.PFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000194 aniStDisabled,
mpagenko3dbcdd22020-07-22 07:38:45 +0000195 fsm.Events{
196
mpagenko1cc3cb42020-07-27 15:24:38 +0000197 {Name: aniEvStart, Src: []string{aniStDisabled}, Dst: aniStStarting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000198
199 //Note: .1p-Mapper and MBPCD might also have multi instances (per T-Cont) - by now only one 1 T-Cont considered!
balaji.nagarajanca025612025-06-23 16:16:06 +0530200 {Name: aniEvPrepareConfig, Src: []string{aniStStarting}, Dst: aniStPrepareConfig},
201 {Name: aniEvStartConfig, Src: []string{aniStPrepareConfig}, Dst: aniStCreatingDot1PMapper},
mpagenkodff5dda2020-08-28 11:52:01 +0000202 {Name: aniEvRxDot1pmapCResp, Src: []string{aniStCreatingDot1PMapper}, Dst: aniStCreatingMBPCD},
mpagenko1cc3cb42020-07-27 15:24:38 +0000203 {Name: aniEvRxMbpcdResp, Src: []string{aniStCreatingMBPCD}, Dst: aniStSettingTconts},
204 {Name: aniEvRxTcontsResp, Src: []string{aniStSettingTconts}, Dst: aniStCreatingGemNCTPs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000205 // the creatingGemNCTPs state is used for multi ME config if required for all configured/available GemPorts
mpagenko1cc3cb42020-07-27 15:24:38 +0000206 {Name: aniEvRxGemntcpsResp, Src: []string{aniStCreatingGemNCTPs}, Dst: aniStCreatingGemIWs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000207 // the creatingGemIWs state is used for multi ME config if required for all configured/available GemPorts
mpagenko1cc3cb42020-07-27 15:24:38 +0000208 {Name: aniEvRxGemiwsResp, Src: []string{aniStCreatingGemIWs}, Dst: aniStSettingPQs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000209 // the settingPQs state is used for multi ME config if required for all configured/available upstream PriorityQueues
mpagenko1cc3cb42020-07-27 15:24:38 +0000210 {Name: aniEvRxPrioqsResp, Src: []string{aniStSettingPQs}, Dst: aniStSettingDot1PMapper},
mpagenkodff5dda2020-08-28 11:52:01 +0000211 {Name: aniEvRxDot1pmapSResp, Src: []string{aniStSettingDot1PMapper}, Dst: aniStConfigDone},
mpagenko3dbcdd22020-07-22 07:38:45 +0000212
mpagenko8b07c1b2020-11-26 10:36:31 +0000213 //for removing Gem related resources
214 {Name: aniEvRemGemiw, Src: []string{aniStConfigDone}, Dst: aniStRemovingGemIW},
Girish Gowdra26a40922021-01-29 17:14:34 -0800215 {Name: aniEvWaitFlowRem, Src: []string{aniStRemovingGemIW}, Dst: aniStWaitingFlowRem},
216 {Name: aniEvFlowRemDone, Src: []string{aniStWaitingFlowRem}, Dst: aniStRemovingGemIW},
mpagenko8b07c1b2020-11-26 10:36:31 +0000217 {Name: aniEvRxRemGemiwResp, Src: []string{aniStRemovingGemIW}, Dst: aniStRemovingGemNCTP},
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300218 {Name: aniEvRxRemGemntpResp, Src: []string{aniStRemovingGemNCTP}, Dst: aniStRemovingTD},
Mahir Gunyel9545be22021-07-04 15:53:16 -0700219 {Name: aniEvRxRemTdResp, Src: []string{aniStRemovingTD}, Dst: aniStRemDot1PMapper},
220 {Name: aniEvRemGemDone, Src: []string{aniStRemDot1PMapper}, Dst: aniStConfigDone},
221 {Name: aniEvRxRem1pMapperResp, Src: []string{aniStRemDot1PMapper}, Dst: aniStRemAniBPCD},
222 {Name: aniEvRxRemAniBPCDResp, Src: []string{aniStRemAniBPCD}, Dst: aniStRemoveDone},
mpagenko8b07c1b2020-11-26 10:36:31 +0000223
224 //for removing TCONT related resources
225 {Name: aniEvRemTcontPath, Src: []string{aniStConfigDone}, Dst: aniStResetTcont},
Mahir Gunyel9545be22021-07-04 15:53:16 -0700226 {Name: aniEvRxResetTcontResp, Src: []string{aniStResetTcont}, Dst: aniStConfigDone},
mpagenko8b07c1b2020-11-26 10:36:31 +0000227
228 {Name: aniEvTimeoutSimple, Src: []string{aniStCreatingDot1PMapper, aniStCreatingMBPCD, aniStSettingTconts, aniStSettingDot1PMapper,
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300229 aniStRemovingGemIW, aniStRemovingGemNCTP, aniStRemovingTD,
mpagenko8b07c1b2020-11-26 10:36:31 +0000230 aniStResetTcont, aniStRemDot1PMapper, aniStRemAniBPCD, aniStRemoveDone}, Dst: aniStStarting},
mpagenko1cc3cb42020-07-27 15:24:38 +0000231 {Name: aniEvTimeoutMids, Src: []string{
232 aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs}, Dst: aniStStarting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000233
mpagenko1cc3cb42020-07-27 15:24:38 +0000234 // exceptional treatment for all states except aniStResetting
balaji.nagarajanca025612025-06-23 16:16:06 +0530235 {Name: aniEvReset, Src: []string{aniStStarting, aniStPrepareConfig, aniStCreatingDot1PMapper, aniStCreatingMBPCD,
mpagenko1cc3cb42020-07-27 15:24:38 +0000236 aniStSettingTconts, aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs, aniStSettingDot1PMapper,
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300237 aniStConfigDone, aniStRemovingGemIW, aniStWaitingFlowRem, aniStRemovingGemNCTP, aniStRemovingTD,
mpagenko8b07c1b2020-11-26 10:36:31 +0000238 aniStResetTcont, aniStRemDot1PMapper, aniStRemAniBPCD, aniStRemoveDone}, Dst: aniStResetting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000239 // the only way to get to resource-cleared disabled state again is via "resseting"
mpagenko1cc3cb42020-07-27 15:24:38 +0000240 {Name: aniEvRestart, Src: []string{aniStResetting}, Dst: aniStDisabled},
balaji.nagarajanca025612025-06-23 16:16:06 +0530241 {Name: aniEvSkipOmciConfig, Src: []string{aniStStarting, aniStPrepareConfig}, Dst: aniStConfigDone},
mpagenko3dbcdd22020-07-22 07:38:45 +0000242 },
243
244 fsm.Callbacks{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000245 "enter_state": func(e *fsm.Event) { instFsm.PAdaptFsm.LogFsmStateChange(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000246 ("enter_" + aniStStarting): func(e *fsm.Event) { instFsm.enterConfigStartingState(ctx, e) },
balaji.nagarajanca025612025-06-23 16:16:06 +0530247 ("enter_" + aniStPrepareConfig): func(e *fsm.Event) { instFsm.prepareAndEnterConfigState(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000248 ("enter_" + aniStCreatingDot1PMapper): func(e *fsm.Event) { instFsm.enterCreatingDot1PMapper(ctx, e) },
249 ("enter_" + aniStCreatingMBPCD): func(e *fsm.Event) { instFsm.enterCreatingMBPCD(ctx, e) },
250 ("enter_" + aniStSettingTconts): func(e *fsm.Event) { instFsm.enterSettingTconts(ctx, e) },
251 ("enter_" + aniStCreatingGemNCTPs): func(e *fsm.Event) { instFsm.enterCreatingGemNCTPs(ctx, e) },
252 ("enter_" + aniStCreatingGemIWs): func(e *fsm.Event) { instFsm.enterCreatingGemIWs(ctx, e) },
253 ("enter_" + aniStSettingPQs): func(e *fsm.Event) { instFsm.enterSettingPQs(ctx, e) },
254 ("enter_" + aniStSettingDot1PMapper): func(e *fsm.Event) { instFsm.enterSettingDot1PMapper(ctx, e) },
255 ("enter_" + aniStConfigDone): func(e *fsm.Event) { instFsm.enterAniConfigDone(ctx, e) },
256 ("enter_" + aniStRemovingGemIW): func(e *fsm.Event) { instFsm.enterRemovingGemIW(ctx, e) },
mpagenkobb47bc22021-04-20 13:29:09 +0000257 ("enter_" + aniStWaitingFlowRem): func(e *fsm.Event) { instFsm.enterWaitingFlowRem(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000258 ("enter_" + aniStRemovingGemNCTP): func(e *fsm.Event) { instFsm.enterRemovingGemNCTP(ctx, e) },
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +0300259 ("enter_" + aniStRemovingTD): func(e *fsm.Event) { instFsm.enterRemovingTD(ctx, e) },
dbainbri4d3a0dc2020-12-02 00:33:42 +0000260 ("enter_" + aniStResetTcont): func(e *fsm.Event) { instFsm.enterResettingTcont(ctx, e) },
261 ("enter_" + aniStRemDot1PMapper): func(e *fsm.Event) { instFsm.enterRemoving1pMapper(ctx, e) },
262 ("enter_" + aniStRemAniBPCD): func(e *fsm.Event) { instFsm.enterRemovingAniBPCD(ctx, e) },
263 ("enter_" + aniStRemoveDone): func(e *fsm.Event) { instFsm.enterAniRemoveDone(ctx, e) },
264 ("enter_" + aniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(ctx, e) },
265 ("enter_" + aniStDisabled): func(e *fsm.Event) { instFsm.enterDisabledState(ctx, e) },
mpagenko3dbcdd22020-07-22 07:38:45 +0000266 },
267 )
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000268 if instFsm.PAdaptFsm.PFsm == nil {
269 logger.Errorw(ctx, "UniPonAniConfigFsm's Base FSM could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000270 "device-id": instFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000271 return nil
272 }
273
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000274 logger.Debugw(ctx, "UniPonAniConfigFsm created", log.Fields{"device-id": instFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000275 return instFsm
276}
277
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530278// setFsmCompleteChannel sets the requested channel and channel result for transfer on success
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000279func (oFsm *UniPonAniConfigFsm) setFsmCompleteChannel(aChSuccess chan<- uint8, aProcStep uint8) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000280 oFsm.chSuccess = aChSuccess
281 oFsm.procStep = aProcStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000282 oFsm.setChanSet(true)
mpagenko3dbcdd22020-07-22 07:38:45 +0000283}
284
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530285// CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000286func (oFsm *UniPonAniConfigFsm) CancelProcessing(ctx context.Context) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530287 logger.Info(ctx, "CancelProcessing entered", log.Fields{"device-id": oFsm.deviceID})
mpagenko73143992021-04-09 15:17:10 +0000288 //early indication about started reset processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000289 oFsm.pUniTechProf.setProfileResetting(ctx, oFsm.pOnuUniPort.UniID, oFsm.techProfileID, true)
mpagenko7d6bb022021-03-11 15:07:55 +0000290 //mutex protection is required for possible concurrent access to FSM members
mpagenkocf48e452021-04-23 09:23:00 +0000291 oFsm.mutexIsAwaitingResponse.Lock()
292 oFsm.isCanceled = true
mpagenko7d6bb022021-03-11 15:07:55 +0000293 if oFsm.isAwaitingResponse {
mpagenkocf48e452021-04-23 09:23:00 +0000294 //attention: for an unbuffered channel the sender is blocked until the value is received (processed)!
295 // accordingly the mutex must be released before sending to channel here (mutex acquired in receiver)
296 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko7d6bb022021-03-11 15:07:55 +0000297 //use channel to indicate that the response waiting shall be aborted
298 oFsm.omciMIdsResponseReceived <- false
mpagenkocf48e452021-04-23 09:23:00 +0000299 } else {
300 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko7d6bb022021-03-11 15:07:55 +0000301 }
mpagenkocf48e452021-04-23 09:23:00 +0000302
303 oFsm.mutexIsAwaitingResponse.Lock()
mpagenkobb47bc22021-04-20 13:29:09 +0000304 if oFsm.isWaitingForFlowDelete {
mpagenkocf48e452021-04-23 09:23:00 +0000305 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenkobb47bc22021-04-20 13:29:09 +0000306 //use channel to indicate that the response waiting shall be aborted
307 oFsm.waitFlowDeleteChannel <- false
mpagenkocf48e452021-04-23 09:23:00 +0000308 } else {
309 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenkobb47bc22021-04-20 13:29:09 +0000310 }
mpagenkocf48e452021-04-23 09:23:00 +0000311
mpagenko7d6bb022021-03-11 15:07:55 +0000312 // in any case (even if it might be automatically requested by above cancellation of waiting) ensure resetting the FSM
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000313 PAdaptFsm := oFsm.PAdaptFsm
314 if PAdaptFsm != nil {
mpagenko7d6bb022021-03-11 15:07:55 +0000315 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
balaji.nagarajanca025612025-06-23 16:16:06 +0530316 if PAdaptFsm.PFsm != nil {
317 _ = PAdaptFsm.PFsm.Event(aniEvReset)
318 }
mpagenko7d6bb022021-03-11 15:07:55 +0000319 }
mpagenko73143992021-04-09 15:17:10 +0000320
mpagenko45cc6a32021-07-23 10:06:57 +0000321 // possible access conflicts on internal data by next needed data clearance
322 // are avoided by using mutexTPState also from within clearAniSideConfig
323 // do not try to lock TpProcMutex here as done in previous code version
324 // as it may result in deadlock situations (as observed at soft-reboot handling where
325 // TpProcMutex is already locked by some ongoing TechProfile config/removal processing
mpagenko73143992021-04-09 15:17:10 +0000326 //remove all TechProf related internal data to allow for new configuration
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000327 oFsm.pUniTechProf.clearAniSideConfig(ctx, oFsm.pOnuUniPort.UniID, oFsm.techProfileID)
mpagenko7d6bb022021-03-11 15:07:55 +0000328}
329
balaji.nagarajanca025612025-06-23 16:16:06 +0530330//nolint:gocyclo
331func (oFsm *UniPonAniConfigFsm) prepareAndEnterConfigState(ctx context.Context, _ *fsm.Event) {
332 logger.Info(ctx, "UniPonAniConfigFsm prepareAndEnterConfigState start", log.Fields{
333 "device-id": oFsm.deviceID})
334 aPAFsm := oFsm.PAdaptFsm
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000335 if aPAFsm != nil && aPAFsm.PFsm != nil {
Mahir Gunyel6781f962021-05-16 23:30:08 -0700336 var err error
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000337 oFsm.mapperSP0ID, err = cmn.GenerateIeeMaperServiceProfileEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.techProfileID))
Mahir Gunyel6781f962021-05-16 23:30:08 -0700338 if err != nil {
339 logger.Errorw(ctx, "error generating maper id", log.Fields{"device-id": oFsm.deviceID,
340 "techProfileID": oFsm.techProfileID, "error": err})
341 return
342 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000343 oFsm.macBPCD0ID, err = cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.techProfileID))
Mahir Gunyel6781f962021-05-16 23:30:08 -0700344 if err != nil {
345 logger.Errorw(ctx, "error generating mbpcd id", log.Fields{"device-id": oFsm.deviceID,
346 "techProfileID": oFsm.techProfileID, "error": err})
347 return
348 }
349 logger.Debugw(ctx, "generated ids for ani config", log.Fields{"mapperSP0ID": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
350 "macBPCD0ID": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16), "device-id": oFsm.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000351 "macBpNo": oFsm.pOnuUniPort.MacBpNo, "techProfileID": oFsm.techProfileID})
352 if oFsm.pOnuDeviceEntry == nil {
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700353 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": oFsm.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800354 return
Himani Chawla26e555c2020-08-31 12:30:20 +0530355 }
bseenivaeba8eb12024-12-13 11:54:28 +0530356 // Access critical state with lock
357 oFsm.pUniTechProf.mutexTPState.RLock()
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +0530358 // Set T-Cont in device irrespective of whether it is stored in onu-adapter or not
359 tcontInstID, _, err := oFsm.pOnuDeviceEntry.AllocateFreeTcont(ctx, oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700360 if err != nil {
361 logger.Errorw(ctx, "No TCont instances found", log.Fields{"device-id": oFsm.deviceID, "err": err})
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700362 //reset the state machine to enable usage on subsequent requests
bseenivaeba8eb12024-12-13 11:54:28 +0530363 oFsm.pUniTechProf.mutexTPState.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000364 _ = aPAFsm.PFsm.Event(aniEvReset)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700365 return
366 }
367 oFsm.tcont0ID = tcontInstID
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700368 logger.Debugw(ctx, "used-tcont-instance-id", log.Fields{"tcont-inst-id": oFsm.tcont0ID,
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +0530369 "alloc-id": oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID,
370 "device-id": oFsm.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800371
mpagenko8b07c1b2020-11-26 10:36:31 +0000372 oFsm.alloc0ID = oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID
373 mapGemPortParams := oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].mapGemPortParams
mpagenko3ce9fa02021-07-28 13:26:54 +0000374 oFsm.pUniTechProf.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800375
Himani Chawla26e555c2020-08-31 12:30:20 +0530376 //for all TechProfile set GemIndices
Girish Gowdra041dcb32020-11-16 16:54:30 -0800377 for _, gemEntry := range mapGemPortParams {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300378 loGemPortAttribs := ponAniGemPortAttribs{}
379
Himani Chawla26e555c2020-08-31 12:30:20 +0530380 //collect all GemConfigData in a separate Fsm related slice (needed also to avoid mix-up with unsorted mapPonAniConfig)
381
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000382 if queueInstKeys := oFsm.pOnuDB.GetSortedInstKeys(ctx, me.PriorityQueueClassID); len(queueInstKeys) > 0 {
Himani Chawla26e555c2020-08-31 12:30:20 +0530383
384 loGemPortAttribs.gemPortID = gemEntry.gemPortID
385 // MibDb usage: upstream PrioQueue.RelatedPort = xxxxyyyy with xxxx=TCont.Entity(incl. slot) and yyyy=prio
386 // i.e.: search PrioQueue list with xxxx=actual T-Cont.Entity,
387 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == yyyy (expect 0..7)
388 usQrelPortMask := uint32((((uint32)(oFsm.tcont0ID)) << 16) + uint32(gemEntry.prioQueueIndex))
389
390 // MibDb usage: downstream PrioQueue.RelatedPort = xxyyzzzz with xx=slot, yy=UniPort and zzzz=prio
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000391 // i.e.: search PrioQueue list with yy=actual pOnuUniPort.UniID,
Himani Chawla26e555c2020-08-31 12:30:20 +0530392 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == zzzz (expect 0..7)
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +0000393 // Note: As we do not maintain any slot numbering, slot number will be excluded from search pattern.
Himani Chawla26e555c2020-08-31 12:30:20 +0530394 // Furthermore OMCI Onu port-Id is expected to start with 1 (not 0).
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000395 dsQrelPortMask := uint32((((uint32)(oFsm.pOnuUniPort.UniID + 1)) << 16) + uint32(gemEntry.prioQueueIndex))
Himani Chawla26e555c2020-08-31 12:30:20 +0530396
397 usQueueFound := false
398 dsQueueFound := false
399 for _, mgmtEntityID := range queueInstKeys {
400 if meAttributes := oFsm.pOnuDB.GetMe(me.PriorityQueueClassID, mgmtEntityID); meAttributes != nil {
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000401 returnVal := meAttributes[me.PriorityQueue_RelatedPort]
Himani Chawla26e555c2020-08-31 12:30:20 +0530402 if returnVal != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000403 if relatedPort, err := oFsm.pOnuDB.GetUint32Attrib(returnVal); err == nil {
Himani Chawla26e555c2020-08-31 12:30:20 +0530404 if relatedPort == usQrelPortMask {
405 loGemPortAttribs.upQueueID = mgmtEntityID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000406 logger.Debugw(ctx, "UpQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
mpagenko01e726e2020-10-23 09:45:29 +0000407 "upQueueID": strconv.FormatInt(int64(loGemPortAttribs.upQueueID), 16), "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530408 usQueueFound = true
409 } else if (relatedPort&0xFFFFFF) == dsQrelPortMask && mgmtEntityID < 0x8000 {
410 loGemPortAttribs.downQueueID = mgmtEntityID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000411 logger.Debugw(ctx, "DownQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
mpagenko01e726e2020-10-23 09:45:29 +0000412 "downQueueID": strconv.FormatInt(int64(loGemPortAttribs.downQueueID), 16), "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530413 dsQueueFound = true
414 }
415 if usQueueFound && dsQueueFound {
416 break
417 }
418 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000419 logger.Warnw(ctx, "Could not convert attribute value", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530420 }
421 } else {
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000422 logger.Warnw(ctx, "PrioQueue.RelatedPort not found in meAttributes:", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530423 }
424 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000425 logger.Warnw(ctx, "No attributes available in DB:", log.Fields{"meClassID": me.PriorityQueueClassID,
mpagenko01e726e2020-10-23 09:45:29 +0000426 "mgmtEntityID": mgmtEntityID, "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530427 }
428 }
429 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000430 logger.Warnw(ctx, "No PriorityQueue instances found", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530431 }
432 loGemPortAttribs.direction = gemEntry.direction
433 loGemPortAttribs.qosPolicy = gemEntry.queueSchedPolicy
434 loGemPortAttribs.weight = gemEntry.queueWeight
435 loGemPortAttribs.pbitString = gemEntry.pbitString
ozgecanetsia82b91a62021-05-21 18:54:49 +0300436
ozgecanetsia4b232302020-11-11 10:58:10 +0300437 if gemEntry.isMulticast {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300438 //TODO this might effectively ignore the for loop starting at line 316
439 loGemPortAttribs.gemPortID = gemEntry.multicastGemPortID
ozgecanetsia4b232302020-11-11 10:58:10 +0300440 loGemPortAttribs.isMulticast = true
441 loGemPortAttribs.multicastGemID = gemEntry.multicastGemPortID
442 loGemPortAttribs.staticACL = gemEntry.staticACL
443 loGemPortAttribs.dynamicACL = gemEntry.dynamicACL
Himani Chawla26e555c2020-08-31 12:30:20 +0530444
dbainbri4d3a0dc2020-12-02 00:33:42 +0000445 logger.Debugw(ctx, "Multicast GemPort attributes:", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300446 "gemPortID": loGemPortAttribs.gemPortID,
447 "isMulticast": loGemPortAttribs.isMulticast,
448 "multicastGemID": loGemPortAttribs.multicastGemID,
449 "staticACL": loGemPortAttribs.staticACL,
450 "dynamicACL": loGemPortAttribs.dynamicACL,
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000451 "device-id": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300452 })
453
454 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000455 logger.Debugw(ctx, "Upstream GemPort attributes:", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300456 "gemPortID": loGemPortAttribs.gemPortID,
457 "upQueueID": loGemPortAttribs.upQueueID,
458 "downQueueID": loGemPortAttribs.downQueueID,
459 "pbitString": loGemPortAttribs.pbitString,
460 "prioQueueIndex": gemEntry.prioQueueIndex,
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000461 "device-id": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300462 })
463 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530464
465 oFsm.gemPortAttribsSlice = append(oFsm.gemPortAttribsSlice, loGemPortAttribs)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530466 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
467 meParams := me.ParamData{
468 EntityID: loGemPortAttribs.gemPortID,
469 Attributes: me.AttributeValueMap{
470 me.GemPortNetworkCtp_PortId: loGemPortAttribs.gemPortID,
471 me.GemPortNetworkCtp_TContPointer: oFsm.tcont0ID,
472 me.GemPortNetworkCtp_Direction: loGemPortAttribs.direction,
473 me.GemPortNetworkCtp_TrafficManagementPointerForUpstream: loGemPortAttribs.upQueueID,
474 me.GemPortNetworkCtp_PriorityQueuePointerForDownStream: loGemPortAttribs.downQueueID,
475 },
476 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530477 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpClassID, loGemPortAttribs.gemPortID, meParams.Attributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530478 var meAttributes me.AttributeValueMap //dummy , anyways we are not going to use the values.
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530479 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID, loGemPortAttribs.gemPortID, meAttributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530480
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530481 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemInterworkingTerminationPointClassID, loGemPortAttribs.gemPortID, meAttributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530482
483 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530484 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000485 if !oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
balaji.nagarajanca025612025-06-23 16:16:06 +0530486 //let the state machine run forward from here directly
487 if oFsm.PAdaptFsm != nil {
488 go func(aPAFsm *cmn.AdapterFsm) {
489 if aPAFsm != nil && aPAFsm.PFsm != nil {
490 _ = aPAFsm.PFsm.Event(aniEvStartConfig)
491 }
492 }(oFsm.PAdaptFsm)
493
494 }
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000495 } else {
496 logger.Debugw(ctx, "reconciling - skip omci-config of ANI side ", log.Fields{"device-id": oFsm.deviceID})
balaji.nagarajanca025612025-06-23 16:16:06 +0530497 //let the state machine run forward from here directly
498 if oFsm.PAdaptFsm != nil {
499 go func(aPAFsm *cmn.AdapterFsm) {
500 if aPAFsm != nil && aPAFsm.PFsm != nil {
501 _ = aPAFsm.PFsm.Event(aniEvSkipOmciConfig)
502 }
503 }(oFsm.PAdaptFsm)
504
505 }
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000506 }
balaji.nagarajanca025612025-06-23 16:16:06 +0530507 logger.Info(ctx, "UniPonAniConfigFsm prepareAndEnterConfigState end", log.Fields{
508 "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530509 }
510}
511
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530512//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000513func (oFsm *UniPonAniConfigFsm) enterConfigStartingState(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530514 logger.Info(ctx, "UniPonAniConfigFsm start", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000515 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000516 // in case the used channel is not yet defined (can be re-used after restarts)
517 if oFsm.omciMIdsResponseReceived == nil {
518 oFsm.omciMIdsResponseReceived = make(chan bool)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000519 logger.Debug(ctx, "UniPonAniConfigFsm - OMCI multiInstance RxChannel defined")
mpagenko3dbcdd22020-07-22 07:38:45 +0000520 } else {
521 // as we may 're-use' this instance of FSM and the connected channel
522 // make sure there is no 'lingering' request in the already existing channel:
523 // (simple loop sufficient as we are the only receiver)
524 for len(oFsm.omciMIdsResponseReceived) > 0 {
525 <-oFsm.omciMIdsResponseReceived
526 }
527 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000528 //ensure internal slices are empty (which might be set from previous run) - release memory
529 oFsm.gemPortAttribsSlice = nil
mpagenkocf48e452021-04-23 09:23:00 +0000530 oFsm.mutexIsAwaitingResponse.Lock()
531 //reset the canceled state possibly existing from previous reset
532 oFsm.isCanceled = false
533 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000534
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000535 // start go routine for processing of ANI config messages
dbainbri4d3a0dc2020-12-02 00:33:42 +0000536 go oFsm.processOmciAniMessages(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000537
538 //let the state machine run forward from here directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000539 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000540 if pConfigAniStateAFsm != nil {
541 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
balaji.nagarajanca025612025-06-23 16:16:06 +0530542 go func(aPAFsm *cmn.AdapterFsm) {
543 if aPAFsm != nil && aPAFsm.PFsm != nil {
544 _ = aPAFsm.PFsm.Event(aniEvPrepareConfig)
545 }
546 }(pConfigAniStateAFsm)
mpagenko3dbcdd22020-07-22 07:38:45 +0000547
mpagenko3dbcdd22020-07-22 07:38:45 +0000548 }
549}
550
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530551//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000552func (oFsm *UniPonAniConfigFsm) enterCreatingDot1PMapper(ctx context.Context, e *fsm.Event) {
553 logger.Debugw(ctx, "UniPonAniConfigFsm Tx Create::Dot1PMapper", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000554 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000555 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000556 oFsm.requestEventOffset = 0 //0 offset for last config request activity
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000557 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000558 meInstance, err := oFsm.pOmciCC.SendCreateDot1PMapper(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
559 oFsm.mapperSP0ID, oFsm.PAdaptFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300560 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000561 logger.Errorw(ctx, "Dot1PMapper create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300562 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000563 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300564 if pConfigAniStateAFsm != nil {
565 oFsm.mutexPLastTxMeInstance.Unlock()
566 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000567 go func(aPAFsm *cmn.AdapterFsm) {
568 if aPAFsm != nil && aPAFsm.PFsm != nil {
569 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300570 }
571 }(pConfigAniStateAFsm)
572 return
573 }
574 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000575 //accept also nil as (error) return value for writing to LastTx
576 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000577 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300578 oFsm.mutexPLastTxMeInstance.Unlock()
579
mpagenko3dbcdd22020-07-22 07:38:45 +0000580}
581
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530582//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000583func (oFsm *UniPonAniConfigFsm) enterCreatingMBPCD(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530584 logger.Info(ctx, "Creating Tx MAC Bridge Port Config Data", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000585 "EntitytId": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16),
586 "TPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000587 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
588 bridgePtr := cmn.MacBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.MacBpNo) //cmp also omci_cc.go::sendCreateMBServiceProfile
mpagenko3dbcdd22020-07-22 07:38:45 +0000589 meParams := me.ParamData{
590 EntityID: oFsm.macBPCD0ID,
591 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000592 me.MacBridgePortConfigurationData_BridgeIdPointer: bridgePtr,
593 me.MacBridgePortConfigurationData_PortNum: 0xFF, //fixed unique ANI side indication
594 me.MacBridgePortConfigurationData_TpType: 3, //for .1PMapper
595 me.MacBridgePortConfigurationData_TpPointer: oFsm.mapperSP0ID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000596 },
597 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000598 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000599 meInstance, err := oFsm.pOmciCC.SendCreateMBPConfigDataVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
600 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300601 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000602 logger.Errorw(ctx, "MBPConfigDataVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300603 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000604 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300605 if pConfigAniStateAFsm != nil {
606 oFsm.mutexPLastTxMeInstance.Unlock()
607 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000608 go func(aPAFsm *cmn.AdapterFsm) {
609 if aPAFsm != nil && aPAFsm.PFsm != nil {
610 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300611 }
612 }(pConfigAniStateAFsm)
613 return
614 }
615 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000616 //accept also nil as (error) return value for writing to LastTx
617 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000618 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300619 oFsm.mutexPLastTxMeInstance.Unlock()
620
mpagenko3dbcdd22020-07-22 07:38:45 +0000621}
622
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530623//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000624func (oFsm *UniPonAniConfigFsm) enterSettingTconts(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530625 logger.Info(ctx, "Tx Setting Tcont ", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000626 "EntitytId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
627 "AllocId": strconv.FormatInt(int64(oFsm.alloc0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000628 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700629 "tcontExist": oFsm.tcontSetBefore})
630 //If tcont was set before, then no need to set it again. Let state machine to proceed.
631 if oFsm.tcontSetBefore {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000632 go func(aPAFsm *cmn.AdapterFsm) {
633 if aPAFsm != nil && aPAFsm.PFsm != nil {
634 _ = aPAFsm.PFsm.Event(aniEvRxTcontsResp)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700635 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000636 }(oFsm.PAdaptFsm)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700637 return
638 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000639 meParams := me.ParamData{
640 EntityID: oFsm.tcont0ID,
641 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000642 me.TCont_AllocId: oFsm.alloc0ID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000643 },
644 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000645 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000646 meInstance, err := oFsm.pOmciCC.SendSetTcontVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
647 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300648 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000649 logger.Errorw(ctx, "TcontVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300650 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000651 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300652 if pConfigAniStateAFsm != nil {
653 oFsm.mutexPLastTxMeInstance.Unlock()
654 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000655 go func(aPAFsm *cmn.AdapterFsm) {
656 if aPAFsm != nil && aPAFsm.PFsm != nil {
657 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300658 }
659 }(pConfigAniStateAFsm)
660 return
661 }
662 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000663 //accept also nil as (error) return value for writing to LastTx
664 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000665 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300666 oFsm.mutexPLastTxMeInstance.Unlock()
667
mpagenko3dbcdd22020-07-22 07:38:45 +0000668}
669
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530670//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000671func (oFsm *UniPonAniConfigFsm) enterCreatingGemNCTPs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530672 logger.Info(ctx, "UniPonAniConfigFsm - start creating GemNWCtp loop", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000673 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000674 go oFsm.performCreatingGemNCTPs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000675}
676
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530677//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000678func (oFsm *UniPonAniConfigFsm) enterCreatingGemIWs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530679 logger.Info(ctx, "UniPonAniConfigFsm - start creating GemIwTP loop", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000680 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000681 go oFsm.performCreatingGemIWs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000682}
683
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000684func (oFsm *UniPonAniConfigFsm) enterSettingPQs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530685 logger.Info(ctx, "UniPonAniConfigFsm - start setting PrioQueue loop", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000686 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000687 go oFsm.performSettingPQs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000688}
689
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000690func (oFsm *UniPonAniConfigFsm) enterSettingDot1PMapper(ctx context.Context, e *fsm.Event) {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300691
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530692 logger.Info(ctx, "UniPonAniConfigFsm Tx Set::.1pMapper with all PBits set", log.Fields{"EntitytId": 0x8042, /*cmp above*/
mpagenko8b07c1b2020-11-26 10:36:31 +0000693 "toGemIw": 1024, /* cmp above */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000694 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000695
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530696 logger.Info(ctx, "UniPonAniConfigFsm Tx Set::1pMapper", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000697 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +0000698 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000699
mpagenko3dbcdd22020-07-22 07:38:45 +0000700 meParams := me.ParamData{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000701 EntityID: oFsm.mapperSP0ID,
Himani Chawla4d908332020-08-31 12:30:20 +0530702 Attributes: make(me.AttributeValueMap),
mpagenko3dbcdd22020-07-22 07:38:45 +0000703 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000704
705 //assign the GemPorts according to the configured Prio
706 var loPrioGemPortArray [8]uint16
707 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300708 if gemPortAttribs.isMulticast {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000709 logger.Debugw(ctx, "UniPonAniConfigFsm Port is Multicast, ignoring .1pMapper", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300710 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
711 "prioString": gemPortAttribs.pbitString})
712 continue
713 }
714 if gemPortAttribs.pbitString == "" {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000715 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString empty string error", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300716 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
717 "prioString": gemPortAttribs.pbitString})
718 continue
719 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000720 for i := 0; i < 8; i++ {
721 // "lenOfPbitMap(8) - i + 1" will give i-th pbit value from LSB position in the pbit map string
722 if prio, err := strconv.Atoi(string(gemPortAttribs.pbitString[7-i])); err == nil {
723 if prio == 1 { // Check this p-bit is set
724 if loPrioGemPortArray[i] == 0 {
725 loPrioGemPortArray[i] = gemPortAttribs.gemPortID //gemPortId=EntityID and unique
726 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000727 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString not unique", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000728 "device-id": oFsm.deviceID, "IgnoredGemPort": gemPortAttribs.gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000729 "SetGemPort": loPrioGemPortArray[i]})
730 }
731 }
732 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000733 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString evaluation error", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000734 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000735 "prioString": gemPortAttribs.pbitString, "position": i})
736 }
737
738 }
739 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300740
ozgecanetsia4b232302020-11-11 10:58:10 +0300741 var foundIwPtr = false
Himani Chawla4d908332020-08-31 12:30:20 +0530742 for index, value := range loPrioGemPortArray {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300743 meAttribute := fmt.Sprintf("InterworkTpPointerForPBitPriority%d", index)
Himani Chawla4d908332020-08-31 12:30:20 +0530744 if value != 0 {
745 foundIwPtr = true
Himani Chawla4d908332020-08-31 12:30:20 +0530746 meParams.Attributes[meAttribute] = value
dbainbri4d3a0dc2020-12-02 00:33:42 +0000747 logger.Debugw(ctx, "UniPonAniConfigFsm Set::1pMapper", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000748 "for Prio": index,
749 "IwPtr": strconv.FormatInt(int64(value), 16),
750 "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300751 } else {
752 // The null pointer 0xFFFF specifies that frames with the associated priority are to be discarded.
mpagenko8b5fdd22020-12-17 17:58:32 +0000753 // setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting
754 // but except for processing effort does not really harm - left to keep changes low
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300755 meParams.Attributes[meAttribute] = 0xffff
Himani Chawla4d908332020-08-31 12:30:20 +0530756 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000757 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300758 // The TP type value 0 also indicates bridging mapping, and the TP pointer should be set to 0xFFFF
mpagenko8b5fdd22020-12-17 17:58:32 +0000759 // setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting
760 // but except for processing effort does not really harm - left to keep changes low
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000761 meParams.Attributes[me.Ieee8021PMapperServiceProfile_TpPointer] = 0xffff
Himani Chawla4d908332020-08-31 12:30:20 +0530762
763 if !foundIwPtr {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530764 logger.Warn(ctx, "UniPonAniConfigFsm no GemIwPtr found for .1pMapper - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000765 "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300766 //TODO With multicast is possible that no upstream gem ports are not present in the tech profile,
767 // 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 +0000768 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000769 //pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300770 //if pConfigAniStateAFsm != nil {
771 // // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000772 // go func(aPAFsm *cmn.AdapterFsm) {
773 // if aPAFsm != nil && aPAFsm.PFsm != nil {
774 // _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300775 // }
776 // }(pConfigAniStateAFsm)
777 //}
778 //Moving forward the FSM as if the response was received correctly.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000779 pConfigAniStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000780 if pConfigAniStateAFsm != nil {
781 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000782 go func(aPAFsm *cmn.AdapterFsm) {
783 if aPAFsm != nil && aPAFsm.PFsm != nil {
784 _ = aPAFsm.PFsm.Event(aniEvRxDot1pmapSResp)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000785 }
786 }(pConfigAniStateAFsm)
787 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300788 } else {
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000789 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000790 meInstance, err := oFsm.pOmciCC.SendSetDot1PMapperVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(), true,
791 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300792 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000793 logger.Errorw(ctx, "Dot1PMapperVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300794 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000795 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300796 if pConfigAniStateAFsm != nil {
797 oFsm.mutexPLastTxMeInstance.Unlock()
798 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000799 go func(aPAFsm *cmn.AdapterFsm) {
800 if aPAFsm != nil && aPAFsm.PFsm != nil {
801 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300802 }
803 }(pConfigAniStateAFsm)
804 return
805 }
806 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300807 //accept also nil as (error) return value for writing to LastTx
808 // - this avoids misinterpretation of new received OMCI messages
809 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300810 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000811 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000812}
813
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000814func (oFsm *UniPonAniConfigFsm) enterAniConfigDone(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530815 logger.Info(ctx, "UniPonAniConfigFsm ani config done", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000816 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenko01e726e2020-10-23 09:45:29 +0000817 //store that the UNI related techProfile processing is done for the given Profile and Uni
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000818 oFsm.pUniTechProf.setConfigDone(oFsm.pOnuUniPort.UniID, oFsm.techProfileID, true)
819 if !oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000820 //use DeviceHandler event notification directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000821 oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset)))
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000822 //if techProfile processing is done it must be checked, if some prior/parallel flow configuration is pending
823 // but only in case the techProfile was configured (not deleted)
824 if oFsm.requestEventOffset == 0 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000825 go oFsm.pDeviceHandler.VerifyUniVlanConfigRequest(ctx, oFsm.pOnuUniPort, oFsm.techProfileID)
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000826 }
827 } else {
828 logger.Debugw(ctx, "reconciling - skip AniConfigDone processing", log.Fields{"device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000829 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000830 if oFsm.isChanSet() {
mpagenko01e726e2020-10-23 09:45:29 +0000831 // indicate processing done to the caller
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000832 logger.Debugw(ctx, "UniPonAniConfigFsm processingDone on channel", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000833 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
834 oFsm.chSuccess <- oFsm.procStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000835 oFsm.setChanSet(false) //reset the internal channel state
mpagenko3dbcdd22020-07-22 07:38:45 +0000836 }
mpagenko01e726e2020-10-23 09:45:29 +0000837
838 //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 +0000839}
840
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530841//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000842func (oFsm *UniPonAniConfigFsm) enterRemovingGemIW(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +0000843 // no need to protect access to oFsm.waitFlowDeleteChannel, only used in synchronized state entries
844 // or CancelProcessing() that uses separate isWaitingForFlowDelete to write to the channel
mpagenkobb47bc22021-04-20 13:29:09 +0000845 //flush the waitFlowDeleteChannel - possibly already/still set by some previous activity
846 select {
847 case <-oFsm.waitFlowDeleteChannel:
848 logger.Debug(ctx, "flushed waitFlowDeleteChannel")
849 default:
850 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000851
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000852 uniVlanConfigFsm := oFsm.pDeviceHandler.GetUniVlanConfigFsm(oFsm.pOnuUniPort.UniID)
853 if uniVlanConfigFsm != nil {
mpagenko3ce9fa02021-07-28 13:26:54 +0000854 // ensure mutexTPState not locked before calling some VlanConfigFsm activity (that might already be pending on it)
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000855 if uniVlanConfigFsm.IsFlowRemovePending(ctx, oFsm.waitFlowDeleteChannel) {
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000856 logger.Debugw(ctx, "flow remove pending - wait before processing gem port delete",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000857 log.Fields{"device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000858 // 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 +0000859 pConfigAniStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000860 if pConfigAniStateAFsm != nil {
861 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000862 go func(aPAFsm *cmn.AdapterFsm) {
863 if aPAFsm != nil && aPAFsm.PFsm != nil {
864 _ = aPAFsm.PFsm.Event(aniEvWaitFlowRem)
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000865 }
866 }(pConfigAniStateAFsm)
867 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000868 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 +0000869 }
870 return
Girish Gowdra26a40922021-01-29 17:14:34 -0800871 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000872 } else {
873 logger.Debugw(ctx, "uni vlan config doesn't exist - no flow remove could be pending",
874 log.Fields{"device-id": oFsm.deviceID, "techProfile-id": oFsm.techProfileID})
Girish Gowdra26a40922021-01-29 17:14:34 -0800875 }
876
mpagenko3ce9fa02021-07-28 13:26:54 +0000877 oFsm.pUniTechProf.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000878 // get the related GemPort entity Id from pUniTechProf, OMCI Gem* entityID is set to be equal to GemPortId!
mpagenko8b07c1b2020-11-26 10:36:31 +0000879 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +0000880 oFsm.pUniTechProf.mutexTPState.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000881 logger.Debugw(ctx, "UniPonAniConfigFsm - start removing one GemIwTP", log.Fields{
882 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko8b07c1b2020-11-26 10:36:31 +0000883 "GemIwTp-entity-id": loGemPortID})
884 oFsm.requestEventOffset = 1 //offset 1 to indicate last activity = remove
885
886 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000887 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000888 meInstance, err := oFsm.pOmciCC.SendDeleteGemIWTP(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
889 oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300890 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000891 logger.Errorw(ctx, "GemIWTP delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300892 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000893 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300894 if pConfigAniStateAFsm != nil {
895 oFsm.mutexPLastTxMeInstance.Unlock()
896 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000897 go func(aPAFsm *cmn.AdapterFsm) {
898 if aPAFsm != nil && aPAFsm.PFsm != nil {
899 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300900 }
901 }(pConfigAniStateAFsm)
902 return
903 }
904 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000905 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300906 oFsm.mutexPLastTxMeInstance.Unlock()
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530907 logger.Infow(ctx, "Deleting GemIWTP at the ONU DB ", log.Fields{"device-id": oFsm.deviceID, "GEMID": loGemPortID})
908 oFsm.pOnuDB.DeleteMe(me.GemInterworkingTerminationPointClassID, loGemPortID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000909}
910
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530911//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000912func (oFsm *UniPonAniConfigFsm) enterWaitingFlowRem(ctx context.Context, e *fsm.Event) {
mpagenkobb47bc22021-04-20 13:29:09 +0000913 oFsm.mutexIsAwaitingResponse.Lock()
914 oFsm.isWaitingForFlowDelete = true
915 oFsm.mutexIsAwaitingResponse.Unlock()
916 select {
917 // maybe be also some outside cancel (but no context modeled for the moment ...)
918 // case <-ctx.Done():
919 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000920 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 +0000921 logger.Warnw(ctx, "UniPonAniConfigFsm WaitingFlowRem timeout", log.Fields{
922 "for device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000923 oFsm.mutexIsAwaitingResponse.Lock()
924 oFsm.isWaitingForFlowDelete = false
925 oFsm.mutexIsAwaitingResponse.Unlock()
926 //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 +0000927 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000928 if pConfigAniStateAFsm != nil {
929 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000930 go func(aPAFsm *cmn.AdapterFsm) {
931 if aPAFsm != nil && aPAFsm.PFsm != nil {
932 _ = aPAFsm.PFsm.Event(aniEvFlowRemDone)
mpagenkobb47bc22021-04-20 13:29:09 +0000933 }
934 }(pConfigAniStateAFsm)
935 } else {
936 logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000937 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000938 }
939 return
940
941 case success := <-oFsm.waitFlowDeleteChannel:
942 if success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000943 logger.Debugw(ctx, "UniPonAniConfigFsm flow removed info received", log.Fields{
944 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000945 oFsm.mutexIsAwaitingResponse.Lock()
946 oFsm.isWaitingForFlowDelete = false
947 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000948 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000949 if pConfigAniStateAFsm != nil {
950 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000951 go func(aPAFsm *cmn.AdapterFsm) {
952 if aPAFsm != nil && aPAFsm.PFsm != nil {
953 _ = aPAFsm.PFsm.Event(aniEvFlowRemDone)
mpagenkobb47bc22021-04-20 13:29:09 +0000954 }
955 }(pConfigAniStateAFsm)
956 } else {
957 logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000958 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000959 }
960 return
961 }
962 // waiting was aborted (probably on external request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000963 logger.Debugw(ctx, "UniPonAniConfigFsm WaitingFlowRem aborted", log.Fields{
964 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000965 oFsm.mutexIsAwaitingResponse.Lock()
966 oFsm.isWaitingForFlowDelete = false
967 oFsm.mutexIsAwaitingResponse.Unlock()
968 //to be sure we can just generate the reset-event to ensure leaving this state towards 'reset'
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000969 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000970 if pConfigAniStateAFsm != nil {
971 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000972 go func(aPAFsm *cmn.AdapterFsm) {
973 if aPAFsm != nil && aPAFsm.PFsm != nil {
974 _ = aPAFsm.PFsm.Event(aniEvReset)
mpagenkobb47bc22021-04-20 13:29:09 +0000975 }
976 }(pConfigAniStateAFsm)
977 }
978 return
979 }
980}
981
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530982//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000983func (oFsm *UniPonAniConfigFsm) enterRemovingGemNCTP(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +0000984 oFsm.pUniTechProf.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000985 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +0000986 oFsm.pUniTechProf.mutexTPState.RUnlock()
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530987 logger.Info(ctx, "UniPonAniConfigFsm - start removing one GemNCTP", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000988 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko8b07c1b2020-11-26 10:36:31 +0000989 "GemNCTP-entity-id": loGemPortID})
990 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000991 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000992 meInstance, err := oFsm.pOmciCC.SendDeleteGemNCTP(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
993 oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300994 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000995 logger.Errorw(ctx, "GemNCTP delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300996 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000997 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300998 if pConfigAniStateAFsm != nil {
999 oFsm.mutexPLastTxMeInstance.Unlock()
1000 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001001 go func(aPAFsm *cmn.AdapterFsm) {
1002 if aPAFsm != nil && aPAFsm.PFsm != nil {
1003 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001004 }
1005 }(pConfigAniStateAFsm)
1006 return
1007 }
1008 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001009 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001010 oFsm.mutexPLastTxMeInstance.Unlock()
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301011 oFsm.pOnuDB.DeleteMe(me.GemPortNetworkCtpClassID, loGemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001012 // Mark the gem port to be removed for Performance History monitoring
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001013 OnuMetricsManager := oFsm.pDeviceHandler.GetOnuMetricsManager()
1014 if OnuMetricsManager != nil {
1015 OnuMetricsManager.RemoveGemPortForPerfMonitoring(ctx, loGemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001016 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001017}
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301018
1019//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001020func (oFsm *UniPonAniConfigFsm) enterRemovingTD(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +00001021 oFsm.pUniTechProf.mutexTPState.RLock()
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001022 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +00001023 oFsm.pUniTechProf.mutexTPState.RUnlock()
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301024 logger.Info(ctx, "UniPonAniConfigFsm - start removing Traffic Descriptor", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001025 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001026 "TD-entity-id": loGemPortID})
1027
1028 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001029 meInstance, err := oFsm.pOmciCC.SendDeleteTD(log.WithSpanFromContext(context.TODO(), ctx),
1030 oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001031
1032 if err != nil {
1033 logger.Errorw(ctx, "TD delete failed - proceed fsm",
1034 log.Fields{"device-id": oFsm.deviceID, "gemPortID": loGemPortID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001035 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001036 if pConfigAniStateAFsm != nil {
1037 oFsm.mutexPLastTxMeInstance.Unlock()
1038 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001039 go func(aPAFsm *cmn.AdapterFsm) {
1040 if aPAFsm != nil && aPAFsm.PFsm != nil {
1041 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001042 }
1043 }(pConfigAniStateAFsm)
1044 return
1045 }
1046 }
1047 oFsm.pLastTxMeInstance = meInstance
1048 oFsm.mutexPLastTxMeInstance.Unlock()
1049}
mpagenko8b07c1b2020-11-26 10:36:31 +00001050
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301051//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001052func (oFsm *UniPonAniConfigFsm) enterResettingTcont(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301053 logger.Info(ctx, "UniPonAniConfigFsm - start resetting the TCont", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001054 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001055
1056 oFsm.requestEventOffset = 1 //offset 1 for last remove activity
1057 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
1058 meParams := me.ParamData{
1059 EntityID: oFsm.tcont0ID,
1060 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001061 me.TCont_AllocId: cmn.UnusedTcontAllocID,
mpagenko8b07c1b2020-11-26 10:36:31 +00001062 },
1063 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001064 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001065 meInstance, err := oFsm.pOmciCC.SendSetTcontVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1066 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001067 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001068 logger.Errorw(ctx, "TcontVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001069 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001070 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001071 if pConfigAniStateAFsm != nil {
1072 oFsm.mutexPLastTxMeInstance.Unlock()
1073 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001074 go func(aPAFsm *cmn.AdapterFsm) {
1075 if aPAFsm != nil && aPAFsm.PFsm != nil {
1076 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001077 }
1078 }(pConfigAniStateAFsm)
1079 return
1080 }
1081 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001082 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001083 oFsm.mutexPLastTxMeInstance.Unlock()
1084
mpagenko8b07c1b2020-11-26 10:36:31 +00001085}
1086
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301087//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001088func (oFsm *UniPonAniConfigFsm) enterRemoving1pMapper(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301089 logger.Info(ctx, "UniPonAniConfigFsm - start deleting the .1pMapper", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001090 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
bseenivaeba8eb12024-12-13 11:54:28 +05301091 var mapGemPortParams map[uint16]*gemPortParamStruct
Mahir Gunyel9545be22021-07-04 15:53:16 -07001092 unicastGemCount := 0
bseenivaeba8eb12024-12-13 11:54:28 +05301093 oFsm.pUniTechProf.mutexTPState.RLock()
1094 if _, ok := oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey]; ok {
1095 mapGemPortParams = oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].mapGemPortParams
1096 } else {
1097 logger.Warnw(ctx, "GemPortParams not found in mapPonAniConfig", log.Fields{"device-id": oFsm.deviceID,
1098 "uni-id": oFsm.pOnuUniPort.UniID})
1099 }
1100 oFsm.pUniTechProf.mutexTPState.RUnlock()
Mahir Gunyel9545be22021-07-04 15:53:16 -07001101 for _, gemEntry := range mapGemPortParams {
1102 if !gemEntry.isMulticast {
1103 unicastGemCount++
1104 }
1105 }
1106 if unicastGemCount > 1 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001107 logger.Debugw(ctx, "UniPonAniConfigFsm - Not the last gem in fsm. Skip the rest", log.Fields{
1108 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "unicast-gem-count": unicastGemCount, "gem-count": len(mapGemPortParams)})
1109 pConfigAniStateAFsm := oFsm.PAdaptFsm
Mahir Gunyel9545be22021-07-04 15:53:16 -07001110 if pConfigAniStateAFsm != nil {
1111 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001112 go func(aPAFsm *cmn.AdapterFsm) {
1113 if aPAFsm != nil && aPAFsm.PFsm != nil {
1114 _ = aPAFsm.PFsm.Event(aniEvRemGemDone)
Mahir Gunyel9545be22021-07-04 15:53:16 -07001115 }
1116 }(pConfigAniStateAFsm)
1117 return
1118 }
1119 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001120 logger.Debugw(ctx, "UniPonAniConfigFsm - Last gem in fsm. Continue with Mapper removal", log.Fields{
1121 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "unicast-gem-count": unicastGemCount, "gem-count": len(mapGemPortParams)})
mpagenko8b07c1b2020-11-26 10:36:31 +00001122
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001123 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001124 meInstance, err := oFsm.pOmciCC.SendDeleteDot1PMapper(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1125 oFsm.PAdaptFsm.CommChan, oFsm.mapperSP0ID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001126 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001127 logger.Errorw(ctx, "Dot1Mapper delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001128 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001129 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001130 if pConfigAniStateAFsm != nil {
1131 oFsm.mutexPLastTxMeInstance.Unlock()
1132 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001133 go func(aPAFsm *cmn.AdapterFsm) {
1134 if aPAFsm != nil && aPAFsm.PFsm != nil {
1135 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001136 }
1137 }(pConfigAniStateAFsm)
1138 return
1139 }
1140 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001141 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001142 oFsm.mutexPLastTxMeInstance.Unlock()
1143
mpagenko8b07c1b2020-11-26 10:36:31 +00001144}
1145
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301146//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001147func (oFsm *UniPonAniConfigFsm) enterRemovingAniBPCD(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301148 logger.Info(ctx, "UniPonAniConfigFsm - start deleting the ANI MBCD", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001149 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001150
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001151 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001152 meInstance, err := oFsm.pOmciCC.SendDeleteMBPConfigData(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1153 oFsm.PAdaptFsm.CommChan, oFsm.macBPCD0ID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001154 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001155 logger.Errorw(ctx, "MBPConfigData delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001156 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001157 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001158 if pConfigAniStateAFsm != nil {
1159 oFsm.mutexPLastTxMeInstance.Unlock()
1160 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001161 go func(aPAFsm *cmn.AdapterFsm) {
1162 if aPAFsm != nil && aPAFsm.PFsm != nil {
1163 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001164 }
1165 }(pConfigAniStateAFsm)
1166 return
1167 }
1168 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001169 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001170 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +00001171}
1172
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001173func (oFsm *UniPonAniConfigFsm) enterAniRemoveDone(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301174 logger.Info(ctx, "UniPonAniConfigFsm ani removal done", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001175 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001176 //use DeviceHandler event notification directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001177 oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset)))
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001178 if oFsm.isChanSet() {
mpagenko8b07c1b2020-11-26 10:36:31 +00001179 // indicate processing done to the caller
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001180 logger.Debugw(ctx, "UniPonAniConfigFsm processingDone on channel", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +00001181 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
1182 oFsm.chSuccess <- oFsm.procStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001183 oFsm.setChanSet(false) //reset the internal channel state
mpagenko8b07c1b2020-11-26 10:36:31 +00001184 }
1185
1186 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001187 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko8b07c1b2020-11-26 10:36:31 +00001188 if pConfigAniStateAFsm != nil {
1189 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001190 go func(aPAFsm *cmn.AdapterFsm) {
1191 if aPAFsm != nil && aPAFsm.PFsm != nil {
1192 _ = aPAFsm.PFsm.Event(aniEvReset)
mpagenko8b07c1b2020-11-26 10:36:31 +00001193 }
1194 }(pConfigAniStateAFsm)
1195 }
1196}
1197
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001198func (oFsm *UniPonAniConfigFsm) enterResettingState(ctx context.Context, e *fsm.Event) {
1199 logger.Debugw(ctx, "UniPonAniConfigFsm resetting", log.Fields{
1200 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001201
mpagenko45cc6a32021-07-23 10:06:57 +00001202 if oFsm.isChanSet() {
1203 // indicate processing error to the caller (in case there was still some open request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001204 logger.Debugw(ctx, "UniPonAniConfigFsm processingError on channel", log.Fields{
mpagenko45cc6a32021-07-23 10:06:57 +00001205 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
1206 //use non-blocking channel send to avoid blocking because of non-existing receiver
1207 // (even though the channel is checked on 'set', the outside receiver channel might (theoretically) already be deleted)
1208 select {
1209 case oFsm.chSuccess <- 0:
1210 default:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001211 logger.Debugw(ctx, "UniPonAniConfigFsm processingError not send on channel (no receiver)", log.Fields{
mpagenko45cc6a32021-07-23 10:06:57 +00001212 "device-id": oFsm.deviceID})
1213 }
1214 oFsm.setChanSet(false) //reset the internal channel state
1215 }
1216
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001217 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko3dbcdd22020-07-22 07:38:45 +00001218 if pConfigAniStateAFsm != nil {
1219 // abort running message processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001220 fsmAbortMsg := cmn.Message{
1221 Type: cmn.TestMsg,
1222 Data: cmn.TestMessage{
1223 TestMessageVal: cmn.AbortMessageProcessing,
mpagenko3dbcdd22020-07-22 07:38:45 +00001224 },
1225 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001226 pConfigAniStateAFsm.CommChan <- fsmAbortMsg
mpagenko3dbcdd22020-07-22 07:38:45 +00001227
1228 //try to restart the FSM to 'disabled', decouple event transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001229 go func(aPAFsm *cmn.AdapterFsm) {
1230 if aPAFsm != nil && aPAFsm.PFsm != nil {
1231 _ = aPAFsm.PFsm.Event(aniEvRestart)
mpagenko3dbcdd22020-07-22 07:38:45 +00001232 }
1233 }(pConfigAniStateAFsm)
Akash Soni3de0e062024-12-11 16:37:26 +05301234 logger.Warnf(ctx, "calling HandleAniConfigFSMFailure resetting", log.Fields{
1235 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
1236 oFsm.pDeviceHandler.HandleAniConfigFSMFailure(ctx, oFsm.pOnuUniPort.UniID)
mpagenko3dbcdd22020-07-22 07:38:45 +00001237 }
1238}
1239
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301240//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001241func (oFsm *UniPonAniConfigFsm) enterDisabledState(ctx context.Context, e *fsm.Event) {
1242 logger.Debugw(ctx, "UniPonAniConfigFsm enters disabled state", log.Fields{
1243 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001244 oFsm.mutexPLastTxMeInstance.Lock()
1245 defer oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00001246 oFsm.pLastTxMeInstance = nil
mpagenko1cc3cb42020-07-27 15:24:38 +00001247}
1248
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001249func (oFsm *UniPonAniConfigFsm) processOmciAniMessages(ctx context.Context) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301250 logger.Info(ctx, "Start UniPonAniConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001251loop:
1252 for {
mpagenko3dbcdd22020-07-22 07:38:45 +00001253 // case <-ctx.Done():
mpagenko01e726e2020-10-23 09:45:29 +00001254 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001255 // break loop
bseenivaeba8eb12024-12-13 11:54:28 +05301256 select {
1257 case message, ok := <-oFsm.PAdaptFsm.CommChan:
1258 if !ok {
1259 logger.Warn(ctx, "UniPonAniConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID})
1260 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
1261 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +00001262 break loop
1263 }
bseenivaeba8eb12024-12-13 11:54:28 +05301264 logger.Debugw(ctx, "UniPonAniConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID})
1265
1266 switch message.Type {
1267 case cmn.TestMsg:
1268 msg, _ := message.Data.(cmn.TestMessage)
1269 if msg.TestMessageVal == cmn.AbortMessageProcessing {
1270 logger.Infow(ctx, "UniPonAniConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID})
1271 break loop
1272 }
1273 logger.Warnw(ctx, "UniPonAniConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal})
1274 case cmn.OMCI:
1275 msg, _ := message.Data.(cmn.OmciMessage)
1276 oFsm.handleOmciAniConfigMessage(ctx, msg)
1277 default:
1278 logger.Warn(ctx, "UniPonAniConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID,
1279 "message.Type": message.Type})
1280 }
1281 case _, ok := <-oFsm.pDeviceHandler.GetDeviceDeleteCommChan(ctx):
1282 if !ok {
1283 logger.Warnw(ctx, "Device deletion channel closed", log.Fields{"device-id": oFsm.deviceID})
1284 }
1285 break loop
Himani Chawla4d908332020-08-31 12:30:20 +05301286 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001287
Himani Chawla4d908332020-08-31 12:30:20 +05301288 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001289 logger.Infow(ctx, "End UniPonAniConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301290}
1291
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001292func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigCreateResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +05301293 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse)
1294 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001295 logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001296 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301297 return
1298 }
1299 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
1300 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001301 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001302 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301303 return
1304 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001305 logger.Debugw(ctx, "CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenkofc4f56e2020-11-04 17:17:49 +00001306 if msgObj.Result == me.Success || msgObj.Result == me.InstanceExists {
1307 //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 +00001308 oFsm.mutexPLastTxMeInstance.RLock()
1309 if oFsm.pLastTxMeInstance != nil {
1310 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1311 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1312 // maybe we can use just the same eventName for different state transitions like "forward"
1313 // - might be checked, but so far I go for sure and have to inspect the concrete state events ...
1314 switch oFsm.pLastTxMeInstance.GetName() {
1315 case "Ieee8021PMapperServiceProfile":
1316 { // let the FSM proceed ...
1317 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001318 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxDot1pmapCResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001319 }
1320 case "MacBridgePortConfigurationData":
1321 { // let the FSM proceed ...
1322 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001323 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxMbpcdResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001324 }
1325 case "GemPortNetworkCtp", "GemInterworkingTerminationPoint", "MulticastGemInterworkingTerminationPoint":
1326 { // let aniConfig Multi-Id processing proceed by stopping the wait function
1327 oFsm.mutexPLastTxMeInstance.RUnlock()
1328 oFsm.omciMIdsResponseReceived <- true
1329 }
1330 default:
1331 {
1332 oFsm.mutexPLastTxMeInstance.RUnlock()
1333 logger.Warnw(ctx, "Unsupported ME name received!",
1334 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1335 }
mpagenkofc4f56e2020-11-04 17:17:49 +00001336 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001337 } else {
1338 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenkofc4f56e2020-11-04 17:17:49 +00001339 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001340 } else {
1341 oFsm.mutexPLastTxMeInstance.RUnlock()
1342 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +00001343 }
1344 } else {
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001345 logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?",
1346 log.Fields{"Error": msgObj.Result, "device-id": oFsm.deviceID})
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001347 // possibly force FSM into abort or ignore some errors for some messages?
1348 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1349 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
Himani Chawla4d908332020-08-31 12:30:20 +05301350 return
1351 }
Himani Chawla4d908332020-08-31 12:30:20 +05301352}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001353func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigSetFailResponseMessage(ctx context.Context, msgObj *omci.SetResponse) {
Mahir Gunyel01034b62021-06-29 11:25:09 -07001354 //If TCONT fails, then we need to revert the allocated TCONT in DB.
1355 //Because FSMs are running sequentially, we don't expect the same TCONT hit by another tech-profile FSM while this FSM is running.
1356 oFsm.mutexPLastTxMeInstance.RLock()
1357 defer oFsm.mutexPLastTxMeInstance.RUnlock()
1358 if oFsm.pLastTxMeInstance != nil && msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1359 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1360 switch oFsm.pLastTxMeInstance.GetName() {
1361 case "TCont":
1362 //If this is for TCONT creation(requestEventOffset=0) and this is the first allocation of TCONT(so noone else is using the same TCONT)
1363 //We should revert DB
bseenivaeba8eb12024-12-13 11:54:28 +05301364 oFsm.pUniTechProf.mutexTPState.RLock()
Mahir Gunyel01034b62021-06-29 11:25:09 -07001365 if oFsm.requestEventOffset == 0 && !oFsm.tcontSetBefore && oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey] != nil {
1366 logger.Debugw(ctx, "UniPonAniConfigFsm TCONT creation failed on device. Freeing alloc id", log.Fields{"device-id": oFsm.deviceID,
1367 "alloc-id": oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID, "uni-tp": oFsm.uniTpKey})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001368 if oFsm.pOnuDeviceEntry != nil {
1369 oFsm.pOnuDeviceEntry.FreeTcont(ctx, oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID)
Mahir Gunyel01034b62021-06-29 11:25:09 -07001370 } else {
1371 logger.Warnw(ctx, "Unable to get device entry! couldn't free tcont",
1372 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1373 }
1374 }
bseenivaeba8eb12024-12-13 11:54:28 +05301375 oFsm.pUniTechProf.mutexTPState.RUnlock()
Mahir Gunyel01034b62021-06-29 11:25:09 -07001376 default:
1377 logger.Warnw(ctx, "Unsupported ME name received with error!",
1378 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "result": msgObj.Result, "device-id": oFsm.deviceID})
1379 }
1380 }
1381}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001382func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigSetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +05301383 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
1384 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001385 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be detected for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001386 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301387 return
1388 }
1389 msgObj, msgOk := msgLayer.(*omci.SetResponse)
1390 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001391 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be assigned for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001392 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301393 return
1394 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001395 logger.Debugw(ctx, "UniPonAniConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +05301396 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001397 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci SetResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00001398 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001399 // possibly force FSM into abort or ignore some errors for some messages?
1400 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1401 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
Mahir Gunyel01034b62021-06-29 11:25:09 -07001402 oFsm.handleOmciAniConfigSetFailResponseMessage(ctx, msgObj)
Himani Chawla4d908332020-08-31 12:30:20 +05301403 return
1404 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001405 oFsm.mutexPLastTxMeInstance.RLock()
1406 if oFsm.pLastTxMeInstance != nil {
1407 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1408 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1409 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
1410 // if, then something like:
1411 //oFsm.pOnuDB.StoreMe(msgObj)
Himani Chawla4d908332020-08-31 12:30:20 +05301412
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001413 switch oFsm.pLastTxMeInstance.GetName() {
1414 case "TCont":
1415 { // let the FSM proceed ...
1416 oFsm.mutexPLastTxMeInstance.RUnlock()
1417 if oFsm.requestEventOffset == 0 { //from TCont config request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001418 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxTcontsResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001419 } else { // from T-Cont reset request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001420 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxResetTcontResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001421 }
1422 }
1423 case "PriorityQueue", "MulticastGemInterworkingTerminationPoint":
1424 { // let the PrioQueue init proceed by stopping the wait function
1425 oFsm.mutexPLastTxMeInstance.RUnlock()
1426 oFsm.omciMIdsResponseReceived <- true
1427 }
1428 case "Ieee8021PMapperServiceProfile":
1429 { // let the FSM proceed ...
1430 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001431 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxDot1pmapSResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001432 }
1433 default:
1434 {
1435 oFsm.mutexPLastTxMeInstance.RUnlock()
1436 logger.Warnw(ctx, "Unsupported ME name received!",
1437 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001438 }
Himani Chawla4d908332020-08-31 12:30:20 +05301439 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001440 } else {
1441 oFsm.mutexPLastTxMeInstance.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +05301442 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001443 } else {
1444 oFsm.mutexPLastTxMeInstance.RUnlock()
1445 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301446 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001447}
1448
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001449func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigDeleteResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
mpagenko8b07c1b2020-11-26 10:36:31 +00001450 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeDeleteResponse)
1451 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001452 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be detected for DeleteResponse",
mpagenko8b07c1b2020-11-26 10:36:31 +00001453 log.Fields{"device-id": oFsm.deviceID})
1454 return
1455 }
1456 msgObj, msgOk := msgLayer.(*omci.DeleteResponse)
1457 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001458 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be assigned for DeleteResponse",
mpagenko8b07c1b2020-11-26 10:36:31 +00001459 log.Fields{"device-id": oFsm.deviceID})
1460 return
1461 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001462 logger.Debugw(ctx, "UniPonAniConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
Akash Soni8eff4632024-12-11 13:41:46 +05301463 if msgObj.Result == me.UnknownInstance {
1464 logger.Warnw(ctx, "UniPonAniConfigFsm - Unknow Instance",
1465 log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj, "Error": msgObj.Result})
1466 } else if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001467 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci DeleteResponse Error",
mpagenko8b07c1b2020-11-26 10:36:31 +00001468 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
1469 //TODO: - later: possibly force FSM into abort or ignore some errors for some messages?
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001470 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1471 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
mpagenko8b07c1b2020-11-26 10:36:31 +00001472 return
1473 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001474 oFsm.mutexPLastTxMeInstance.RLock()
1475 if oFsm.pLastTxMeInstance != nil {
1476 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1477 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1478 //remove ME from DB //TODO??? obviously the Python code does not store/remove the config ...
1479 // if, then something like: oFsm.pOnuDB.XyyMe(msgObj)
mpagenko8b07c1b2020-11-26 10:36:31 +00001480
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001481 switch oFsm.pLastTxMeInstance.GetName() {
1482 case "GemInterworkingTerminationPoint":
1483 { // let the FSM proceed ...
1484 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001485 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemGemiwResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001486 }
1487 case "GemPortNetworkCtp":
1488 { // let the FSM proceed ...
1489 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001490 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemGemntpResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001491 }
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001492 case "TrafficDescriptor":
1493 { // let the FSM proceed ...
1494 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001495 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemTdResp)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001496 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001497 case "Ieee8021PMapperServiceProfile":
1498 { // let the FSM proceed ...
1499 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001500 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRem1pMapperResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001501 }
1502 case "MacBridgePortConfigurationData":
1503 { // this is the last event of the T-Cont cleanup procedure, FSM may be reset here
1504 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001505 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemAniBPCDResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001506 }
1507 default:
1508 {
1509 oFsm.mutexPLastTxMeInstance.RUnlock()
1510 logger.Warnw(ctx, "Unsupported ME name received!",
1511 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1512 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001513 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001514 } else {
1515 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko8b07c1b2020-11-26 10:36:31 +00001516 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001517 } else {
1518 oFsm.mutexPLastTxMeInstance.RUnlock()
1519 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001520 }
1521}
1522
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001523func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001524 logger.Debugw(ctx, "Rx OMCI UniPonAniConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001525 "msgType": msg.OmciMsg.MessageType})
1526
1527 switch msg.OmciMsg.MessageType {
1528 case omci.CreateResponseType:
1529 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001530 oFsm.handleOmciAniConfigCreateResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301531
mpagenko3dbcdd22020-07-22 07:38:45 +00001532 } //CreateResponseType
1533 case omci.SetResponseType:
1534 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001535 oFsm.handleOmciAniConfigSetResponseMessage(ctx, msg)
mpagenko3dbcdd22020-07-22 07:38:45 +00001536
mpagenko3dbcdd22020-07-22 07:38:45 +00001537 } //SetResponseType
mpagenko8b07c1b2020-11-26 10:36:31 +00001538 case omci.DeleteResponseType:
1539 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001540 oFsm.handleOmciAniConfigDeleteResponseMessage(ctx, msg)
mpagenko8b07c1b2020-11-26 10:36:31 +00001541
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001542 } //DeleteResponseType
mpagenko3dbcdd22020-07-22 07:38:45 +00001543 default:
1544 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001545 logger.Errorw(ctx, "UniPonAniConfigFsm - Rx OMCI unhandled MsgType",
mpagenko01e726e2020-10-23 09:45:29 +00001546 log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001547 return
1548 }
1549 }
1550}
1551
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001552func (oFsm *UniPonAniConfigFsm) performCreatingGemNCTPs(ctx context.Context) {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001553 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
1554 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301555 logger.Info(ctx, "UniPonAniConfigFsm Tx Create::GemNWCtp", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001556 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
1557 "TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001558 "device-id": oFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001559 meParams := me.ParamData{
1560 EntityID: gemPortAttribs.gemPortID, //unique, same as PortId
1561 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001562 me.GemPortNetworkCtp_PortId: gemPortAttribs.gemPortID,
1563 me.GemPortNetworkCtp_TContPointer: oFsm.tcont0ID,
1564 me.GemPortNetworkCtp_Direction: gemPortAttribs.direction,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001565 //ONU-G.TrafficManagementOption dependency ->PrioQueue or TCont
1566 // TODO!! verify dependency and QueueId in case of Multi-GemPort setup!
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001567 me.GemPortNetworkCtp_TrafficManagementPointerForUpstream: gemPortAttribs.upQueueID, //might be different in wrr-only Setup - tcont0ID
1568 me.GemPortNetworkCtp_PriorityQueuePointerForDownStream: gemPortAttribs.downQueueID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001569 },
1570 }
Holger Hildebrandtc408f492022-07-14 08:39:24 +00001571 if oFsm.techProfileType == cTechProfileTypeXgsPon {
1572 meParams.Attributes[me.GemPortNetworkCtp_EncryptionKeyRing] = GemEncryptKeyRingUnicastDownstreamOnly
1573 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001574 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001575 meInstance, err := oFsm.pOmciCC.SendCreateGemNCTPVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1576 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001577 if err != nil {
1578 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001579 logger.Errorw(ctx, "GemNCTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001580 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001581 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001582 return
1583 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001584 //accept also nil as (error) return value for writing to LastTx
1585 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001586 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001587 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001588 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001589 err = oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001590 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001591 logger.Errorw(ctx, "GemNWCtp create failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001592 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001593 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001594 return
1595 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301596 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpClassID, gemPortAttribs.gemPortID, meParams.Attributes)
Girish Gowdra50e56422021-06-01 16:46:04 -07001597 // Mark the gem port to be added for Performance History monitoring
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001598 OnuMetricsManager := oFsm.pDeviceHandler.GetOnuMetricsManager()
1599 if OnuMetricsManager != nil {
1600 OnuMetricsManager.AddGemPortForPerfMonitoring(ctx, gemPortAttribs.gemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001601 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001602 } //for all GemPorts of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +00001603
1604 // if Config has been done for all GemPort instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001605 logger.Debugw(ctx, "GemNWCtp create loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001606 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxGemntcpsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001607}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001608func (oFsm *UniPonAniConfigFsm) hasMulticastGem(ctx context.Context) bool {
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001609 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
1610 if gemPortAttribs.isMulticast {
1611 logger.Debugw(ctx, "Found multicast gem", log.Fields{"device-id": oFsm.deviceID})
1612 return true
1613 }
1614 }
1615 return false
1616}
mpagenko3dbcdd22020-07-22 07:38:45 +00001617
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001618func (oFsm *UniPonAniConfigFsm) performCreatingGemIWs(ctx context.Context) {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001619 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
1620 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301621 logger.Info(ctx, "UniPonAniConfigFsm Tx Create::GemIwTp", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001622 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
1623 "SPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001624 "device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001625
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301626 var meParams me.ParamData
ozgecanetsia4b232302020-11-11 10:58:10 +03001627 //TODO if the port has only downstream direction the isMulticast flag can be removed.
1628 if gemPortAttribs.isMulticast {
ozgecanetsia4b232302020-11-11 10:58:10 +03001629
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301630 meParams = me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001631 EntityID: gemPortAttribs.multicastGemID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001632 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001633 me.MulticastGemInterworkingTerminationPoint_GemPortNetworkCtpConnectivityPointer: gemPortAttribs.multicastGemID,
1634 me.MulticastGemInterworkingTerminationPoint_InterworkingOption: 0, // Don't Care
1635 me.MulticastGemInterworkingTerminationPoint_ServiceProfilePointer: 0, // Don't Care
1636 me.MulticastGemInterworkingTerminationPoint_GalProfilePointer: cmn.GalEthernetEID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001637 },
1638 }
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001639 if oFsm.pUniTechProf.multicastConfiguredForOtherUniTps(ctx, oFsm.uniTpKey) {
1640 logger.Debugw(ctx, "MulticastGemInterworkingTP already exist", log.Fields{"device-id": oFsm.deviceID, "multicast-gem-id": gemPortAttribs.multicastGemID})
1641 continue
1642 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001643 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001644 meInstance, err := oFsm.pOmciCC.SendCreateMulticastGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(),
1645 true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001646 if err != nil {
1647 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001648 logger.Errorw(ctx, "MulticastGemIWTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001649 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001650 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001651 return
1652
1653 }
ozgecanetsia4b232302020-11-11 10:58:10 +03001654 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001655 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001656 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001657 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001658 if err != nil {
ozgecanetsiab36ed572021-04-01 10:38:48 +03001659 logger.Errorw(ctx, "MulticastGemIWTP create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001660 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001661 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001662 return
1663 }
1664 ipv4MulticastTable := make([]uint8, 12)
1665 //Gem Port ID
1666 binary.BigEndian.PutUint16(ipv4MulticastTable[0:], gemPortAttribs.multicastGemID)
1667 //Secondary Key
1668 binary.BigEndian.PutUint16(ipv4MulticastTable[2:], 0)
1669 // Multicast IP range start This is the 224.0.0.1 address
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001670 binary.BigEndian.PutUint32(ipv4MulticastTable[4:], cmn.IPToInt32(net.IPv4(224, 0, 0, 0)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001671 // MulticastIp range stop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001672 binary.BigEndian.PutUint32(ipv4MulticastTable[8:], cmn.IPToInt32(net.IPv4(239, 255, 255, 255)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001673
1674 meIPV4MCTableParams := me.ParamData{
1675 EntityID: gemPortAttribs.multicastGemID,
1676 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001677 me.MulticastGemInterworkingTerminationPoint_Ipv4MulticastAddressTable: ipv4MulticastTable,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001678 },
1679 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001680 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001681 meIPV4MCTableInstance, err := oFsm.pOmciCC.SendSetMulticastGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(),
1682 true, oFsm.PAdaptFsm.CommChan, meIPV4MCTableParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001683 if err != nil {
1684 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001685 logger.Errorw(ctx, "MulticastGemIWTPVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001686 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001687 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001688 return
1689 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001690 oFsm.pLastTxMeInstance = meIPV4MCTableInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001691 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia4b232302020-11-11 10:58:10 +03001692
1693 } else {
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301694 meParams = me.ParamData{
ozgecanetsia4b232302020-11-11 10:58:10 +03001695 EntityID: gemPortAttribs.gemPortID,
1696 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001697 me.GemInterworkingTerminationPoint_GemPortNetworkCtpConnectivityPointer: gemPortAttribs.gemPortID, //same as EntityID, see above
1698 me.GemInterworkingTerminationPoint_InterworkingOption: 5, //fixed model:: G.998 .1pMapper
1699 me.GemInterworkingTerminationPoint_ServiceProfilePointer: oFsm.mapperSP0ID,
1700 me.GemInterworkingTerminationPoint_InterworkingTerminationPointPointer: 0, //not used with .1PMapper Mac bridge
1701 me.GemInterworkingTerminationPoint_GalProfilePointer: cmn.GalEthernetEID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001702 },
1703 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001704 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001705 meInstance, err := oFsm.pOmciCC.SendCreateGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1706 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001707 if err != nil {
1708 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001709 logger.Errorw(ctx, "GEMIWTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001710 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001711 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001712 return
1713 }
ozgecanetsia4b232302020-11-11 10:58:10 +03001714 //accept also nil as (error) return value for writing to LastTx
1715 // - this avoids misinterpretation of new received OMCI messages
1716 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001717 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia4b232302020-11-11 10:58:10 +03001718 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001719 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001720 err := oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001721 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001722 logger.Errorw(ctx, "GemTP create failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001723 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001724 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001725 return
1726 }
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301727 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 +05301728 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemInterworkingTerminationPointClassID, gemPortAttribs.gemPortID, meParams.Attributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301729
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001730 } //for all GemPort's of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +00001731
1732 // if Config has been done for all GemPort instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001733 logger.Debugw(ctx, "GemIwTp create loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001734 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxGemiwsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001735}
1736
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001737func (oFsm *UniPonAniConfigFsm) performSettingPQs(ctx context.Context) {
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001738 //If upstream PQs were set before, then no need to set them again. Let state machine to proceed.
1739 if oFsm.tcontSetBefore {
1740 logger.Debugw(ctx, "No need to set PQs again.", log.Fields{
1741 "device-id": oFsm.deviceID, "tcont": oFsm.alloc0ID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001742 "uni-id": oFsm.pOnuUniPort.UniID,
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001743 "techProfile-id": oFsm.techProfileID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001744 go func(aPAFsm *cmn.AdapterFsm) {
1745 if aPAFsm != nil && aPAFsm.PFsm != nil {
1746 _ = aPAFsm.PFsm.Event(aniEvRxPrioqsResp)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001747 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001748 }(oFsm.PAdaptFsm)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001749 return
1750 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001751 const cu16StrictPrioWeight uint16 = 0xFFFF
1752 //find all upstream PrioQueues related to this T-Cont
1753 loQueueMap := ordered_map.NewOrderedMap()
1754 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001755 if gemPortAttribs.isMulticast {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001756 logger.Debugw(ctx, "UniPonAniConfigFsm Port is Multicast, ignoring PQs", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001757 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
1758 "prioString": gemPortAttribs.pbitString})
1759 continue
1760 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001761 if gemPortAttribs.qosPolicy == "WRR" {
Himani Chawla4d908332020-08-31 12:30:20 +05301762 if _, ok := loQueueMap.Get(gemPortAttribs.upQueueID); !ok {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001763 //key does not yet exist
1764 loQueueMap.Set(gemPortAttribs.upQueueID, uint16(gemPortAttribs.weight))
1765 }
1766 } else {
1767 loQueueMap.Set(gemPortAttribs.upQueueID, cu16StrictPrioWeight) //use invalid weight value to indicate SP
1768 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001769 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001770
Girish Gowdra09e5f212021-09-30 16:28:36 -07001771 trafficSchedPtrSetSupported := false
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001772 loOnu2g := oFsm.pOnuDB.GetMe(me.Onu2GClassID, cmn.Onu2gMeID)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001773 if loOnu2g == nil {
1774 logger.Errorw(ctx, "onu2g is nil, cannot read qos configuration flexibility parameter",
1775 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001776 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001777 return
1778 }
1779 returnVal := loOnu2g["QualityOfServiceQosConfigurationFlexibility"]
1780 if returnVal != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001781 if qosCfgFlexParam, err := oFsm.pOnuDB.GetUint16Attrib(returnVal); err == nil {
Girish Gowdra09e5f212021-09-30 16:28:36 -07001782 trafficSchedPtrSetSupported = qosCfgFlexParam&bitTrafficSchedulerPtrSetPermitted == bitTrafficSchedulerPtrSetPermitted
1783 logger.Debugw(ctx, "trafficSchedPtrSetSupported set",
1784 log.Fields{"qosCfgFlexParam": qosCfgFlexParam, "trafficSchedPtrSetSupported": trafficSchedPtrSetSupported})
1785 } else {
1786 logger.Errorw(ctx, "Cannot extract qos configuration flexibility parameter",
1787 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001788 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001789 return
1790 }
1791 } else {
1792 logger.Errorw(ctx, "Cannot read qos configuration flexibility parameter",
1793 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001794 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001795 return
1796 }
1797
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001798 //TODO: assumption here is that ONU data uses SP setting in the T-Cont and WRR in the TrafficScheduler
1799 // if that is not the case, the reverse case could be checked and reacted accordingly or if the
1800 // complete chain is not valid, then some error should be thrown and configuration can be aborted
1801 // or even be finished without correct SP/WRR setting
1802
1803 //TODO: search for the (WRR)trafficScheduler related to the T-Cont of this queue
1804 //By now assume fixed value 0x8000, which is the only announce BBSIM TrafficScheduler,
1805 // even though its T-Cont seems to be wrong ...
1806 loTrafficSchedulerEID := 0x8000
1807 //for all found queues
1808 iter := loQueueMap.IterFunc()
1809 for kv, ok := iter(); ok; kv, ok = iter() {
1810 queueIndex := (kv.Key).(uint16)
1811 meParams := me.ParamData{
1812 EntityID: queueIndex,
Himani Chawla4d908332020-08-31 12:30:20 +05301813 Attributes: make(me.AttributeValueMap),
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001814 }
Girish Gowdra09e5f212021-09-30 16:28:36 -07001815 if trafficSchedPtrSetSupported {
1816 if (kv.Value).(uint16) == cu16StrictPrioWeight {
1817 //StrictPrio indication
1818 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio", log.Fields{
1819 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1820 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001821 meParams.Attributes[me.PriorityQueue_TrafficSchedulerPointer] = 0 //ensure T-Cont defined StrictPrio scheduling
Girish Gowdra09e5f212021-09-30 16:28:36 -07001822 } else {
1823 //WRR indication
1824 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to WRR", log.Fields{
1825 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1826 "Weight": kv.Value,
1827 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001828 meParams.Attributes[me.PriorityQueue_TrafficSchedulerPointer] = loTrafficSchedulerEID //ensure assignment of the relevant trafficScheduler
1829 meParams.Attributes[me.PriorityQueue_Weight] = uint8(kv.Value.(uint16))
Girish Gowdra09e5f212021-09-30 16:28:36 -07001830 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001831 } else {
Girish Gowdra09e5f212021-09-30 16:28:36 -07001832 // setting Traffic Scheduler (TS) pointer is not supported unless we point to another TS that points to the same TCONT.
1833 // 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.
1834 // 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.
1835 if (kv.Value).(uint16) == cu16StrictPrioWeight { // SP case, nothing to be done. Proceed to the next queue
1836 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio, traffic sched ptr set unsupported", log.Fields{
1837 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1838 "device-id": oFsm.deviceID})
1839 continue
1840 }
1841 // WRR case, update weight.
1842 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to WRR, traffic sched ptr set unsupported", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001843 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1844 "Weight": kv.Value,
mpagenko01e726e2020-10-23 09:45:29 +00001845 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001846 meParams.Attributes[me.PriorityQueue_Weight] = uint8(kv.Value.(uint16))
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001847 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001848 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001849 meInstance, err := oFsm.pOmciCC.SendSetPrioQueueVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1850 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001851 if err != nil {
1852 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001853 logger.Errorw(ctx, "PrioQueueVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001854 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001855 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001856 return
1857 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001858 //accept also nil as (error) return value for writing to LastTx
1859 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001860 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001861 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001862
1863 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001864 err = oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001865 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001866 logger.Errorw(ctx, "PrioQueue set failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001867 log.Fields{"device-id": oFsm.deviceID, "QueueId": strconv.FormatInt(int64(queueIndex), 16)})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001868 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001869 return
1870 }
1871
1872 //TODO: In case of WRR setting of the GemPort/PrioQueue it might further be necessary to
1873 // write the assigned trafficScheduler with the requested Prio to be considered in the StrictPrio scheduling
1874 // of the (next upstream) assigned T-Cont, which is f(prioQueue[priority]) - in relation to other SP prioQueues
1875 // not yet done because of BBSIM TrafficScheduler issues (and not done in py code as well)
1876
1877 } //for all upstream prioQueues
mpagenko3dbcdd22020-07-22 07:38:45 +00001878
1879 // if Config has been done for all PrioQueue instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001880 logger.Debugw(ctx, "PrioQueue set loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001881 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxPrioqsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001882}
1883
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001884func (oFsm *UniPonAniConfigFsm) waitforOmciResponse(ctx context.Context) error {
mpagenko7d6bb022021-03-11 15:07:55 +00001885 oFsm.mutexIsAwaitingResponse.Lock()
mpagenkocf48e452021-04-23 09:23:00 +00001886 if oFsm.isCanceled {
1887 // FSM already canceled before entering wait
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001888 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 +00001889 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001890 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenkocf48e452021-04-23 09:23:00 +00001891 }
mpagenko7d6bb022021-03-11 15:07:55 +00001892 oFsm.isAwaitingResponse = true
1893 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko3dbcdd22020-07-22 07:38:45 +00001894 select {
Himani Chawla4d908332020-08-31 12:30:20 +05301895 // maybe be also some outside cancel (but no context modeled for the moment ...)
mpagenko3dbcdd22020-07-22 07:38:45 +00001896 // case <-ctx.Done():
mpagenko01e726e2020-10-23 09:45:29 +00001897 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +00001898 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 +00001899 logger.Warnw(ctx, "UniPonAniConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001900 oFsm.mutexIsAwaitingResponse.Lock()
1901 oFsm.isAwaitingResponse = false
1902 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001903 oFsm.mutexPLastTxMeInstance.RLock()
1904 if oFsm.pLastTxMeInstance != nil {
1905 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureTimeout, oFsm.pLastTxMeInstance.GetClassID(),
1906 oFsm.pLastTxMeInstance.GetEntityID(), oFsm.pLastTxMeInstance.GetClassID().String(), 0)
1907 }
1908 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00001909 return fmt.Errorf("uniPonAniConfigFsm multi entity timeout %s", oFsm.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +00001910 case success := <-oFsm.omciMIdsResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +05301911 if success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001912 logger.Debugw(ctx, "UniPonAniConfigFsm multi entity response received", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001913 oFsm.mutexIsAwaitingResponse.Lock()
1914 oFsm.isAwaitingResponse = false
1915 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko3dbcdd22020-07-22 07:38:45 +00001916 return nil
1917 }
mpagenko7d6bb022021-03-11 15:07:55 +00001918 // waiting was aborted (probably on external request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001919 logger.Debugw(ctx, "UniPonAniConfigFsm wait-for-multi-entity-response aborted", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001920 oFsm.mutexIsAwaitingResponse.Lock()
1921 oFsm.isAwaitingResponse = false
1922 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001923 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenko3dbcdd22020-07-22 07:38:45 +00001924 }
1925}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001926
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001927func (oFsm *UniPonAniConfigFsm) setChanSet(flagValue bool) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001928 oFsm.mutexChanSet.Lock()
1929 oFsm.chanSet = flagValue
1930 oFsm.mutexChanSet.Unlock()
1931}
1932
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001933func (oFsm *UniPonAniConfigFsm) isChanSet() bool {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001934 oFsm.mutexChanSet.RLock()
1935 flagValue := oFsm.chanSet
1936 oFsm.mutexChanSet.RUnlock()
1937 return flagValue
1938}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001939
1940// PrepareForGarbageCollection - remove references to prepare for garbage collection
1941func (oFsm *UniPonAniConfigFsm) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301942 logger.Info(ctx, "prepare for garbage collection", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001943 oFsm.pDeviceHandler = nil
1944 oFsm.pOnuDeviceEntry = nil
1945 oFsm.pOmciCC = nil
1946}