blob: acf5e080cf29afb230cda7fc9c7d83dfd80024b3 [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()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000358 tcontInstID, tcontAlreadyExist, err := oFsm.pOnuDeviceEntry.AllocateFreeTcont(ctx, oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700359 if err != nil {
360 logger.Errorw(ctx, "No TCont instances found", log.Fields{"device-id": oFsm.deviceID, "err": err})
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700361 //reset the state machine to enable usage on subsequent requests
bseenivaeba8eb12024-12-13 11:54:28 +0530362 oFsm.pUniTechProf.mutexTPState.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000363 _ = aPAFsm.PFsm.Event(aniEvReset)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700364 return
365 }
366 oFsm.tcont0ID = tcontInstID
367 oFsm.tcontSetBefore = tcontAlreadyExist
368 logger.Debugw(ctx, "used-tcont-instance-id", log.Fields{"tcont-inst-id": oFsm.tcont0ID,
369 "alloc-id": oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID,
370 "tcontAlreadyExist": tcontAlreadyExist,
371 "device-id": oFsm.deviceID})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800372
mpagenko8b07c1b2020-11-26 10:36:31 +0000373 oFsm.alloc0ID = oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID
374 mapGemPortParams := oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].mapGemPortParams
mpagenko3ce9fa02021-07-28 13:26:54 +0000375 oFsm.pUniTechProf.mutexTPState.RUnlock()
Girish Gowdra041dcb32020-11-16 16:54:30 -0800376
Himani Chawla26e555c2020-08-31 12:30:20 +0530377 //for all TechProfile set GemIndices
Girish Gowdra041dcb32020-11-16 16:54:30 -0800378 for _, gemEntry := range mapGemPortParams {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300379 loGemPortAttribs := ponAniGemPortAttribs{}
380
Himani Chawla26e555c2020-08-31 12:30:20 +0530381 //collect all GemConfigData in a separate Fsm related slice (needed also to avoid mix-up with unsorted mapPonAniConfig)
382
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000383 if queueInstKeys := oFsm.pOnuDB.GetSortedInstKeys(ctx, me.PriorityQueueClassID); len(queueInstKeys) > 0 {
Himani Chawla26e555c2020-08-31 12:30:20 +0530384
385 loGemPortAttribs.gemPortID = gemEntry.gemPortID
386 // MibDb usage: upstream PrioQueue.RelatedPort = xxxxyyyy with xxxx=TCont.Entity(incl. slot) and yyyy=prio
387 // i.e.: search PrioQueue list with xxxx=actual T-Cont.Entity,
388 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == yyyy (expect 0..7)
389 usQrelPortMask := uint32((((uint32)(oFsm.tcont0ID)) << 16) + uint32(gemEntry.prioQueueIndex))
390
391 // MibDb usage: downstream PrioQueue.RelatedPort = xxyyzzzz with xx=slot, yy=UniPort and zzzz=prio
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000392 // i.e.: search PrioQueue list with yy=actual pOnuUniPort.UniID,
Himani Chawla26e555c2020-08-31 12:30:20 +0530393 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == zzzz (expect 0..7)
Holger Hildebrandt5ba6c132022-10-06 13:53:14 +0000394 // Note: As we do not maintain any slot numbering, slot number will be excluded from search pattern.
Himani Chawla26e555c2020-08-31 12:30:20 +0530395 // Furthermore OMCI Onu port-Id is expected to start with 1 (not 0).
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000396 dsQrelPortMask := uint32((((uint32)(oFsm.pOnuUniPort.UniID + 1)) << 16) + uint32(gemEntry.prioQueueIndex))
Himani Chawla26e555c2020-08-31 12:30:20 +0530397
398 usQueueFound := false
399 dsQueueFound := false
400 for _, mgmtEntityID := range queueInstKeys {
401 if meAttributes := oFsm.pOnuDB.GetMe(me.PriorityQueueClassID, mgmtEntityID); meAttributes != nil {
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000402 returnVal := meAttributes[me.PriorityQueue_RelatedPort]
Himani Chawla26e555c2020-08-31 12:30:20 +0530403 if returnVal != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000404 if relatedPort, err := oFsm.pOnuDB.GetUint32Attrib(returnVal); err == nil {
Himani Chawla26e555c2020-08-31 12:30:20 +0530405 if relatedPort == usQrelPortMask {
406 loGemPortAttribs.upQueueID = mgmtEntityID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000407 logger.Debugw(ctx, "UpQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
mpagenko01e726e2020-10-23 09:45:29 +0000408 "upQueueID": strconv.FormatInt(int64(loGemPortAttribs.upQueueID), 16), "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530409 usQueueFound = true
410 } else if (relatedPort&0xFFFFFF) == dsQrelPortMask && mgmtEntityID < 0x8000 {
411 loGemPortAttribs.downQueueID = mgmtEntityID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000412 logger.Debugw(ctx, "DownQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
mpagenko01e726e2020-10-23 09:45:29 +0000413 "downQueueID": strconv.FormatInt(int64(loGemPortAttribs.downQueueID), 16), "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530414 dsQueueFound = true
415 }
416 if usQueueFound && dsQueueFound {
417 break
418 }
419 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000420 logger.Warnw(ctx, "Could not convert attribute value", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530421 }
422 } else {
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000423 logger.Warnw(ctx, "PrioQueue.RelatedPort not found in meAttributes:", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530424 }
425 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000426 logger.Warnw(ctx, "No attributes available in DB:", log.Fields{"meClassID": me.PriorityQueueClassID,
mpagenko01e726e2020-10-23 09:45:29 +0000427 "mgmtEntityID": mgmtEntityID, "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530428 }
429 }
430 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000431 logger.Warnw(ctx, "No PriorityQueue instances found", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530432 }
433 loGemPortAttribs.direction = gemEntry.direction
434 loGemPortAttribs.qosPolicy = gemEntry.queueSchedPolicy
435 loGemPortAttribs.weight = gemEntry.queueWeight
436 loGemPortAttribs.pbitString = gemEntry.pbitString
ozgecanetsia82b91a62021-05-21 18:54:49 +0300437
ozgecanetsia4b232302020-11-11 10:58:10 +0300438 if gemEntry.isMulticast {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300439 //TODO this might effectively ignore the for loop starting at line 316
440 loGemPortAttribs.gemPortID = gemEntry.multicastGemPortID
ozgecanetsia4b232302020-11-11 10:58:10 +0300441 loGemPortAttribs.isMulticast = true
442 loGemPortAttribs.multicastGemID = gemEntry.multicastGemPortID
443 loGemPortAttribs.staticACL = gemEntry.staticACL
444 loGemPortAttribs.dynamicACL = gemEntry.dynamicACL
Himani Chawla26e555c2020-08-31 12:30:20 +0530445
dbainbri4d3a0dc2020-12-02 00:33:42 +0000446 logger.Debugw(ctx, "Multicast GemPort attributes:", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300447 "gemPortID": loGemPortAttribs.gemPortID,
448 "isMulticast": loGemPortAttribs.isMulticast,
449 "multicastGemID": loGemPortAttribs.multicastGemID,
450 "staticACL": loGemPortAttribs.staticACL,
451 "dynamicACL": loGemPortAttribs.dynamicACL,
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000452 "device-id": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300453 })
454
455 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000456 logger.Debugw(ctx, "Upstream GemPort attributes:", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300457 "gemPortID": loGemPortAttribs.gemPortID,
458 "upQueueID": loGemPortAttribs.upQueueID,
459 "downQueueID": loGemPortAttribs.downQueueID,
460 "pbitString": loGemPortAttribs.pbitString,
461 "prioQueueIndex": gemEntry.prioQueueIndex,
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000462 "device-id": oFsm.deviceID,
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300463 })
464 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530465
466 oFsm.gemPortAttribsSlice = append(oFsm.gemPortAttribsSlice, loGemPortAttribs)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530467 if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
468 meParams := me.ParamData{
469 EntityID: loGemPortAttribs.gemPortID,
470 Attributes: me.AttributeValueMap{
471 me.GemPortNetworkCtp_PortId: loGemPortAttribs.gemPortID,
472 me.GemPortNetworkCtp_TContPointer: oFsm.tcont0ID,
473 me.GemPortNetworkCtp_Direction: loGemPortAttribs.direction,
474 me.GemPortNetworkCtp_TrafficManagementPointerForUpstream: loGemPortAttribs.upQueueID,
475 me.GemPortNetworkCtp_PriorityQueuePointerForDownStream: loGemPortAttribs.downQueueID,
476 },
477 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530478 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpClassID, loGemPortAttribs.gemPortID, meParams.Attributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530479 var meAttributes me.AttributeValueMap //dummy , anyways we are not going to use the values.
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530480 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID, loGemPortAttribs.gemPortID, meAttributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530481
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530482 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemInterworkingTerminationPointClassID, loGemPortAttribs.gemPortID, meAttributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530483
484 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530485 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000486 if !oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
balaji.nagarajanca025612025-06-23 16:16:06 +0530487 //let the state machine run forward from here directly
488 if oFsm.PAdaptFsm != nil {
489 go func(aPAFsm *cmn.AdapterFsm) {
490 if aPAFsm != nil && aPAFsm.PFsm != nil {
491 _ = aPAFsm.PFsm.Event(aniEvStartConfig)
492 }
493 }(oFsm.PAdaptFsm)
494
495 }
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000496 } else {
497 logger.Debugw(ctx, "reconciling - skip omci-config of ANI side ", log.Fields{"device-id": oFsm.deviceID})
balaji.nagarajanca025612025-06-23 16:16:06 +0530498 //let the state machine run forward from here directly
499 if oFsm.PAdaptFsm != nil {
500 go func(aPAFsm *cmn.AdapterFsm) {
501 if aPAFsm != nil && aPAFsm.PFsm != nil {
502 _ = aPAFsm.PFsm.Event(aniEvSkipOmciConfig)
503 }
504 }(oFsm.PAdaptFsm)
505
506 }
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000507 }
balaji.nagarajanca025612025-06-23 16:16:06 +0530508 logger.Info(ctx, "UniPonAniConfigFsm prepareAndEnterConfigState end", log.Fields{
509 "device-id": oFsm.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530510 }
511}
512
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530513//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000514func (oFsm *UniPonAniConfigFsm) enterConfigStartingState(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530515 logger.Info(ctx, "UniPonAniConfigFsm start", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000516 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000517 // in case the used channel is not yet defined (can be re-used after restarts)
518 if oFsm.omciMIdsResponseReceived == nil {
519 oFsm.omciMIdsResponseReceived = make(chan bool)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000520 logger.Debug(ctx, "UniPonAniConfigFsm - OMCI multiInstance RxChannel defined")
mpagenko3dbcdd22020-07-22 07:38:45 +0000521 } else {
522 // as we may 're-use' this instance of FSM and the connected channel
523 // make sure there is no 'lingering' request in the already existing channel:
524 // (simple loop sufficient as we are the only receiver)
525 for len(oFsm.omciMIdsResponseReceived) > 0 {
526 <-oFsm.omciMIdsResponseReceived
527 }
528 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000529 //ensure internal slices are empty (which might be set from previous run) - release memory
530 oFsm.gemPortAttribsSlice = nil
mpagenkocf48e452021-04-23 09:23:00 +0000531 oFsm.mutexIsAwaitingResponse.Lock()
532 //reset the canceled state possibly existing from previous reset
533 oFsm.isCanceled = false
534 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000535
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000536 // start go routine for processing of ANI config messages
dbainbri4d3a0dc2020-12-02 00:33:42 +0000537 go oFsm.processOmciAniMessages(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000538
539 //let the state machine run forward from here directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000540 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko3dbcdd22020-07-22 07:38:45 +0000541 if pConfigAniStateAFsm != nil {
542 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
balaji.nagarajanca025612025-06-23 16:16:06 +0530543 go func(aPAFsm *cmn.AdapterFsm) {
544 if aPAFsm != nil && aPAFsm.PFsm != nil {
545 _ = aPAFsm.PFsm.Event(aniEvPrepareConfig)
546 }
547 }(pConfigAniStateAFsm)
mpagenko3dbcdd22020-07-22 07:38:45 +0000548
mpagenko3dbcdd22020-07-22 07:38:45 +0000549 }
550}
551
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530552//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000553func (oFsm *UniPonAniConfigFsm) enterCreatingDot1PMapper(ctx context.Context, e *fsm.Event) {
554 logger.Debugw(ctx, "UniPonAniConfigFsm Tx Create::Dot1PMapper", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000555 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000556 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000557 oFsm.requestEventOffset = 0 //0 offset for last config request activity
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000558 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000559 meInstance, err := oFsm.pOmciCC.SendCreateDot1PMapper(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
560 oFsm.mapperSP0ID, oFsm.PAdaptFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300561 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000562 logger.Errorw(ctx, "Dot1PMapper create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300563 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000564 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300565 if pConfigAniStateAFsm != nil {
566 oFsm.mutexPLastTxMeInstance.Unlock()
567 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000568 go func(aPAFsm *cmn.AdapterFsm) {
569 if aPAFsm != nil && aPAFsm.PFsm != nil {
570 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300571 }
572 }(pConfigAniStateAFsm)
573 return
574 }
575 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000576 //accept also nil as (error) return value for writing to LastTx
577 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000578 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300579 oFsm.mutexPLastTxMeInstance.Unlock()
580
mpagenko3dbcdd22020-07-22 07:38:45 +0000581}
582
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530583//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000584func (oFsm *UniPonAniConfigFsm) enterCreatingMBPCD(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530585 logger.Info(ctx, "Creating Tx MAC Bridge Port Config Data", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000586 "EntitytId": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16),
587 "TPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000588 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
589 bridgePtr := cmn.MacBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.MacBpNo) //cmp also omci_cc.go::sendCreateMBServiceProfile
mpagenko3dbcdd22020-07-22 07:38:45 +0000590 meParams := me.ParamData{
591 EntityID: oFsm.macBPCD0ID,
592 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000593 me.MacBridgePortConfigurationData_BridgeIdPointer: bridgePtr,
594 me.MacBridgePortConfigurationData_PortNum: 0xFF, //fixed unique ANI side indication
595 me.MacBridgePortConfigurationData_TpType: 3, //for .1PMapper
596 me.MacBridgePortConfigurationData_TpPointer: oFsm.mapperSP0ID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000597 },
598 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000599 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000600 meInstance, err := oFsm.pOmciCC.SendCreateMBPConfigDataVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
601 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300602 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000603 logger.Errorw(ctx, "MBPConfigDataVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300604 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000605 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300606 if pConfigAniStateAFsm != nil {
607 oFsm.mutexPLastTxMeInstance.Unlock()
608 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000609 go func(aPAFsm *cmn.AdapterFsm) {
610 if aPAFsm != nil && aPAFsm.PFsm != nil {
611 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300612 }
613 }(pConfigAniStateAFsm)
614 return
615 }
616 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000617 //accept also nil as (error) return value for writing to LastTx
618 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000619 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300620 oFsm.mutexPLastTxMeInstance.Unlock()
621
mpagenko3dbcdd22020-07-22 07:38:45 +0000622}
623
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530624//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000625func (oFsm *UniPonAniConfigFsm) enterSettingTconts(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530626 logger.Info(ctx, "Tx Setting Tcont ", log.Fields{
mpagenko3dbcdd22020-07-22 07:38:45 +0000627 "EntitytId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
628 "AllocId": strconv.FormatInt(int64(oFsm.alloc0ID), 16),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000629 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700630 "tcontExist": oFsm.tcontSetBefore})
631 //If tcont was set before, then no need to set it again. Let state machine to proceed.
632 if oFsm.tcontSetBefore {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000633 go func(aPAFsm *cmn.AdapterFsm) {
634 if aPAFsm != nil && aPAFsm.PFsm != nil {
635 _ = aPAFsm.PFsm.Event(aniEvRxTcontsResp)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700636 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000637 }(oFsm.PAdaptFsm)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700638 return
639 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000640 meParams := me.ParamData{
641 EntityID: oFsm.tcont0ID,
642 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000643 me.TCont_AllocId: oFsm.alloc0ID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000644 },
645 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000646 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000647 meInstance, err := oFsm.pOmciCC.SendSetTcontVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
648 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300649 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000650 logger.Errorw(ctx, "TcontVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300651 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000652 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300653 if pConfigAniStateAFsm != nil {
654 oFsm.mutexPLastTxMeInstance.Unlock()
655 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000656 go func(aPAFsm *cmn.AdapterFsm) {
657 if aPAFsm != nil && aPAFsm.PFsm != nil {
658 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300659 }
660 }(pConfigAniStateAFsm)
661 return
662 }
663 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000664 //accept also nil as (error) return value for writing to LastTx
665 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000666 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300667 oFsm.mutexPLastTxMeInstance.Unlock()
668
mpagenko3dbcdd22020-07-22 07:38:45 +0000669}
670
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530671//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000672func (oFsm *UniPonAniConfigFsm) enterCreatingGemNCTPs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530673 logger.Info(ctx, "UniPonAniConfigFsm - start creating GemNWCtp loop", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000674 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000675 go oFsm.performCreatingGemNCTPs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000676}
677
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530678//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000679func (oFsm *UniPonAniConfigFsm) enterCreatingGemIWs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530680 logger.Info(ctx, "UniPonAniConfigFsm - start creating GemIwTP loop", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000681 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000682 go oFsm.performCreatingGemIWs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000683}
684
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000685func (oFsm *UniPonAniConfigFsm) enterSettingPQs(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530686 logger.Info(ctx, "UniPonAniConfigFsm - start setting PrioQueue loop", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000687 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000688 go oFsm.performSettingPQs(ctx)
mpagenko3dbcdd22020-07-22 07:38:45 +0000689}
690
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000691func (oFsm *UniPonAniConfigFsm) enterSettingDot1PMapper(ctx context.Context, e *fsm.Event) {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300692
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530693 logger.Info(ctx, "UniPonAniConfigFsm Tx Set::.1pMapper with all PBits set", log.Fields{"EntitytId": 0x8042, /*cmp above*/
mpagenko8b07c1b2020-11-26 10:36:31 +0000694 "toGemIw": 1024, /* cmp above */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000695 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000696
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530697 logger.Info(ctx, "UniPonAniConfigFsm Tx Set::1pMapper", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000698 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +0000699 "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000700
mpagenko3dbcdd22020-07-22 07:38:45 +0000701 meParams := me.ParamData{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000702 EntityID: oFsm.mapperSP0ID,
Himani Chawla4d908332020-08-31 12:30:20 +0530703 Attributes: make(me.AttributeValueMap),
mpagenko3dbcdd22020-07-22 07:38:45 +0000704 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000705
706 //assign the GemPorts according to the configured Prio
707 var loPrioGemPortArray [8]uint16
708 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300709 if gemPortAttribs.isMulticast {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000710 logger.Debugw(ctx, "UniPonAniConfigFsm Port is Multicast, ignoring .1pMapper", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300711 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
712 "prioString": gemPortAttribs.pbitString})
713 continue
714 }
715 if gemPortAttribs.pbitString == "" {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000716 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString empty string error", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300717 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
718 "prioString": gemPortAttribs.pbitString})
719 continue
720 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000721 for i := 0; i < 8; i++ {
722 // "lenOfPbitMap(8) - i + 1" will give i-th pbit value from LSB position in the pbit map string
723 if prio, err := strconv.Atoi(string(gemPortAttribs.pbitString[7-i])); err == nil {
724 if prio == 1 { // Check this p-bit is set
725 if loPrioGemPortArray[i] == 0 {
726 loPrioGemPortArray[i] = gemPortAttribs.gemPortID //gemPortId=EntityID and unique
727 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000728 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString not unique", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000729 "device-id": oFsm.deviceID, "IgnoredGemPort": gemPortAttribs.gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000730 "SetGemPort": loPrioGemPortArray[i]})
731 }
732 }
733 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000734 logger.Warnw(ctx, "UniPonAniConfigFsm PrioString evaluation error", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000735 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000736 "prioString": gemPortAttribs.pbitString, "position": i})
737 }
738
739 }
740 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300741
ozgecanetsia4b232302020-11-11 10:58:10 +0300742 var foundIwPtr = false
Himani Chawla4d908332020-08-31 12:30:20 +0530743 for index, value := range loPrioGemPortArray {
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300744 meAttribute := fmt.Sprintf("InterworkTpPointerForPBitPriority%d", index)
Himani Chawla4d908332020-08-31 12:30:20 +0530745 if value != 0 {
746 foundIwPtr = true
Himani Chawla4d908332020-08-31 12:30:20 +0530747 meParams.Attributes[meAttribute] = value
dbainbri4d3a0dc2020-12-02 00:33:42 +0000748 logger.Debugw(ctx, "UniPonAniConfigFsm Set::1pMapper", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000749 "for Prio": index,
750 "IwPtr": strconv.FormatInt(int64(value), 16),
751 "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300752 } else {
753 // The null pointer 0xFFFF specifies that frames with the associated priority are to be discarded.
mpagenko8b5fdd22020-12-17 17:58:32 +0000754 // setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting
755 // but except for processing effort does not really harm - left to keep changes low
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300756 meParams.Attributes[meAttribute] = 0xffff
Himani Chawla4d908332020-08-31 12:30:20 +0530757 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000758 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300759 // The TP type value 0 also indicates bridging mapping, and the TP pointer should be set to 0xFFFF
mpagenko8b5fdd22020-12-17 17:58:32 +0000760 // setting this parameter is not strictly needed anymore with the ensured .1pMapper create default setting
761 // but except for processing effort does not really harm - left to keep changes low
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000762 meParams.Attributes[me.Ieee8021PMapperServiceProfile_TpPointer] = 0xffff
Himani Chawla4d908332020-08-31 12:30:20 +0530763
764 if !foundIwPtr {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530765 logger.Warn(ctx, "UniPonAniConfigFsm no GemIwPtr found for .1pMapper - abort", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000766 "device-id": oFsm.deviceID})
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300767 //TODO With multicast is possible that no upstream gem ports are not present in the tech profile,
768 // 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 +0000769 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000770 //pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300771 //if pConfigAniStateAFsm != nil {
772 // // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000773 // go func(aPAFsm *cmn.AdapterFsm) {
774 // if aPAFsm != nil && aPAFsm.PFsm != nil {
775 // _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300776 // }
777 // }(pConfigAniStateAFsm)
778 //}
779 //Moving forward the FSM as if the response was received correctly.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000780 pConfigAniStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000781 if pConfigAniStateAFsm != nil {
782 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000783 go func(aPAFsm *cmn.AdapterFsm) {
784 if aPAFsm != nil && aPAFsm.PFsm != nil {
785 _ = aPAFsm.PFsm.Event(aniEvRxDot1pmapSResp)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000786 }
787 }(pConfigAniStateAFsm)
788 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300789 } else {
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000790 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000791 meInstance, err := oFsm.pOmciCC.SendSetDot1PMapperVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(), true,
792 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300793 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000794 logger.Errorw(ctx, "Dot1PMapperVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300795 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000796 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300797 if pConfigAniStateAFsm != nil {
798 oFsm.mutexPLastTxMeInstance.Unlock()
799 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000800 go func(aPAFsm *cmn.AdapterFsm) {
801 if aPAFsm != nil && aPAFsm.PFsm != nil {
802 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300803 }
804 }(pConfigAniStateAFsm)
805 return
806 }
807 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +0300808 //accept also nil as (error) return value for writing to LastTx
809 // - this avoids misinterpretation of new received OMCI messages
810 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300811 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000812 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000813}
814
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000815func (oFsm *UniPonAniConfigFsm) enterAniConfigDone(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530816 logger.Info(ctx, "UniPonAniConfigFsm ani config done", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000817 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenko01e726e2020-10-23 09:45:29 +0000818 //store that the UNI related techProfile processing is done for the given Profile and Uni
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000819 oFsm.pUniTechProf.setConfigDone(oFsm.pOnuUniPort.UniID, oFsm.techProfileID, true)
820 if !oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() {
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000821 //use DeviceHandler event notification directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000822 oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset)))
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000823 //if techProfile processing is done it must be checked, if some prior/parallel flow configuration is pending
824 // but only in case the techProfile was configured (not deleted)
825 if oFsm.requestEventOffset == 0 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000826 go oFsm.pDeviceHandler.VerifyUniVlanConfigRequest(ctx, oFsm.pOnuUniPort, oFsm.techProfileID)
Holger Hildebrandt01bc3bf2021-04-26 09:59:01 +0000827 }
828 } else {
829 logger.Debugw(ctx, "reconciling - skip AniConfigDone processing", log.Fields{"device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +0000830 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000831 if oFsm.isChanSet() {
mpagenko01e726e2020-10-23 09:45:29 +0000832 // indicate processing done to the caller
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000833 logger.Debugw(ctx, "UniPonAniConfigFsm processingDone on channel", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000834 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
835 oFsm.chSuccess <- oFsm.procStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000836 oFsm.setChanSet(false) //reset the internal channel state
mpagenko3dbcdd22020-07-22 07:38:45 +0000837 }
mpagenko01e726e2020-10-23 09:45:29 +0000838
839 //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 +0000840}
841
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530842//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000843func (oFsm *UniPonAniConfigFsm) enterRemovingGemIW(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +0000844 // no need to protect access to oFsm.waitFlowDeleteChannel, only used in synchronized state entries
845 // or CancelProcessing() that uses separate isWaitingForFlowDelete to write to the channel
mpagenkobb47bc22021-04-20 13:29:09 +0000846 //flush the waitFlowDeleteChannel - possibly already/still set by some previous activity
847 select {
848 case <-oFsm.waitFlowDeleteChannel:
849 logger.Debug(ctx, "flushed waitFlowDeleteChannel")
850 default:
851 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000852
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000853 uniVlanConfigFsm := oFsm.pDeviceHandler.GetUniVlanConfigFsm(oFsm.pOnuUniPort.UniID)
854 if uniVlanConfigFsm != nil {
mpagenko3ce9fa02021-07-28 13:26:54 +0000855 // ensure mutexTPState not locked before calling some VlanConfigFsm activity (that might already be pending on it)
Holger Hildebrandtc192bc42021-10-28 14:38:31 +0000856 if uniVlanConfigFsm.IsFlowRemovePending(ctx, oFsm.waitFlowDeleteChannel) {
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000857 logger.Debugw(ctx, "flow remove pending - wait before processing gem port delete",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000858 log.Fields{"device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000859 // 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 +0000860 pConfigAniStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000861 if pConfigAniStateAFsm != nil {
862 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000863 go func(aPAFsm *cmn.AdapterFsm) {
864 if aPAFsm != nil && aPAFsm.PFsm != nil {
865 _ = aPAFsm.PFsm.Event(aniEvWaitFlowRem)
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000866 }
867 }(pConfigAniStateAFsm)
868 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000869 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 +0000870 }
871 return
Girish Gowdra26a40922021-01-29 17:14:34 -0800872 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000873 } else {
874 logger.Debugw(ctx, "uni vlan config doesn't exist - no flow remove could be pending",
875 log.Fields{"device-id": oFsm.deviceID, "techProfile-id": oFsm.techProfileID})
Girish Gowdra26a40922021-01-29 17:14:34 -0800876 }
877
mpagenko3ce9fa02021-07-28 13:26:54 +0000878 oFsm.pUniTechProf.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000879 // get the related GemPort entity Id from pUniTechProf, OMCI Gem* entityID is set to be equal to GemPortId!
mpagenko8b07c1b2020-11-26 10:36:31 +0000880 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +0000881 oFsm.pUniTechProf.mutexTPState.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000882 logger.Debugw(ctx, "UniPonAniConfigFsm - start removing one GemIwTP", log.Fields{
883 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko8b07c1b2020-11-26 10:36:31 +0000884 "GemIwTp-entity-id": loGemPortID})
885 oFsm.requestEventOffset = 1 //offset 1 to indicate last activity = remove
886
887 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000888 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000889 meInstance, err := oFsm.pOmciCC.SendDeleteGemIWTP(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
890 oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300891 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000892 logger.Errorw(ctx, "GemIWTP delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300893 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000894 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300895 if pConfigAniStateAFsm != nil {
896 oFsm.mutexPLastTxMeInstance.Unlock()
897 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000898 go func(aPAFsm *cmn.AdapterFsm) {
899 if aPAFsm != nil && aPAFsm.PFsm != nil {
900 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300901 }
902 }(pConfigAniStateAFsm)
903 return
904 }
905 }
mpagenko8b07c1b2020-11-26 10:36:31 +0000906 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +0300907 oFsm.mutexPLastTxMeInstance.Unlock()
praneeth kumar nalmas3947c582023-12-13 15:38:50 +0530908 logger.Infow(ctx, "Deleting GemIWTP at the ONU DB ", log.Fields{"device-id": oFsm.deviceID, "GEMID": loGemPortID})
909 oFsm.pOnuDB.DeleteMe(me.GemInterworkingTerminationPointClassID, loGemPortID)
mpagenko8b07c1b2020-11-26 10:36:31 +0000910}
911
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530912//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000913func (oFsm *UniPonAniConfigFsm) enterWaitingFlowRem(ctx context.Context, e *fsm.Event) {
mpagenkobb47bc22021-04-20 13:29:09 +0000914 oFsm.mutexIsAwaitingResponse.Lock()
915 oFsm.isWaitingForFlowDelete = true
916 oFsm.mutexIsAwaitingResponse.Unlock()
917 select {
918 // maybe be also some outside cancel (but no context modeled for the moment ...)
919 // case <-ctx.Done():
920 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000921 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 +0000922 logger.Warnw(ctx, "UniPonAniConfigFsm WaitingFlowRem timeout", log.Fields{
923 "for device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000924 oFsm.mutexIsAwaitingResponse.Lock()
925 oFsm.isWaitingForFlowDelete = false
926 oFsm.mutexIsAwaitingResponse.Unlock()
927 //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 +0000928 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000929 if pConfigAniStateAFsm != nil {
930 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000931 go func(aPAFsm *cmn.AdapterFsm) {
932 if aPAFsm != nil && aPAFsm.PFsm != nil {
933 _ = aPAFsm.PFsm.Event(aniEvFlowRemDone)
mpagenkobb47bc22021-04-20 13:29:09 +0000934 }
935 }(pConfigAniStateAFsm)
936 } else {
937 logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000938 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000939 }
940 return
941
942 case success := <-oFsm.waitFlowDeleteChannel:
943 if success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000944 logger.Debugw(ctx, "UniPonAniConfigFsm flow removed info received", log.Fields{
945 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000946 oFsm.mutexIsAwaitingResponse.Lock()
947 oFsm.isWaitingForFlowDelete = false
948 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000949 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000950 if pConfigAniStateAFsm != nil {
951 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000952 go func(aPAFsm *cmn.AdapterFsm) {
953 if aPAFsm != nil && aPAFsm.PFsm != nil {
954 _ = aPAFsm.PFsm.Event(aniEvFlowRemDone)
mpagenkobb47bc22021-04-20 13:29:09 +0000955 }
956 }(pConfigAniStateAFsm)
957 } else {
958 logger.Errorw(ctx, "pConfigAniStateAFsm is nil", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000959 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000960 }
961 return
962 }
963 // waiting was aborted (probably on external request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000964 logger.Debugw(ctx, "UniPonAniConfigFsm WaitingFlowRem aborted", log.Fields{
965 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "techProfile-id": oFsm.techProfileID})
mpagenkobb47bc22021-04-20 13:29:09 +0000966 oFsm.mutexIsAwaitingResponse.Lock()
967 oFsm.isWaitingForFlowDelete = false
968 oFsm.mutexIsAwaitingResponse.Unlock()
969 //to be sure we can just generate the reset-event to ensure leaving this state towards 'reset'
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000970 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenkobb47bc22021-04-20 13:29:09 +0000971 if pConfigAniStateAFsm != nil {
972 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000973 go func(aPAFsm *cmn.AdapterFsm) {
974 if aPAFsm != nil && aPAFsm.PFsm != nil {
975 _ = aPAFsm.PFsm.Event(aniEvReset)
mpagenkobb47bc22021-04-20 13:29:09 +0000976 }
977 }(pConfigAniStateAFsm)
978 }
979 return
980 }
981}
982
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +0530983//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000984func (oFsm *UniPonAniConfigFsm) enterRemovingGemNCTP(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +0000985 oFsm.pUniTechProf.mutexTPState.RLock()
mpagenko8b07c1b2020-11-26 10:36:31 +0000986 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +0000987 oFsm.pUniTechProf.mutexTPState.RUnlock()
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530988 logger.Info(ctx, "UniPonAniConfigFsm - start removing one GemNCTP", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000989 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
mpagenko8b07c1b2020-11-26 10:36:31 +0000990 "GemNCTP-entity-id": loGemPortID})
991 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +0000992 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000993 meInstance, err := oFsm.pOmciCC.SendDeleteGemNCTP(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
994 oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300995 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000996 logger.Errorw(ctx, "GemNCTP delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +0300997 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000998 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300999 if pConfigAniStateAFsm != nil {
1000 oFsm.mutexPLastTxMeInstance.Unlock()
1001 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001002 go func(aPAFsm *cmn.AdapterFsm) {
1003 if aPAFsm != nil && aPAFsm.PFsm != nil {
1004 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001005 }
1006 }(pConfigAniStateAFsm)
1007 return
1008 }
1009 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001010 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001011 oFsm.mutexPLastTxMeInstance.Unlock()
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301012 oFsm.pOnuDB.DeleteMe(me.GemPortNetworkCtpClassID, loGemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001013 // Mark the gem port to be removed for Performance History monitoring
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001014 OnuMetricsManager := oFsm.pDeviceHandler.GetOnuMetricsManager()
1015 if OnuMetricsManager != nil {
1016 OnuMetricsManager.RemoveGemPortForPerfMonitoring(ctx, loGemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001017 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001018}
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301019
1020//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001021func (oFsm *UniPonAniConfigFsm) enterRemovingTD(ctx context.Context, e *fsm.Event) {
mpagenko3ce9fa02021-07-28 13:26:54 +00001022 oFsm.pUniTechProf.mutexTPState.RLock()
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001023 loGemPortID := (*(oFsm.pUniTechProf.mapRemoveGemEntry[oFsm.uniTpKey])).gemPortID
mpagenko3ce9fa02021-07-28 13:26:54 +00001024 oFsm.pUniTechProf.mutexTPState.RUnlock()
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301025 logger.Info(ctx, "UniPonAniConfigFsm - start removing Traffic Descriptor", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001026 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID,
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001027 "TD-entity-id": loGemPortID})
1028
1029 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001030 meInstance, err := oFsm.pOmciCC.SendDeleteTD(log.WithSpanFromContext(context.TODO(), ctx),
1031 oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, loGemPortID)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001032
1033 if err != nil {
1034 logger.Errorw(ctx, "TD delete failed - proceed fsm",
1035 log.Fields{"device-id": oFsm.deviceID, "gemPortID": loGemPortID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001036 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001037 if pConfigAniStateAFsm != nil {
1038 oFsm.mutexPLastTxMeInstance.Unlock()
1039 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001040 go func(aPAFsm *cmn.AdapterFsm) {
1041 if aPAFsm != nil && aPAFsm.PFsm != nil {
1042 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001043 }
1044 }(pConfigAniStateAFsm)
1045 return
1046 }
1047 }
1048 oFsm.pLastTxMeInstance = meInstance
1049 oFsm.mutexPLastTxMeInstance.Unlock()
1050}
mpagenko8b07c1b2020-11-26 10:36:31 +00001051
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301052//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001053func (oFsm *UniPonAniConfigFsm) enterResettingTcont(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301054 logger.Info(ctx, "UniPonAniConfigFsm - start resetting the TCont", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001055 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001056
1057 oFsm.requestEventOffset = 1 //offset 1 for last remove activity
1058 // this state entry is only expected in a suitable state (checked outside in onu_uni_tp)
1059 meParams := me.ParamData{
1060 EntityID: oFsm.tcont0ID,
1061 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001062 me.TCont_AllocId: cmn.UnusedTcontAllocID,
mpagenko8b07c1b2020-11-26 10:36:31 +00001063 },
1064 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001065 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001066 meInstance, err := oFsm.pOmciCC.SendSetTcontVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1067 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001068 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001069 logger.Errorw(ctx, "TcontVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001070 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001071 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001072 if pConfigAniStateAFsm != nil {
1073 oFsm.mutexPLastTxMeInstance.Unlock()
1074 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001075 go func(aPAFsm *cmn.AdapterFsm) {
1076 if aPAFsm != nil && aPAFsm.PFsm != nil {
1077 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001078 }
1079 }(pConfigAniStateAFsm)
1080 return
1081 }
1082 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001083 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001084 oFsm.mutexPLastTxMeInstance.Unlock()
1085
mpagenko8b07c1b2020-11-26 10:36:31 +00001086}
1087
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301088//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001089func (oFsm *UniPonAniConfigFsm) enterRemoving1pMapper(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301090 logger.Info(ctx, "UniPonAniConfigFsm - start deleting the .1pMapper", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001091 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
bseenivaeba8eb12024-12-13 11:54:28 +05301092 var mapGemPortParams map[uint16]*gemPortParamStruct
Mahir Gunyel9545be22021-07-04 15:53:16 -07001093 unicastGemCount := 0
bseenivaeba8eb12024-12-13 11:54:28 +05301094 oFsm.pUniTechProf.mutexTPState.RLock()
1095 if _, ok := oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey]; ok {
1096 mapGemPortParams = oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].mapGemPortParams
1097 } else {
1098 logger.Warnw(ctx, "GemPortParams not found in mapPonAniConfig", log.Fields{"device-id": oFsm.deviceID,
1099 "uni-id": oFsm.pOnuUniPort.UniID})
1100 }
1101 oFsm.pUniTechProf.mutexTPState.RUnlock()
Mahir Gunyel9545be22021-07-04 15:53:16 -07001102 for _, gemEntry := range mapGemPortParams {
1103 if !gemEntry.isMulticast {
1104 unicastGemCount++
1105 }
1106 }
1107 if unicastGemCount > 1 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001108 logger.Debugw(ctx, "UniPonAniConfigFsm - Not the last gem in fsm. Skip the rest", log.Fields{
1109 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "unicast-gem-count": unicastGemCount, "gem-count": len(mapGemPortParams)})
1110 pConfigAniStateAFsm := oFsm.PAdaptFsm
Mahir Gunyel9545be22021-07-04 15:53:16 -07001111 if pConfigAniStateAFsm != nil {
1112 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001113 go func(aPAFsm *cmn.AdapterFsm) {
1114 if aPAFsm != nil && aPAFsm.PFsm != nil {
1115 _ = aPAFsm.PFsm.Event(aniEvRemGemDone)
Mahir Gunyel9545be22021-07-04 15:53:16 -07001116 }
1117 }(pConfigAniStateAFsm)
1118 return
1119 }
1120 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001121 logger.Debugw(ctx, "UniPonAniConfigFsm - Last gem in fsm. Continue with Mapper removal", log.Fields{
1122 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, "unicast-gem-count": unicastGemCount, "gem-count": len(mapGemPortParams)})
mpagenko8b07c1b2020-11-26 10:36:31 +00001123
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001124 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001125 meInstance, err := oFsm.pOmciCC.SendDeleteDot1PMapper(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1126 oFsm.PAdaptFsm.CommChan, oFsm.mapperSP0ID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001127 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001128 logger.Errorw(ctx, "Dot1Mapper delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001129 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001130 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001131 if pConfigAniStateAFsm != nil {
1132 oFsm.mutexPLastTxMeInstance.Unlock()
1133 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001134 go func(aPAFsm *cmn.AdapterFsm) {
1135 if aPAFsm != nil && aPAFsm.PFsm != nil {
1136 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001137 }
1138 }(pConfigAniStateAFsm)
1139 return
1140 }
1141 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001142 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001143 oFsm.mutexPLastTxMeInstance.Unlock()
1144
mpagenko8b07c1b2020-11-26 10:36:31 +00001145}
1146
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301147//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001148func (oFsm *UniPonAniConfigFsm) enterRemovingAniBPCD(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301149 logger.Info(ctx, "UniPonAniConfigFsm - start deleting the ANI MBCD", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001150 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001151
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001152 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001153 meInstance, err := oFsm.pOmciCC.SendDeleteMBPConfigData(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1154 oFsm.PAdaptFsm.CommChan, oFsm.macBPCD0ID)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001155 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001156 logger.Errorw(ctx, "MBPConfigData delete failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001157 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001158 pConfigAniStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001159 if pConfigAniStateAFsm != nil {
1160 oFsm.mutexPLastTxMeInstance.Unlock()
1161 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001162 go func(aPAFsm *cmn.AdapterFsm) {
1163 if aPAFsm != nil && aPAFsm.PFsm != nil {
1164 _ = aPAFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001165 }
1166 }(pConfigAniStateAFsm)
1167 return
1168 }
1169 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001170 oFsm.pLastTxMeInstance = meInstance
ozgecanetsiab36ed572021-04-01 10:38:48 +03001171 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko8b07c1b2020-11-26 10:36:31 +00001172}
1173
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001174func (oFsm *UniPonAniConfigFsm) enterAniRemoveDone(ctx context.Context, e *fsm.Event) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301175 logger.Info(ctx, "UniPonAniConfigFsm ani removal done", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001176 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001177 //use DeviceHandler event notification directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001178 oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent((uint8(oFsm.requestEvent) + oFsm.requestEventOffset)))
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001179 if oFsm.isChanSet() {
mpagenko8b07c1b2020-11-26 10:36:31 +00001180 // indicate processing done to the caller
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001181 logger.Debugw(ctx, "UniPonAniConfigFsm processingDone on channel", log.Fields{
mpagenko8b07c1b2020-11-26 10:36:31 +00001182 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
1183 oFsm.chSuccess <- oFsm.procStep
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001184 oFsm.setChanSet(false) //reset the internal channel state
mpagenko8b07c1b2020-11-26 10:36:31 +00001185 }
1186
1187 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001188 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko8b07c1b2020-11-26 10:36:31 +00001189 if pConfigAniStateAFsm != nil {
1190 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001191 go func(aPAFsm *cmn.AdapterFsm) {
1192 if aPAFsm != nil && aPAFsm.PFsm != nil {
1193 _ = aPAFsm.PFsm.Event(aniEvReset)
mpagenko8b07c1b2020-11-26 10:36:31 +00001194 }
1195 }(pConfigAniStateAFsm)
1196 }
1197}
1198
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001199func (oFsm *UniPonAniConfigFsm) enterResettingState(ctx context.Context, e *fsm.Event) {
1200 logger.Debugw(ctx, "UniPonAniConfigFsm resetting", log.Fields{
1201 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001202
mpagenko45cc6a32021-07-23 10:06:57 +00001203 if oFsm.isChanSet() {
1204 // indicate processing error to the caller (in case there was still some open request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001205 logger.Debugw(ctx, "UniPonAniConfigFsm processingError on channel", log.Fields{
mpagenko45cc6a32021-07-23 10:06:57 +00001206 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.deviceID})
1207 //use non-blocking channel send to avoid blocking because of non-existing receiver
1208 // (even though the channel is checked on 'set', the outside receiver channel might (theoretically) already be deleted)
1209 select {
1210 case oFsm.chSuccess <- 0:
1211 default:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001212 logger.Debugw(ctx, "UniPonAniConfigFsm processingError not send on channel (no receiver)", log.Fields{
mpagenko45cc6a32021-07-23 10:06:57 +00001213 "device-id": oFsm.deviceID})
1214 }
1215 oFsm.setChanSet(false) //reset the internal channel state
1216 }
1217
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001218 pConfigAniStateAFsm := oFsm.PAdaptFsm
mpagenko3dbcdd22020-07-22 07:38:45 +00001219 if pConfigAniStateAFsm != nil {
1220 // abort running message processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001221 fsmAbortMsg := cmn.Message{
1222 Type: cmn.TestMsg,
1223 Data: cmn.TestMessage{
1224 TestMessageVal: cmn.AbortMessageProcessing,
mpagenko3dbcdd22020-07-22 07:38:45 +00001225 },
1226 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001227 pConfigAniStateAFsm.CommChan <- fsmAbortMsg
mpagenko3dbcdd22020-07-22 07:38:45 +00001228
1229 //try to restart the FSM to 'disabled', decouple event transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001230 go func(aPAFsm *cmn.AdapterFsm) {
1231 if aPAFsm != nil && aPAFsm.PFsm != nil {
1232 _ = aPAFsm.PFsm.Event(aniEvRestart)
mpagenko3dbcdd22020-07-22 07:38:45 +00001233 }
1234 }(pConfigAniStateAFsm)
Akash Soni3de0e062024-12-11 16:37:26 +05301235 logger.Warnf(ctx, "calling HandleAniConfigFSMFailure resetting", log.Fields{
1236 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
1237 oFsm.pDeviceHandler.HandleAniConfigFSMFailure(ctx, oFsm.pOnuUniPort.UniID)
mpagenko3dbcdd22020-07-22 07:38:45 +00001238 }
1239}
1240
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +05301241//nolint:unparam
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001242func (oFsm *UniPonAniConfigFsm) enterDisabledState(ctx context.Context, e *fsm.Event) {
1243 logger.Debugw(ctx, "UniPonAniConfigFsm enters disabled state", log.Fields{
1244 "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID})
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001245 oFsm.mutexPLastTxMeInstance.Lock()
1246 defer oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko01e726e2020-10-23 09:45:29 +00001247 oFsm.pLastTxMeInstance = nil
mpagenko1cc3cb42020-07-27 15:24:38 +00001248}
1249
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001250func (oFsm *UniPonAniConfigFsm) processOmciAniMessages(ctx context.Context) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301251 logger.Info(ctx, "Start UniPonAniConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001252loop:
1253 for {
mpagenko3dbcdd22020-07-22 07:38:45 +00001254 // case <-ctx.Done():
mpagenko01e726e2020-10-23 09:45:29 +00001255 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001256 // break loop
bseenivaeba8eb12024-12-13 11:54:28 +05301257 select {
1258 case message, ok := <-oFsm.PAdaptFsm.CommChan:
1259 if !ok {
1260 logger.Warn(ctx, "UniPonAniConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID})
1261 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
1262 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +00001263 break loop
1264 }
bseenivaeba8eb12024-12-13 11:54:28 +05301265 logger.Debugw(ctx, "UniPonAniConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID})
1266
1267 switch message.Type {
1268 case cmn.TestMsg:
1269 msg, _ := message.Data.(cmn.TestMessage)
1270 if msg.TestMessageVal == cmn.AbortMessageProcessing {
1271 logger.Infow(ctx, "UniPonAniConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID})
1272 break loop
1273 }
1274 logger.Warnw(ctx, "UniPonAniConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal})
1275 case cmn.OMCI:
1276 msg, _ := message.Data.(cmn.OmciMessage)
1277 oFsm.handleOmciAniConfigMessage(ctx, msg)
1278 default:
1279 logger.Warn(ctx, "UniPonAniConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID,
1280 "message.Type": message.Type})
1281 }
1282 case _, ok := <-oFsm.pDeviceHandler.GetDeviceDeleteCommChan(ctx):
1283 if !ok {
1284 logger.Warnw(ctx, "Device deletion channel closed", log.Fields{"device-id": oFsm.deviceID})
1285 }
1286 break loop
Himani Chawla4d908332020-08-31 12:30:20 +05301287 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001288
Himani Chawla4d908332020-08-31 12:30:20 +05301289 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001290 logger.Infow(ctx, "End UniPonAniConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301291}
1292
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001293func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigCreateResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +05301294 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse)
1295 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001296 logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001297 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301298 return
1299 }
1300 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
1301 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001302 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001303 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301304 return
1305 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001306 logger.Debugw(ctx, "CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
mpagenkofc4f56e2020-11-04 17:17:49 +00001307 if msgObj.Result == me.Success || msgObj.Result == me.InstanceExists {
1308 //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 +00001309 oFsm.mutexPLastTxMeInstance.RLock()
1310 if oFsm.pLastTxMeInstance != nil {
1311 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1312 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1313 // maybe we can use just the same eventName for different state transitions like "forward"
1314 // - might be checked, but so far I go for sure and have to inspect the concrete state events ...
1315 switch oFsm.pLastTxMeInstance.GetName() {
1316 case "Ieee8021PMapperServiceProfile":
1317 { // let the FSM proceed ...
1318 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001319 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxDot1pmapCResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001320 }
1321 case "MacBridgePortConfigurationData":
1322 { // let the FSM proceed ...
1323 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001324 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxMbpcdResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001325 }
1326 case "GemPortNetworkCtp", "GemInterworkingTerminationPoint", "MulticastGemInterworkingTerminationPoint":
1327 { // let aniConfig Multi-Id processing proceed by stopping the wait function
1328 oFsm.mutexPLastTxMeInstance.RUnlock()
1329 oFsm.omciMIdsResponseReceived <- true
1330 }
1331 default:
1332 {
1333 oFsm.mutexPLastTxMeInstance.RUnlock()
1334 logger.Warnw(ctx, "Unsupported ME name received!",
1335 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1336 }
mpagenkofc4f56e2020-11-04 17:17:49 +00001337 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001338 } else {
1339 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenkofc4f56e2020-11-04 17:17:49 +00001340 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001341 } else {
1342 oFsm.mutexPLastTxMeInstance.RUnlock()
1343 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +00001344 }
1345 } else {
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001346 logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?",
1347 log.Fields{"Error": msgObj.Result, "device-id": oFsm.deviceID})
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001348 // possibly force FSM into abort or ignore some errors for some messages?
1349 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1350 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
Himani Chawla4d908332020-08-31 12:30:20 +05301351 return
1352 }
Himani Chawla4d908332020-08-31 12:30:20 +05301353}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001354func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigSetFailResponseMessage(ctx context.Context, msgObj *omci.SetResponse) {
Mahir Gunyel01034b62021-06-29 11:25:09 -07001355 //If TCONT fails, then we need to revert the allocated TCONT in DB.
1356 //Because FSMs are running sequentially, we don't expect the same TCONT hit by another tech-profile FSM while this FSM is running.
1357 oFsm.mutexPLastTxMeInstance.RLock()
1358 defer oFsm.mutexPLastTxMeInstance.RUnlock()
1359 if oFsm.pLastTxMeInstance != nil && msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1360 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1361 switch oFsm.pLastTxMeInstance.GetName() {
1362 case "TCont":
1363 //If this is for TCONT creation(requestEventOffset=0) and this is the first allocation of TCONT(so noone else is using the same TCONT)
1364 //We should revert DB
bseenivaeba8eb12024-12-13 11:54:28 +05301365 oFsm.pUniTechProf.mutexTPState.RLock()
Mahir Gunyel01034b62021-06-29 11:25:09 -07001366 if oFsm.requestEventOffset == 0 && !oFsm.tcontSetBefore && oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey] != nil {
1367 logger.Debugw(ctx, "UniPonAniConfigFsm TCONT creation failed on device. Freeing alloc id", log.Fields{"device-id": oFsm.deviceID,
1368 "alloc-id": oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID, "uni-tp": oFsm.uniTpKey})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001369 if oFsm.pOnuDeviceEntry != nil {
1370 oFsm.pOnuDeviceEntry.FreeTcont(ctx, oFsm.pUniTechProf.mapPonAniConfig[oFsm.uniTpKey].tcontParams.allocID)
Mahir Gunyel01034b62021-06-29 11:25:09 -07001371 } else {
1372 logger.Warnw(ctx, "Unable to get device entry! couldn't free tcont",
1373 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1374 }
1375 }
bseenivaeba8eb12024-12-13 11:54:28 +05301376 oFsm.pUniTechProf.mutexTPState.RUnlock()
Mahir Gunyel01034b62021-06-29 11:25:09 -07001377 default:
1378 logger.Warnw(ctx, "Unsupported ME name received with error!",
1379 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "result": msgObj.Result, "device-id": oFsm.deviceID})
1380 }
1381 }
1382}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001383func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigSetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +05301384 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
1385 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001386 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be detected for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001387 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301388 return
1389 }
1390 msgObj, msgOk := msgLayer.(*omci.SetResponse)
1391 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001392 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be assigned for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +00001393 log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301394 return
1395 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001396 logger.Debugw(ctx, "UniPonAniConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +05301397 if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001398 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci SetResponse Error - later: drive FSM to abort state ?",
mpagenko01e726e2020-10-23 09:45:29 +00001399 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001400 // possibly force FSM into abort or ignore some errors for some messages?
1401 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1402 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
Mahir Gunyel01034b62021-06-29 11:25:09 -07001403 oFsm.handleOmciAniConfigSetFailResponseMessage(ctx, msgObj)
Himani Chawla4d908332020-08-31 12:30:20 +05301404 return
1405 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001406 oFsm.mutexPLastTxMeInstance.RLock()
1407 if oFsm.pLastTxMeInstance != nil {
1408 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1409 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1410 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
1411 // if, then something like:
1412 //oFsm.pOnuDB.StoreMe(msgObj)
Himani Chawla4d908332020-08-31 12:30:20 +05301413
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001414 switch oFsm.pLastTxMeInstance.GetName() {
1415 case "TCont":
1416 { // let the FSM proceed ...
1417 oFsm.mutexPLastTxMeInstance.RUnlock()
1418 if oFsm.requestEventOffset == 0 { //from TCont config request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001419 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxTcontsResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001420 } else { // from T-Cont reset request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001421 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxResetTcontResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001422 }
1423 }
1424 case "PriorityQueue", "MulticastGemInterworkingTerminationPoint":
1425 { // let the PrioQueue init proceed by stopping the wait function
1426 oFsm.mutexPLastTxMeInstance.RUnlock()
1427 oFsm.omciMIdsResponseReceived <- true
1428 }
1429 case "Ieee8021PMapperServiceProfile":
1430 { // let the FSM proceed ...
1431 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001432 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxDot1pmapSResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001433 }
1434 default:
1435 {
1436 oFsm.mutexPLastTxMeInstance.RUnlock()
1437 logger.Warnw(ctx, "Unsupported ME name received!",
1438 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001439 }
Himani Chawla4d908332020-08-31 12:30:20 +05301440 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001441 } else {
1442 oFsm.mutexPLastTxMeInstance.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +05301443 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001444 } else {
1445 oFsm.mutexPLastTxMeInstance.RUnlock()
1446 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301447 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001448}
1449
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001450func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigDeleteResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
mpagenko8b07c1b2020-11-26 10:36:31 +00001451 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeDeleteResponse)
1452 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001453 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be detected for DeleteResponse",
mpagenko8b07c1b2020-11-26 10:36:31 +00001454 log.Fields{"device-id": oFsm.deviceID})
1455 return
1456 }
1457 msgObj, msgOk := msgLayer.(*omci.DeleteResponse)
1458 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001459 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci Msg layer could not be assigned for DeleteResponse",
mpagenko8b07c1b2020-11-26 10:36:31 +00001460 log.Fields{"device-id": oFsm.deviceID})
1461 return
1462 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001463 logger.Debugw(ctx, "UniPonAniConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
Akash Soni8eff4632024-12-11 13:41:46 +05301464 if msgObj.Result == me.UnknownInstance {
1465 logger.Warnw(ctx, "UniPonAniConfigFsm - Unknow Instance",
1466 log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj, "Error": msgObj.Result})
1467 } else if msgObj.Result != me.Success {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001468 logger.Errorw(ctx, "UniPonAniConfigFsm - Omci DeleteResponse Error",
mpagenko8b07c1b2020-11-26 10:36:31 +00001469 log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result})
1470 //TODO: - later: possibly force FSM into abort or ignore some errors for some messages?
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001471 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
1472 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
mpagenko8b07c1b2020-11-26 10:36:31 +00001473 return
1474 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001475 oFsm.mutexPLastTxMeInstance.RLock()
1476 if oFsm.pLastTxMeInstance != nil {
1477 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
1478 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
1479 //remove ME from DB //TODO??? obviously the Python code does not store/remove the config ...
1480 // if, then something like: oFsm.pOnuDB.XyyMe(msgObj)
mpagenko8b07c1b2020-11-26 10:36:31 +00001481
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001482 switch oFsm.pLastTxMeInstance.GetName() {
1483 case "GemInterworkingTerminationPoint":
1484 { // let the FSM proceed ...
1485 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001486 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemGemiwResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001487 }
1488 case "GemPortNetworkCtp":
1489 { // let the FSM proceed ...
1490 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001491 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemGemntpResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001492 }
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001493 case "TrafficDescriptor":
1494 { // let the FSM proceed ...
1495 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001496 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemTdResp)
ozgecanetsiaa88b5ca2021-06-28 21:00:16 +03001497 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001498 case "Ieee8021PMapperServiceProfile":
1499 { // let the FSM proceed ...
1500 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001501 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRem1pMapperResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001502 }
1503 case "MacBridgePortConfigurationData":
1504 { // this is the last event of the T-Cont cleanup procedure, FSM may be reset here
1505 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001506 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxRemAniBPCDResp)
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001507 }
1508 default:
1509 {
1510 oFsm.mutexPLastTxMeInstance.RUnlock()
1511 logger.Warnw(ctx, "Unsupported ME name received!",
1512 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
1513 }
mpagenko8b07c1b2020-11-26 10:36:31 +00001514 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001515 } else {
1516 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko8b07c1b2020-11-26 10:36:31 +00001517 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001518 } else {
1519 oFsm.mutexPLastTxMeInstance.RUnlock()
1520 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID})
mpagenko8b07c1b2020-11-26 10:36:31 +00001521 }
1522}
1523
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001524func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001525 logger.Debugw(ctx, "Rx OMCI UniPonAniConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001526 "msgType": msg.OmciMsg.MessageType})
1527
1528 switch msg.OmciMsg.MessageType {
1529 case omci.CreateResponseType:
1530 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001531 oFsm.handleOmciAniConfigCreateResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301532
mpagenko3dbcdd22020-07-22 07:38:45 +00001533 } //CreateResponseType
1534 case omci.SetResponseType:
1535 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001536 oFsm.handleOmciAniConfigSetResponseMessage(ctx, msg)
mpagenko3dbcdd22020-07-22 07:38:45 +00001537
mpagenko3dbcdd22020-07-22 07:38:45 +00001538 } //SetResponseType
mpagenko8b07c1b2020-11-26 10:36:31 +00001539 case omci.DeleteResponseType:
1540 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001541 oFsm.handleOmciAniConfigDeleteResponseMessage(ctx, msg)
mpagenko8b07c1b2020-11-26 10:36:31 +00001542
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001543 } //DeleteResponseType
mpagenko3dbcdd22020-07-22 07:38:45 +00001544 default:
1545 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001546 logger.Errorw(ctx, "UniPonAniConfigFsm - Rx OMCI unhandled MsgType",
mpagenko01e726e2020-10-23 09:45:29 +00001547 log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001548 return
1549 }
1550 }
1551}
1552
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001553func (oFsm *UniPonAniConfigFsm) performCreatingGemNCTPs(ctx context.Context) {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001554 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
1555 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301556 logger.Info(ctx, "UniPonAniConfigFsm Tx Create::GemNWCtp", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001557 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
1558 "TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001559 "device-id": oFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001560 meParams := me.ParamData{
1561 EntityID: gemPortAttribs.gemPortID, //unique, same as PortId
1562 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001563 me.GemPortNetworkCtp_PortId: gemPortAttribs.gemPortID,
1564 me.GemPortNetworkCtp_TContPointer: oFsm.tcont0ID,
1565 me.GemPortNetworkCtp_Direction: gemPortAttribs.direction,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001566 //ONU-G.TrafficManagementOption dependency ->PrioQueue or TCont
1567 // TODO!! verify dependency and QueueId in case of Multi-GemPort setup!
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001568 me.GemPortNetworkCtp_TrafficManagementPointerForUpstream: gemPortAttribs.upQueueID, //might be different in wrr-only Setup - tcont0ID
1569 me.GemPortNetworkCtp_PriorityQueuePointerForDownStream: gemPortAttribs.downQueueID,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001570 },
1571 }
Holger Hildebrandtc408f492022-07-14 08:39:24 +00001572 if oFsm.techProfileType == cTechProfileTypeXgsPon {
1573 meParams.Attributes[me.GemPortNetworkCtp_EncryptionKeyRing] = GemEncryptKeyRingUnicastDownstreamOnly
1574 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001575 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001576 meInstance, err := oFsm.pOmciCC.SendCreateGemNCTPVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1577 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001578 if err != nil {
1579 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001580 logger.Errorw(ctx, "GemNCTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001581 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001582 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001583 return
1584 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001585 //accept also nil as (error) return value for writing to LastTx
1586 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001587 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001588 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001589 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001590 err = oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001591 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001592 logger.Errorw(ctx, "GemNWCtp create failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001593 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001594 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001595 return
1596 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301597 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemPortNetworkCtpClassID, gemPortAttribs.gemPortID, meParams.Attributes)
Girish Gowdra50e56422021-06-01 16:46:04 -07001598 // Mark the gem port to be added for Performance History monitoring
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001599 OnuMetricsManager := oFsm.pDeviceHandler.GetOnuMetricsManager()
1600 if OnuMetricsManager != nil {
1601 OnuMetricsManager.AddGemPortForPerfMonitoring(ctx, gemPortAttribs.gemPortID)
Girish Gowdra5c5aaf42021-02-17 19:40:50 -08001602 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001603 } //for all GemPorts of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +00001604
1605 // if Config has been done for all GemPort instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001606 logger.Debugw(ctx, "GemNWCtp create loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001607 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxGemntcpsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001608}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001609func (oFsm *UniPonAniConfigFsm) hasMulticastGem(ctx context.Context) bool {
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001610 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
1611 if gemPortAttribs.isMulticast {
1612 logger.Debugw(ctx, "Found multicast gem", log.Fields{"device-id": oFsm.deviceID})
1613 return true
1614 }
1615 }
1616 return false
1617}
mpagenko3dbcdd22020-07-22 07:38:45 +00001618
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001619func (oFsm *UniPonAniConfigFsm) performCreatingGemIWs(ctx context.Context) {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001620 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
1621 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301622 logger.Info(ctx, "UniPonAniConfigFsm Tx Create::GemIwTp", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001623 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
1624 "SPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
mpagenko01e726e2020-10-23 09:45:29 +00001625 "device-id": oFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001626
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301627 var meParams me.ParamData
ozgecanetsia4b232302020-11-11 10:58:10 +03001628 //TODO if the port has only downstream direction the isMulticast flag can be removed.
1629 if gemPortAttribs.isMulticast {
ozgecanetsia4b232302020-11-11 10:58:10 +03001630
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301631 meParams = me.ParamData{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001632 EntityID: gemPortAttribs.multicastGemID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001633 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001634 me.MulticastGemInterworkingTerminationPoint_GemPortNetworkCtpConnectivityPointer: gemPortAttribs.multicastGemID,
1635 me.MulticastGemInterworkingTerminationPoint_InterworkingOption: 0, // Don't Care
1636 me.MulticastGemInterworkingTerminationPoint_ServiceProfilePointer: 0, // Don't Care
1637 me.MulticastGemInterworkingTerminationPoint_GalProfilePointer: cmn.GalEthernetEID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001638 },
1639 }
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03001640 if oFsm.pUniTechProf.multicastConfiguredForOtherUniTps(ctx, oFsm.uniTpKey) {
1641 logger.Debugw(ctx, "MulticastGemInterworkingTP already exist", log.Fields{"device-id": oFsm.deviceID, "multicast-gem-id": gemPortAttribs.multicastGemID})
1642 continue
1643 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001644 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001645 meInstance, err := oFsm.pOmciCC.SendCreateMulticastGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(),
1646 true, oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001647 if err != nil {
1648 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001649 logger.Errorw(ctx, "MulticastGemIWTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001650 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001651 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001652 return
1653
1654 }
ozgecanetsia4b232302020-11-11 10:58:10 +03001655 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001656 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001657 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001658 err = oFsm.waitforOmciResponse(ctx)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001659 if err != nil {
ozgecanetsiab36ed572021-04-01 10:38:48 +03001660 logger.Errorw(ctx, "MulticastGemIWTP create failed, aborting AniConfig FSM!",
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001661 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001662 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001663 return
1664 }
1665 ipv4MulticastTable := make([]uint8, 12)
1666 //Gem Port ID
1667 binary.BigEndian.PutUint16(ipv4MulticastTable[0:], gemPortAttribs.multicastGemID)
1668 //Secondary Key
1669 binary.BigEndian.PutUint16(ipv4MulticastTable[2:], 0)
1670 // Multicast IP range start This is the 224.0.0.1 address
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001671 binary.BigEndian.PutUint32(ipv4MulticastTable[4:], cmn.IPToInt32(net.IPv4(224, 0, 0, 0)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001672 // MulticastIp range stop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001673 binary.BigEndian.PutUint32(ipv4MulticastTable[8:], cmn.IPToInt32(net.IPv4(239, 255, 255, 255)))
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001674
1675 meIPV4MCTableParams := me.ParamData{
1676 EntityID: gemPortAttribs.multicastGemID,
1677 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001678 me.MulticastGemInterworkingTerminationPoint_Ipv4MulticastAddressTable: ipv4MulticastTable,
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001679 },
1680 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001681 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001682 meIPV4MCTableInstance, err := oFsm.pOmciCC.SendSetMulticastGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(),
1683 true, oFsm.PAdaptFsm.CommChan, meIPV4MCTableParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001684 if err != nil {
1685 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001686 logger.Errorw(ctx, "MulticastGemIWTPVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001687 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001688 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001689 return
1690 }
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001691 oFsm.pLastTxMeInstance = meIPV4MCTableInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001692 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia4b232302020-11-11 10:58:10 +03001693
1694 } else {
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301695 meParams = me.ParamData{
ozgecanetsia4b232302020-11-11 10:58:10 +03001696 EntityID: gemPortAttribs.gemPortID,
1697 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001698 me.GemInterworkingTerminationPoint_GemPortNetworkCtpConnectivityPointer: gemPortAttribs.gemPortID, //same as EntityID, see above
1699 me.GemInterworkingTerminationPoint_InterworkingOption: 5, //fixed model:: G.998 .1pMapper
1700 me.GemInterworkingTerminationPoint_ServiceProfilePointer: oFsm.mapperSP0ID,
1701 me.GemInterworkingTerminationPoint_InterworkingTerminationPointPointer: 0, //not used with .1PMapper Mac bridge
1702 me.GemInterworkingTerminationPoint_GalProfilePointer: cmn.GalEthernetEID,
ozgecanetsia4b232302020-11-11 10:58:10 +03001703 },
1704 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001705 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001706 meInstance, err := oFsm.pOmciCC.SendCreateGemIWTPVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1707 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001708 if err != nil {
1709 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001710 logger.Errorw(ctx, "GEMIWTPVar create failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001711 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001712 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001713 return
1714 }
ozgecanetsia4b232302020-11-11 10:58:10 +03001715 //accept also nil as (error) return value for writing to LastTx
1716 // - this avoids misinterpretation of new received OMCI messages
1717 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001718 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsia4b232302020-11-11 10:58:10 +03001719 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001720 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +00001721 err := oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001722 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001723 logger.Errorw(ctx, "GemTP create failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001724 log.Fields{"device-id": oFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001725 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001726 return
1727 }
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301728 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 +05301729 oFsm.pOnuDB.PutOnuSpeficMe(ctx, me.GemInterworkingTerminationPointClassID, gemPortAttribs.gemPortID, meParams.Attributes)
praneeth kumar nalmas3947c582023-12-13 15:38:50 +05301730
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001731 } //for all GemPort's of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +00001732
1733 // if Config has been done for all GemPort instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001734 logger.Debugw(ctx, "GemIwTp create loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001735 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxGemiwsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001736}
1737
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001738func (oFsm *UniPonAniConfigFsm) performSettingPQs(ctx context.Context) {
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001739 //If upstream PQs were set before, then no need to set them again. Let state machine to proceed.
1740 if oFsm.tcontSetBefore {
1741 logger.Debugw(ctx, "No need to set PQs again.", log.Fields{
1742 "device-id": oFsm.deviceID, "tcont": oFsm.alloc0ID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001743 "uni-id": oFsm.pOnuUniPort.UniID,
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001744 "techProfile-id": oFsm.techProfileID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001745 go func(aPAFsm *cmn.AdapterFsm) {
1746 if aPAFsm != nil && aPAFsm.PFsm != nil {
1747 _ = aPAFsm.PFsm.Event(aniEvRxPrioqsResp)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001748 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001749 }(oFsm.PAdaptFsm)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -07001750 return
1751 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001752 const cu16StrictPrioWeight uint16 = 0xFFFF
1753 //find all upstream PrioQueues related to this T-Cont
1754 loQueueMap := ordered_map.NewOrderedMap()
1755 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001756 if gemPortAttribs.isMulticast {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001757 logger.Debugw(ctx, "UniPonAniConfigFsm Port is Multicast, ignoring PQs", log.Fields{
ozgecanetsiab5000ef2020-11-27 14:38:20 +03001758 "device-id": oFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
1759 "prioString": gemPortAttribs.pbitString})
1760 continue
1761 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001762 if gemPortAttribs.qosPolicy == "WRR" {
Himani Chawla4d908332020-08-31 12:30:20 +05301763 if _, ok := loQueueMap.Get(gemPortAttribs.upQueueID); !ok {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001764 //key does not yet exist
1765 loQueueMap.Set(gemPortAttribs.upQueueID, uint16(gemPortAttribs.weight))
1766 }
1767 } else {
1768 loQueueMap.Set(gemPortAttribs.upQueueID, cu16StrictPrioWeight) //use invalid weight value to indicate SP
1769 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001770 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001771
Girish Gowdra09e5f212021-09-30 16:28:36 -07001772 trafficSchedPtrSetSupported := false
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001773 loOnu2g := oFsm.pOnuDB.GetMe(me.Onu2GClassID, cmn.Onu2gMeID)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001774 if loOnu2g == nil {
1775 logger.Errorw(ctx, "onu2g is nil, cannot read qos configuration flexibility parameter",
1776 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001777 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001778 return
1779 }
1780 returnVal := loOnu2g["QualityOfServiceQosConfigurationFlexibility"]
1781 if returnVal != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001782 if qosCfgFlexParam, err := oFsm.pOnuDB.GetUint16Attrib(returnVal); err == nil {
Girish Gowdra09e5f212021-09-30 16:28:36 -07001783 trafficSchedPtrSetSupported = qosCfgFlexParam&bitTrafficSchedulerPtrSetPermitted == bitTrafficSchedulerPtrSetPermitted
1784 logger.Debugw(ctx, "trafficSchedPtrSetSupported set",
1785 log.Fields{"qosCfgFlexParam": qosCfgFlexParam, "trafficSchedPtrSetSupported": trafficSchedPtrSetSupported})
1786 } else {
1787 logger.Errorw(ctx, "Cannot extract qos configuration flexibility parameter",
1788 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001789 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001790 return
1791 }
1792 } else {
1793 logger.Errorw(ctx, "Cannot read qos configuration flexibility parameter",
1794 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001795 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Girish Gowdra09e5f212021-09-30 16:28:36 -07001796 return
1797 }
1798
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001799 //TODO: assumption here is that ONU data uses SP setting in the T-Cont and WRR in the TrafficScheduler
1800 // if that is not the case, the reverse case could be checked and reacted accordingly or if the
1801 // complete chain is not valid, then some error should be thrown and configuration can be aborted
1802 // or even be finished without correct SP/WRR setting
1803
1804 //TODO: search for the (WRR)trafficScheduler related to the T-Cont of this queue
1805 //By now assume fixed value 0x8000, which is the only announce BBSIM TrafficScheduler,
1806 // even though its T-Cont seems to be wrong ...
1807 loTrafficSchedulerEID := 0x8000
1808 //for all found queues
1809 iter := loQueueMap.IterFunc()
1810 for kv, ok := iter(); ok; kv, ok = iter() {
1811 queueIndex := (kv.Key).(uint16)
1812 meParams := me.ParamData{
1813 EntityID: queueIndex,
Himani Chawla4d908332020-08-31 12:30:20 +05301814 Attributes: make(me.AttributeValueMap),
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001815 }
Girish Gowdra09e5f212021-09-30 16:28:36 -07001816 if trafficSchedPtrSetSupported {
1817 if (kv.Value).(uint16) == cu16StrictPrioWeight {
1818 //StrictPrio indication
1819 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio", log.Fields{
1820 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1821 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001822 meParams.Attributes[me.PriorityQueue_TrafficSchedulerPointer] = 0 //ensure T-Cont defined StrictPrio scheduling
Girish Gowdra09e5f212021-09-30 16:28:36 -07001823 } else {
1824 //WRR indication
1825 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to WRR", log.Fields{
1826 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1827 "Weight": kv.Value,
1828 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001829 meParams.Attributes[me.PriorityQueue_TrafficSchedulerPointer] = loTrafficSchedulerEID //ensure assignment of the relevant trafficScheduler
1830 meParams.Attributes[me.PriorityQueue_Weight] = uint8(kv.Value.(uint16))
Girish Gowdra09e5f212021-09-30 16:28:36 -07001831 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001832 } else {
Girish Gowdra09e5f212021-09-30 16:28:36 -07001833 // setting Traffic Scheduler (TS) pointer is not supported unless we point to another TS that points to the same TCONT.
1834 // 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.
1835 // 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.
1836 if (kv.Value).(uint16) == cu16StrictPrioWeight { // SP case, nothing to be done. Proceed to the next queue
1837 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio, traffic sched ptr set unsupported", log.Fields{
1838 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1839 "device-id": oFsm.deviceID})
1840 continue
1841 }
1842 // WRR case, update weight.
1843 logger.Debugw(ctx, "uniPonAniConfigFsm Tx Set::PrioQueue to WRR, traffic sched ptr set unsupported", log.Fields{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001844 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
1845 "Weight": kv.Value,
mpagenko01e726e2020-10-23 09:45:29 +00001846 "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001847 meParams.Attributes[me.PriorityQueue_Weight] = uint8(kv.Value.(uint16))
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001848 }
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001849 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001850 meInstance, err := oFsm.pOmciCC.SendSetPrioQueueVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
1851 oFsm.PAdaptFsm.CommChan, meParams)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001852 if err != nil {
1853 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001854 logger.Errorw(ctx, "PrioQueueVar set failed, aborting UniPonAniConfigFsm!",
ozgecanetsiab36ed572021-04-01 10:38:48 +03001855 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001856 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001857 return
1858 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001859 //accept also nil as (error) return value for writing to LastTx
1860 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +00001861 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt9902b2b2021-04-21 14:52:32 +00001862 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001863
1864 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +03001865 err = oFsm.waitforOmciResponse(ctx)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001866 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001867 logger.Errorw(ctx, "PrioQueue set failed, aborting AniConfig FSM!",
mpagenko01e726e2020-10-23 09:45:29 +00001868 log.Fields{"device-id": oFsm.deviceID, "QueueId": strconv.FormatInt(int64(queueIndex), 16)})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001869 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001870 return
1871 }
1872
1873 //TODO: In case of WRR setting of the GemPort/PrioQueue it might further be necessary to
1874 // write the assigned trafficScheduler with the requested Prio to be considered in the StrictPrio scheduling
1875 // of the (next upstream) assigned T-Cont, which is f(prioQueue[priority]) - in relation to other SP prioQueues
1876 // not yet done because of BBSIM TrafficScheduler issues (and not done in py code as well)
1877
1878 } //for all upstream prioQueues
mpagenko3dbcdd22020-07-22 07:38:45 +00001879
1880 // if Config has been done for all PrioQueue instances let the FSM proceed
dbainbri4d3a0dc2020-12-02 00:33:42 +00001881 logger.Debugw(ctx, "PrioQueue set loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001882 _ = oFsm.PAdaptFsm.PFsm.Event(aniEvRxPrioqsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +00001883}
1884
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001885func (oFsm *UniPonAniConfigFsm) waitforOmciResponse(ctx context.Context) error {
mpagenko7d6bb022021-03-11 15:07:55 +00001886 oFsm.mutexIsAwaitingResponse.Lock()
mpagenkocf48e452021-04-23 09:23:00 +00001887 if oFsm.isCanceled {
1888 // FSM already canceled before entering wait
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001889 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 +00001890 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001891 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenkocf48e452021-04-23 09:23:00 +00001892 }
mpagenko7d6bb022021-03-11 15:07:55 +00001893 oFsm.isAwaitingResponse = true
1894 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko3dbcdd22020-07-22 07:38:45 +00001895 select {
Himani Chawla4d908332020-08-31 12:30:20 +05301896 // maybe be also some outside cancel (but no context modeled for the moment ...)
mpagenko3dbcdd22020-07-22 07:38:45 +00001897 // case <-ctx.Done():
mpagenko01e726e2020-10-23 09:45:29 +00001898 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +00001899 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 +00001900 logger.Warnw(ctx, "UniPonAniConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001901 oFsm.mutexIsAwaitingResponse.Lock()
1902 oFsm.isAwaitingResponse = false
1903 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt7e138462023-03-29 12:12:14 +00001904 oFsm.mutexPLastTxMeInstance.RLock()
1905 if oFsm.pLastTxMeInstance != nil {
1906 oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureTimeout, oFsm.pLastTxMeInstance.GetClassID(),
1907 oFsm.pLastTxMeInstance.GetEntityID(), oFsm.pLastTxMeInstance.GetClassID().String(), 0)
1908 }
1909 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenko01e726e2020-10-23 09:45:29 +00001910 return fmt.Errorf("uniPonAniConfigFsm multi entity timeout %s", oFsm.deviceID)
mpagenko3dbcdd22020-07-22 07:38:45 +00001911 case success := <-oFsm.omciMIdsResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +05301912 if success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001913 logger.Debugw(ctx, "UniPonAniConfigFsm multi entity response received", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001914 oFsm.mutexIsAwaitingResponse.Lock()
1915 oFsm.isAwaitingResponse = false
1916 oFsm.mutexIsAwaitingResponse.Unlock()
mpagenko3dbcdd22020-07-22 07:38:45 +00001917 return nil
1918 }
mpagenko7d6bb022021-03-11 15:07:55 +00001919 // waiting was aborted (probably on external request)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001920 logger.Debugw(ctx, "UniPonAniConfigFsm wait-for-multi-entity-response aborted", log.Fields{"for device-id": oFsm.deviceID})
mpagenko7d6bb022021-03-11 15:07:55 +00001921 oFsm.mutexIsAwaitingResponse.Lock()
1922 oFsm.isAwaitingResponse = false
1923 oFsm.mutexIsAwaitingResponse.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001924 return fmt.Errorf(cmn.CErrWaitAborted)
mpagenko3dbcdd22020-07-22 07:38:45 +00001925 }
1926}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001927
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001928func (oFsm *UniPonAniConfigFsm) setChanSet(flagValue bool) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001929 oFsm.mutexChanSet.Lock()
1930 oFsm.chanSet = flagValue
1931 oFsm.mutexChanSet.Unlock()
1932}
1933
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001934func (oFsm *UniPonAniConfigFsm) isChanSet() bool {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001935 oFsm.mutexChanSet.RLock()
1936 flagValue := oFsm.chanSet
1937 oFsm.mutexChanSet.RUnlock()
1938 return flagValue
1939}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001940
1941// PrepareForGarbageCollection - remove references to prepare for garbage collection
1942func (oFsm *UniPonAniConfigFsm) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301943 logger.Info(ctx, "prepare for garbage collection", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001944 oFsm.pDeviceHandler = nil
1945 oFsm.pOnuDeviceEntry = nil
1946 oFsm.pOmciCC = nil
1947}