blob: c4bc2351e52090c65bf01db90cf6ee4c8faaa1a9 [file] [log] [blame]
mpagenko3dbcdd22020-07-22 07:38:45 +00001/*
2 * Copyright 2020-present Open Networking Foundation
3 *
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
17//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
19
20import (
21 "context"
22 "errors"
23 "strconv"
24 "time"
25
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000026 "github.com/cevaris/ordered_map"
mpagenko3dbcdd22020-07-22 07:38:45 +000027 "github.com/looplab/fsm"
mpagenko3dbcdd22020-07-22 07:38:45 +000028 "github.com/opencord/omci-lib-go"
29 me "github.com/opencord/omci-lib-go/generated"
30 "github.com/opencord/voltha-lib-go/v3/pkg/log"
31 //ic "github.com/opencord/voltha-protos/v3/go/inter_container"
32 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
33 //"github.com/opencord/voltha-protos/v3/go/voltha"
34)
35
mpagenko1cc3cb42020-07-27 15:24:38 +000036const (
37 // events of config PON ANI port FSM
38 aniEvStart = "uniEvStart"
39 aniEvStartConfig = "aniEvStartConfig"
40 aniEvRxDot1pmapCresp = "aniEvRxDot1pmapCresp"
41 aniEvRxMbpcdResp = "aniEvRxMbpcdResp"
42 aniEvRxTcontsResp = "aniEvRxTcontsResp"
43 aniEvRxGemntcpsResp = "aniEvRxGemntcpsResp"
44 aniEvRxGemiwsResp = "aniEvRxGemiwsResp"
45 aniEvRxPrioqsResp = "aniEvRxPrioqsResp"
46 aniEvRxDot1pmapSresp = "aniEvRxDot1pmapSresp"
47 aniEvTimeoutSimple = "aniEvTimeoutSimple"
48 aniEvTimeoutMids = "aniEvTimeoutMids"
49 aniEvReset = "aniEvReset"
50 aniEvRestart = "aniEvRestart"
51)
52const (
53 // states of config PON ANI port FSM
54 aniStDisabled = "aniStDisabled"
55 aniStStarting = "aniStStarting"
56 aniStCreatingDot1PMapper = "aniStCreatingDot1PMapper"
57 aniStCreatingMBPCD = "aniStCreatingMBPCD"
58 aniStSettingTconts = "aniStSettingTconts"
59 aniStCreatingGemNCTPs = "aniStCreatingGemNCTPs"
60 aniStCreatingGemIWs = "aniStCreatingGemIWs"
61 aniStSettingPQs = "aniStSettingPQs"
62 aniStSettingDot1PMapper = "aniStSettingDot1PMapper"
63 aniStConfigDone = "aniStConfigDone"
64 aniStResetting = "aniStResetting"
65)
66
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000067type ponAniGemPortAttribs struct {
68 gemPortID uint16
69 upQueueID uint16
70 downQueueID uint16
71 direction uint8
72 qosPolicy string
73 weight uint8
74 pbitString string
75}
76
mpagenko1cc3cb42020-07-27 15:24:38 +000077//UniPonAniConfigFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI
mpagenko3dbcdd22020-07-22 07:38:45 +000078type UniPonAniConfigFsm struct {
79 pOmciCC *OmciCC
80 pOnuUniPort *OnuUniPort
81 pUniTechProf *OnuUniTechProf
82 pOnuDB *OnuDeviceDB
83 techProfileID uint16
84 requestEvent OnuDeviceEvent
85 omciMIdsResponseReceived chan bool //seperate channel needed for checking multiInstance OMCI message responses
86 pAdaptFsm *AdapterFsm
mpagenko1cc3cb42020-07-27 15:24:38 +000087 aniConfigCompleted bool
mpagenko3dbcdd22020-07-22 07:38:45 +000088 chSuccess chan<- uint8
89 procStep uint8
90 chanSet bool
91 mapperSP0ID uint16
92 macBPCD0ID uint16
93 tcont0ID uint16
94 alloc0ID uint16
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000095 gemPortAttribsSlice []ponAniGemPortAttribs
mpagenko3dbcdd22020-07-22 07:38:45 +000096}
97
mpagenko1cc3cb42020-07-27 15:24:38 +000098//NewUniPonAniConfigFsm is the 'constructor' for the state machine to config the PON ANI ports of ONU UNI ports via OMCI
mpagenko3dbcdd22020-07-22 07:38:45 +000099func NewUniPonAniConfigFsm(apDevOmciCC *OmciCC, apUniPort *OnuUniPort, apUniTechProf *OnuUniTechProf,
100 apOnuDB *OnuDeviceDB, aTechProfileID uint16, aRequestEvent OnuDeviceEvent, aName string,
101 aDeviceID string, aCommChannel chan Message) *UniPonAniConfigFsm {
102 instFsm := &UniPonAniConfigFsm{
mpagenko1cc3cb42020-07-27 15:24:38 +0000103 pOmciCC: apDevOmciCC,
104 pOnuUniPort: apUniPort,
105 pUniTechProf: apUniTechProf,
106 pOnuDB: apOnuDB,
107 techProfileID: aTechProfileID,
108 requestEvent: aRequestEvent,
109 aniConfigCompleted: false,
110 chanSet: false,
mpagenko3dbcdd22020-07-22 07:38:45 +0000111 }
112 instFsm.pAdaptFsm = NewAdapterFsm(aName, aDeviceID, aCommChannel)
113 if instFsm.pAdaptFsm == nil {
114 logger.Errorw("UniPonAniConfigFsm's AdapterFsm could not be instantiated!!", log.Fields{
115 "device-id": aDeviceID})
116 return nil
117 }
118
119 instFsm.pAdaptFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000120 aniStDisabled,
mpagenko3dbcdd22020-07-22 07:38:45 +0000121 fsm.Events{
122
mpagenko1cc3cb42020-07-27 15:24:38 +0000123 {Name: aniEvStart, Src: []string{aniStDisabled}, Dst: aniStStarting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000124
125 //Note: .1p-Mapper and MBPCD might also have multi instances (per T-Cont) - by now only one 1 T-Cont considered!
mpagenko1cc3cb42020-07-27 15:24:38 +0000126 {Name: aniEvStartConfig, Src: []string{aniStStarting}, Dst: aniStCreatingDot1PMapper},
127 {Name: aniEvRxDot1pmapCresp, Src: []string{aniStCreatingDot1PMapper}, Dst: aniStCreatingMBPCD},
128 {Name: aniEvRxMbpcdResp, Src: []string{aniStCreatingMBPCD}, Dst: aniStSettingTconts},
129 {Name: aniEvRxTcontsResp, Src: []string{aniStSettingTconts}, Dst: aniStCreatingGemNCTPs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000130 // the creatingGemNCTPs state is used for multi ME config if required for all configured/available GemPorts
mpagenko1cc3cb42020-07-27 15:24:38 +0000131 {Name: aniEvRxGemntcpsResp, Src: []string{aniStCreatingGemNCTPs}, Dst: aniStCreatingGemIWs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000132 // the creatingGemIWs state is used for multi ME config if required for all configured/available GemPorts
mpagenko1cc3cb42020-07-27 15:24:38 +0000133 {Name: aniEvRxGemiwsResp, Src: []string{aniStCreatingGemIWs}, Dst: aniStSettingPQs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000134 // the settingPQs state is used for multi ME config if required for all configured/available upstream PriorityQueues
mpagenko1cc3cb42020-07-27 15:24:38 +0000135 {Name: aniEvRxPrioqsResp, Src: []string{aniStSettingPQs}, Dst: aniStSettingDot1PMapper},
136 {Name: aniEvRxDot1pmapSresp, Src: []string{aniStSettingDot1PMapper}, Dst: aniStConfigDone},
mpagenko3dbcdd22020-07-22 07:38:45 +0000137
mpagenko1cc3cb42020-07-27 15:24:38 +0000138 {Name: aniEvTimeoutSimple, Src: []string{
139 aniStCreatingDot1PMapper, aniStCreatingMBPCD, aniStSettingTconts, aniStSettingDot1PMapper}, Dst: aniStStarting},
140 {Name: aniEvTimeoutMids, Src: []string{
141 aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs}, Dst: aniStStarting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000142
mpagenko1cc3cb42020-07-27 15:24:38 +0000143 // exceptional treatment for all states except aniStResetting
144 {Name: aniEvReset, Src: []string{aniStStarting, aniStCreatingDot1PMapper, aniStCreatingMBPCD,
145 aniStSettingTconts, aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs, aniStSettingDot1PMapper,
146 aniStConfigDone}, Dst: aniStResetting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000147 // the only way to get to resource-cleared disabled state again is via "resseting"
mpagenko1cc3cb42020-07-27 15:24:38 +0000148 {Name: aniEvRestart, Src: []string{aniStResetting}, Dst: aniStDisabled},
mpagenko3dbcdd22020-07-22 07:38:45 +0000149 },
150
151 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000152 "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) },
153 ("enter_" + aniStStarting): func(e *fsm.Event) { instFsm.enterConfigStartingState(e) },
154 ("enter_" + aniStCreatingDot1PMapper): func(e *fsm.Event) { instFsm.enterCreatingDot1PMapper(e) },
155 ("enter_" + aniStCreatingMBPCD): func(e *fsm.Event) { instFsm.enterCreatingMBPCD(e) },
156 ("enter_" + aniStSettingTconts): func(e *fsm.Event) { instFsm.enterSettingTconts(e) },
157 ("enter_" + aniStCreatingGemNCTPs): func(e *fsm.Event) { instFsm.enterCreatingGemNCTPs(e) },
158 ("enter_" + aniStCreatingGemIWs): func(e *fsm.Event) { instFsm.enterCreatingGemIWs(e) },
159 ("enter_" + aniStSettingPQs): func(e *fsm.Event) { instFsm.enterSettingPQs(e) },
160 ("enter_" + aniStSettingDot1PMapper): func(e *fsm.Event) { instFsm.enterSettingDot1PMapper(e) },
161 ("enter_" + aniStConfigDone): func(e *fsm.Event) { instFsm.enterAniConfigDone(e) },
162 ("enter_" + aniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(e) },
163 ("enter_" + aniStDisabled): func(e *fsm.Event) { instFsm.enterDisabledState(e) },
mpagenko3dbcdd22020-07-22 07:38:45 +0000164 },
165 )
166 if instFsm.pAdaptFsm.pFsm == nil {
167 logger.Errorw("UniPonAniConfigFsm's Base FSM could not be instantiated!!", log.Fields{
168 "device-id": aDeviceID})
169 return nil
170 }
171
172 logger.Infow("UniPonAniConfigFsm created", log.Fields{"device-id": aDeviceID})
173 return instFsm
174}
175
176//SetFsmCompleteChannel sets the requested channel and channel result for transfer on success
177func (oFsm *UniPonAniConfigFsm) SetFsmCompleteChannel(aChSuccess chan<- uint8, aProcStep uint8) {
178 oFsm.chSuccess = aChSuccess
179 oFsm.procStep = aProcStep
180 oFsm.chanSet = true
181}
182
183func (oFsm *UniPonAniConfigFsm) enterConfigStartingState(e *fsm.Event) {
184 logger.Debugw("UniPonAniConfigFsm start", log.Fields{"in state": e.FSM.Current(),
185 "device-id": oFsm.pAdaptFsm.deviceID})
186 // in case the used channel is not yet defined (can be re-used after restarts)
187 if oFsm.omciMIdsResponseReceived == nil {
188 oFsm.omciMIdsResponseReceived = make(chan bool)
189 logger.Debug("UniPonAniConfigFsm - OMCI multiInstance RxChannel defined")
190 } else {
191 // as we may 're-use' this instance of FSM and the connected channel
192 // make sure there is no 'lingering' request in the already existing channel:
193 // (simple loop sufficient as we are the only receiver)
194 for len(oFsm.omciMIdsResponseReceived) > 0 {
195 <-oFsm.omciMIdsResponseReceived
196 }
197 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000198 //ensure internal slices are empty (which might be set from previous run) - release memory
199 oFsm.gemPortAttribsSlice = nil
200
mpagenko3dbcdd22020-07-22 07:38:45 +0000201 // start go routine for processing of LockState messages
202 go oFsm.ProcessOmciAniMessages()
203
204 //let the state machine run forward from here directly
205 pConfigAniStateAFsm := oFsm.pAdaptFsm
206 if pConfigAniStateAFsm != nil {
207 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
208 go func(a_pAFsm *AdapterFsm) {
209 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
210 //stick to pythonAdapter numbering scheme
211 //index 0 in naming refers to possible usage of multiple instances (later)
212 oFsm.mapperSP0ID = ieeeMapperServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo) + oFsm.techProfileID
213 oFsm.macBPCD0ID = macBridgePortAniEID + uint16(oFsm.pOnuUniPort.entityId) + oFsm.techProfileID
mpagenko3dbcdd22020-07-22 07:38:45 +0000214
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000215 // For the time beeing: if there are multiple T-Conts on the ONU the first one from the entityID-ordered list is used
216 // TODO!: if more T-Conts have to be supported (tcontXID!), then use the first instances of the entity-ordered list
217 // or use the py code approach, which might be a bit more complicated, but also more secure, as it
218 // ensures that the selected T-Cont also has queues (which I would assume per definition from ONU, but who knows ...)
219 // so this approach would search the (sorted) upstream PrioQueue list and use the T-Cont (if available) from highest Bytes
220 // or sndHighByte of relatedPort Attribute (T-Cont Reference) and in case of multiple TConts find the next free TContIndex
221 // that way from PrioQueue.relatedPort list
222 if tcontInstKeys := oFsm.pOnuDB.GetSortedInstKeys(me.TContClassID); len(tcontInstKeys) > 0 {
223 oFsm.tcont0ID = tcontInstKeys[0]
224 logger.Debugw("Used TcontId:", log.Fields{"TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
225 "device-id": oFsm.pAdaptFsm.deviceID})
226 } else {
227 logger.Warnw("No TCont instances found", log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID})
228 }
229 oFsm.alloc0ID = (*(oFsm.pUniTechProf.mapPonAniConfig[uint32(oFsm.pOnuUniPort.uniId)]))[0].tcontParams.allocID
230 loGemPortAttribs := ponAniGemPortAttribs{}
231 //for all TechProfile set GemIndices
232 for _, gemEntry := range (*(oFsm.pUniTechProf.mapPonAniConfig[uint32(oFsm.pOnuUniPort.uniId)]))[0].mapGemPortParams {
233 //collect all GemConfigData in a seperate Fsm related slice (needed also to avoid mix-up with unsorted mapPonAniConfig)
234
235 if queueInstKeys := oFsm.pOnuDB.GetSortedInstKeys(me.PriorityQueueClassID); len(queueInstKeys) > 0 {
236
237 loGemPortAttribs.gemPortID = gemEntry.gemPortID
238 // MibDb usage: upstream PrioQueue.RelatedPort = xxxxyyyy with xxxx=TCont.Entity(incl. slot) and yyyy=prio
239 // i.e.: search PrioQueue list with xxxx=actual T-Cont.Entity,
240 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == yyyy (expect 0..7)
241 usQrelPortMask := uint32((((uint32)(oFsm.tcont0ID)) << 16) + uint32(gemEntry.prioQueueIndex))
242
243 // MibDb usage: downstream PrioQueue.RelatedPort = xxyyzzzz with xx=slot, yy=UniPort and zzzz=prio
244 // i.e.: search PrioQueue list with yy=actual pOnuUniPort.uniId,
245 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == zzzz (expect 0..7)
246 // Note: As we do not maintain any slot numbering, slot number will be excluded from seatch pattern.
247 // Furthermore OMCI Onu port-Id is expected to start with 1 (not 0).
248 dsQrelPortMask := uint32((((uint32)(oFsm.pOnuUniPort.uniId + 1)) << 16) + uint32(gemEntry.prioQueueIndex))
249
250 usQueueFound := false
251 dsQueueFound := false
252 for _, mgmtEntityId := range queueInstKeys {
253 if meAttributes := oFsm.pOnuDB.GetMe(me.PriorityQueueClassID, mgmtEntityId); meAttributes != nil {
254 returnVal := meAttributes["RelatedPort"]
255 if returnVal != nil {
256 relatedPort := returnVal.(uint32)
257 if relatedPort == usQrelPortMask {
258 loGemPortAttribs.upQueueID = mgmtEntityId
259 logger.Debugw("UpQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
260 "upQueueID": strconv.FormatInt(int64(loGemPortAttribs.upQueueID), 16), "deviceId": oFsm.pAdaptFsm.deviceID})
261 usQueueFound = true
262 } else if (relatedPort&0xFFFFFF) == dsQrelPortMask && mgmtEntityId < 0x8000 {
263 loGemPortAttribs.downQueueID = mgmtEntityId
264 logger.Debugw("DownQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
265 "downQueueID": strconv.FormatInt(int64(loGemPortAttribs.downQueueID), 16), "deviceId": oFsm.pAdaptFsm.deviceID})
266 dsQueueFound = true
267 }
268 if usQueueFound && dsQueueFound {
269 break
270 }
271 } else {
272 logger.Warnw("'relatedPort' not found in meAttributes:", log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID})
273 }
274 } else {
275 logger.Warnw("No attributes available in DB:", log.Fields{"meClassID": me.PriorityQueueClassID,
276 "mgmtEntityId": mgmtEntityId, "deviceId": oFsm.pAdaptFsm.deviceID})
277 }
278 }
279 } else {
280 logger.Warnw("No PriorityQueue instances found", log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID})
281 }
282 loGemPortAttribs.direction = gemEntry.direction
283 loGemPortAttribs.qosPolicy = gemEntry.queueSchedPolicy
284 loGemPortAttribs.weight = gemEntry.queueWeight
285 loGemPortAttribs.pbitString = gemEntry.pbitString
286
287 logger.Debugw("prio-related GemPort attributes assigned:", log.Fields{
288 "gemPortID": loGemPortAttribs.gemPortID,
289 "upQueueID": loGemPortAttribs.upQueueID,
290 "downQueueID": loGemPortAttribs.downQueueID,
291 "pbitString": loGemPortAttribs.pbitString,
292 })
293
294 oFsm.gemPortAttribsSlice = append(oFsm.gemPortAttribsSlice, loGemPortAttribs)
295 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000296 a_pAFsm.pFsm.Event(aniEvStartConfig)
mpagenko3dbcdd22020-07-22 07:38:45 +0000297 }
298 }(pConfigAniStateAFsm)
299 }
300}
301
302func (oFsm *UniPonAniConfigFsm) enterCreatingDot1PMapper(e *fsm.Event) {
303 logger.Debugw("UniPonAniConfigFsm Tx Create::Dot1PMapper", log.Fields{
304 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
305 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
306 meInstance := oFsm.pOmciCC.sendCreateDot1PMapper(context.TODO(), ConstDefaultOmciTimeout, true,
307 oFsm.mapperSP0ID, oFsm.pAdaptFsm.commChan)
308 //accept also nil as (error) return value for writing to LastTx
309 // - this avoids misinterpretation of new received OMCI messages
310 oFsm.pOmciCC.pLastTxMeInstance = meInstance
311}
312
313func (oFsm *UniPonAniConfigFsm) enterCreatingMBPCD(e *fsm.Event) {
314 logger.Debugw("UniPonAniConfigFsm Tx Create::MBPCD", log.Fields{
315 "EntitytId": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16),
316 "TPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
317 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
318 bridgePtr := macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo) //cmp also omci_cc.go::sendCreateMBServiceProfile
319 meParams := me.ParamData{
320 EntityID: oFsm.macBPCD0ID,
321 Attributes: me.AttributeValueMap{
322 "BridgeIdPointer": bridgePtr,
323 "PortNum": 0xFF, //fixed unique ANI side indication
324 "TpType": 3, //for .1PMapper
325 "TpPointer": oFsm.mapperSP0ID,
326 },
327 }
328 meInstance := oFsm.pOmciCC.sendCreateMBPConfigDataVar(context.TODO(), ConstDefaultOmciTimeout, true,
329 oFsm.pAdaptFsm.commChan, meParams)
330 //accept also nil as (error) return value for writing to LastTx
331 // - this avoids misinterpretation of new received OMCI messages
332 oFsm.pOmciCC.pLastTxMeInstance = meInstance
333
334}
335
336func (oFsm *UniPonAniConfigFsm) enterSettingTconts(e *fsm.Event) {
337 logger.Debugw("UniPonAniConfigFsm Tx Set::Tcont", log.Fields{
338 "EntitytId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
339 "AllocId": strconv.FormatInt(int64(oFsm.alloc0ID), 16),
340 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
341 meParams := me.ParamData{
342 EntityID: oFsm.tcont0ID,
343 Attributes: me.AttributeValueMap{
344 "AllocId": oFsm.alloc0ID,
345 },
346 }
347 meInstance := oFsm.pOmciCC.sendSetTcontVar(context.TODO(), ConstDefaultOmciTimeout, true,
348 oFsm.pAdaptFsm.commChan, meParams)
349 //accept also nil as (error) return value for writing to LastTx
350 // - this avoids misinterpretation of new received OMCI messages
351 oFsm.pOmciCC.pLastTxMeInstance = meInstance
352}
353
354func (oFsm *UniPonAniConfigFsm) enterCreatingGemNCTPs(e *fsm.Event) {
355 //TODO!! this is just for the first GemPort right now - needs update
356 logger.Debugw("UniPonAniConfigFsm - start creating GemNWCtp loop", log.Fields{
357 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
358 go oFsm.performCreatingGemNCTPs()
359}
360
361func (oFsm *UniPonAniConfigFsm) enterCreatingGemIWs(e *fsm.Event) {
362 logger.Debugw("UniPonAniConfigFsm - start creating GemIwTP loop", log.Fields{
363 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
364 go oFsm.performCreatingGemIWs()
365}
366
367func (oFsm *UniPonAniConfigFsm) enterSettingPQs(e *fsm.Event) {
368 logger.Debugw("UniPonAniConfigFsm - start setting PrioQueue loop", log.Fields{
369 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
370 go oFsm.performSettingPQs()
371}
372
373func (oFsm *UniPonAniConfigFsm) enterSettingDot1PMapper(e *fsm.Event) {
374 logger.Debugw("UniPonAniConfigFsm Tx Set::.1pMapper with all PBits set", log.Fields{"EntitytId": 0x8042, /*cmp above*/
375 "toGemIw": 1024 /* cmp above */, "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
376
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000377 logger.Debugw("UniPonAniConfigFsm Tx Set::1pMapper", log.Fields{
378 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
379 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
380
mpagenko3dbcdd22020-07-22 07:38:45 +0000381 meParams := me.ParamData{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000382 EntityID: oFsm.mapperSP0ID,
383 Attributes: make(me.AttributeValueMap, 0),
mpagenko3dbcdd22020-07-22 07:38:45 +0000384 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000385
386 //assign the GemPorts according to the configured Prio
387 var loPrioGemPortArray [8]uint16
388 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
389 for i := 0; i < 8; i++ {
390 // "lenOfPbitMap(8) - i + 1" will give i-th pbit value from LSB position in the pbit map string
391 if prio, err := strconv.Atoi(string(gemPortAttribs.pbitString[7-i])); err == nil {
392 if prio == 1 { // Check this p-bit is set
393 if loPrioGemPortArray[i] == 0 {
394 loPrioGemPortArray[i] = gemPortAttribs.gemPortID //gemPortId=EntityID and unique
395 } else {
396 logger.Warnw("UniPonAniConfigFsm PrioString not unique", log.Fields{
397 "device-id": oFsm.pAdaptFsm.deviceID, "IgnoredGemPort": gemPortAttribs.gemPortID,
398 "SetGemPort": loPrioGemPortArray[i]})
399 }
400 }
401 } else {
402 logger.Warnw("UniPonAniConfigFsm PrioString evaluation error", log.Fields{
403 "device-id": oFsm.pAdaptFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
404 "prioString": gemPortAttribs.pbitString, "position": i})
405 }
406
407 }
408 }
409 var foundIwPtr bool = false
410 if loPrioGemPortArray[0] != 0 {
411 foundIwPtr = true
412 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
413 "IwPtr for Prio0": strconv.FormatInt(int64(loPrioGemPortArray[0]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
414 meParams.Attributes["InterworkTpPointerForPBitPriority0"] = loPrioGemPortArray[0]
415 }
416 if loPrioGemPortArray[1] != 0 {
417 foundIwPtr = true
418 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
419 "IwPtr for Prio1": strconv.FormatInt(int64(loPrioGemPortArray[1]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
420 meParams.Attributes["InterworkTpPointerForPBitPriority1"] = loPrioGemPortArray[1]
421 }
422 if loPrioGemPortArray[2] != 0 {
423 foundIwPtr = true
424 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
425 "IwPtr for Prio2": strconv.FormatInt(int64(loPrioGemPortArray[2]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
426 meParams.Attributes["InterworkTpPointerForPBitPriority2"] = loPrioGemPortArray[2]
427 }
428 if loPrioGemPortArray[3] != 0 {
429 foundIwPtr = true
430 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
431 "IwPtr for Prio3": strconv.FormatInt(int64(loPrioGemPortArray[3]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
432 meParams.Attributes["InterworkTpPointerForPBitPriority3"] = loPrioGemPortArray[3]
433 }
434 if loPrioGemPortArray[4] != 0 {
435 foundIwPtr = true
436 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
437 "IwPtr for Prio4": strconv.FormatInt(int64(loPrioGemPortArray[4]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
438 meParams.Attributes["InterworkTpPointerForPBitPriority4"] = loPrioGemPortArray[4]
439 }
440 if loPrioGemPortArray[5] != 0 {
441 foundIwPtr = true
442 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
443 "IwPtr for Prio5": strconv.FormatInt(int64(loPrioGemPortArray[5]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
444 meParams.Attributes["InterworkTpPointerForPBitPriority5"] = loPrioGemPortArray[5]
445 }
446 if loPrioGemPortArray[6] != 0 {
447 foundIwPtr = true
448 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
449 "IwPtr for Prio6": strconv.FormatInt(int64(loPrioGemPortArray[6]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
450 meParams.Attributes["InterworkTpPointerForPBitPriority6"] = loPrioGemPortArray[6]
451 }
452 if loPrioGemPortArray[7] != 0 {
453 foundIwPtr = true
454 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
455 "IwPtr for Prio7": strconv.FormatInt(int64(loPrioGemPortArray[7]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
456 meParams.Attributes["InterworkTpPointerForPBitPriority7"] = loPrioGemPortArray[7]
457 }
458 if foundIwPtr == false {
459 logger.Errorw("UniPonAniConfigFsm no GemIwPtr found for .1pMapper - abort", log.Fields{
460 "device-id": oFsm.pAdaptFsm.deviceID})
461 //let's reset the state machine in order to release all resources now
462 pConfigAniStateAFsm := oFsm.pAdaptFsm
463 if pConfigAniStateAFsm != nil {
464 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
465 go func(a_pAFsm *AdapterFsm) {
466 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
467 a_pAFsm.pFsm.Event(aniEvReset)
468 }
469 }(pConfigAniStateAFsm)
470 }
471 }
472
mpagenko3dbcdd22020-07-22 07:38:45 +0000473 meInstance := oFsm.pOmciCC.sendSetDot1PMapperVar(context.TODO(), ConstDefaultOmciTimeout, true,
474 oFsm.pAdaptFsm.commChan, meParams)
475 //accept also nil as (error) return value for writing to LastTx
476 // - this avoids misinterpretation of new received OMCI messages
477 oFsm.pOmciCC.pLastTxMeInstance = meInstance
478}
479
480func (oFsm *UniPonAniConfigFsm) enterAniConfigDone(e *fsm.Event) {
481
mpagenko1cc3cb42020-07-27 15:24:38 +0000482 oFsm.aniConfigCompleted = true
mpagenko3dbcdd22020-07-22 07:38:45 +0000483
484 //let's reset the state machine in order to release all resources now
485 pConfigAniStateAFsm := oFsm.pAdaptFsm
486 if pConfigAniStateAFsm != nil {
487 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
488 go func(a_pAFsm *AdapterFsm) {
489 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000490 a_pAFsm.pFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +0000491 }
492 }(pConfigAniStateAFsm)
493 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000494}
495
496func (oFsm *UniPonAniConfigFsm) enterResettingState(e *fsm.Event) {
497 logger.Debugw("UniPonAniConfigFsm resetting", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000498
mpagenko3dbcdd22020-07-22 07:38:45 +0000499 pConfigAniStateAFsm := oFsm.pAdaptFsm
500 if pConfigAniStateAFsm != nil {
501 // abort running message processing
502 fsmAbortMsg := Message{
503 Type: TestMsg,
504 Data: TestMessage{
505 TestMessageVal: AbortMessageProcessing,
506 },
507 }
508 pConfigAniStateAFsm.commChan <- fsmAbortMsg
509
510 //try to restart the FSM to 'disabled', decouple event transfer
511 go func(a_pAFsm *AdapterFsm) {
512 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000513 a_pAFsm.pFsm.Event(aniEvRestart)
mpagenko3dbcdd22020-07-22 07:38:45 +0000514 }
515 }(pConfigAniStateAFsm)
516 }
517}
518
mpagenko1cc3cb42020-07-27 15:24:38 +0000519func (oFsm *UniPonAniConfigFsm) enterDisabledState(e *fsm.Event) {
520 logger.Debugw("UniPonAniConfigFsm enters disabled state", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
521
522 if oFsm.aniConfigCompleted {
523 logger.Debugw("UniPonAniConfigFsm send dh event notification", log.Fields{
524 "from_State": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
525 //use DeviceHandler event notification directly
526 oFsm.pOmciCC.pBaseDeviceHandler.DeviceProcStatusUpdate(oFsm.requestEvent)
527 oFsm.aniConfigCompleted = false
528 }
529
530 if oFsm.chanSet {
531 // indicate processing done to the caller
532 logger.Debugw("UniPonAniConfigFsm processingDone on channel", log.Fields{
533 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
534 oFsm.chSuccess <- oFsm.procStep
535 oFsm.chanSet = false //reset the internal channel state
536 }
537
538}
539
mpagenko3dbcdd22020-07-22 07:38:45 +0000540func (oFsm *UniPonAniConfigFsm) ProcessOmciAniMessages( /*ctx context.Context*/ ) {
541 logger.Debugw("Start UniPonAniConfigFsm Msg processing", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
542loop:
543 for {
544 select {
545 // case <-ctx.Done():
546 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.pAdaptFsm.deviceID})
547 // break loop
548 case message, ok := <-oFsm.pAdaptFsm.commChan:
549 if !ok {
550 logger.Info("UniPonAniConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
551 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
mpagenko1cc3cb42020-07-27 15:24:38 +0000552 oFsm.pAdaptFsm.pFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +0000553 break loop
554 }
555 logger.Debugw("UniPonAniConfigFsm Rx Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
556
557 switch message.Type {
558 case TestMsg:
559 msg, _ := message.Data.(TestMessage)
560 if msg.TestMessageVal == AbortMessageProcessing {
561 logger.Infow("UniPonAniConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
562 break loop
563 }
564 logger.Warnw("UniPonAniConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "MessageVal": msg.TestMessageVal})
565 case OMCI:
566 msg, _ := message.Data.(OmciMessage)
567 oFsm.handleOmciAniConfigMessage(msg)
568 default:
569 logger.Warn("UniPonAniConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID,
570 "message.Type": message.Type})
571 }
572 }
573 }
574 logger.Infow("End UniPonAniConfigFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
575}
576
577func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigMessage(msg OmciMessage) {
578 logger.Debugw("Rx OMCI UniPonAniConfigFsm Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID,
579 "msgType": msg.OmciMsg.MessageType})
580
581 switch msg.OmciMsg.MessageType {
582 case omci.CreateResponseType:
583 {
584 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse)
585 if msgLayer == nil {
586 logger.Error("Omci Msg layer could not be detected for CreateResponse")
587 return
588 }
589 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
590 if !msgOk {
591 logger.Error("Omci Msg layer could not be assigned for CreateResponse")
592 return
593 }
594 logger.Debugw("CreateResponse Data", log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj})
595 if msgObj.Result != me.Success {
596 logger.Errorw("Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result})
597 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
598 return
599 }
600 if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() &&
601 msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() {
602 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
603 // if, then something like:
604 //oFsm.pOnuDB.StoreMe(msgObj)
605
606 // maybe we can use just the same eventName for different state transitions like "forward"
607 // - might be checked, but so far I go for sure and have to inspect the concrete state events ...
608 switch oFsm.pOmciCC.pLastTxMeInstance.GetName() {
609 case "Ieee8021PMapperServiceProfile":
610 { // let the FSM proceed ...
mpagenko1cc3cb42020-07-27 15:24:38 +0000611 oFsm.pAdaptFsm.pFsm.Event(aniEvRxDot1pmapCresp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000612 }
613 case "MacBridgePortConfigurationData":
614 { // let the FSM proceed ...
mpagenko1cc3cb42020-07-27 15:24:38 +0000615 oFsm.pAdaptFsm.pFsm.Event(aniEvRxMbpcdResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000616 }
617 case "GemPortNetworkCtp", "GemInterworkingTerminationPoint":
618 { // let aniConfig Multi-Id processing proceed by stopping the wait function
619 oFsm.omciMIdsResponseReceived <- true
620 }
621 }
622 }
623 } //CreateResponseType
624 case omci.SetResponseType:
625 {
626 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
627 if msgLayer == nil {
628 logger.Error("UniPonAniConfigFsm - Omci Msg layer could not be detected for SetResponse")
629 return
630 }
631 msgObj, msgOk := msgLayer.(*omci.SetResponse)
632 if !msgOk {
633 logger.Error("UniPonAniConfigFsm - Omci Msg layer could not be assigned for SetResponse")
634 return
635 }
636 logger.Debugw("UniPonAniConfigFsm SetResponse Data", log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj})
637 if msgObj.Result != me.Success {
638 logger.Errorw("UniPonAniConfigFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result})
639 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
640 return
641 }
642 if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() &&
643 msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() {
644 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
645 // if, then something like:
646 //oFsm.pOnuDB.StoreMe(msgObj)
647
648 switch oFsm.pOmciCC.pLastTxMeInstance.GetName() {
649 case "TCont":
650 { // let the FSM proceed ...
mpagenko1cc3cb42020-07-27 15:24:38 +0000651 oFsm.pAdaptFsm.pFsm.Event(aniEvRxTcontsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000652 }
653 case "PriorityQueue":
654 { // let the PrioQueue init proceed by stopping the wait function
655 oFsm.omciMIdsResponseReceived <- true
656 }
657 case "Ieee8021PMapperServiceProfile":
658 { // let the FSM proceed ...
mpagenko1cc3cb42020-07-27 15:24:38 +0000659 oFsm.pAdaptFsm.pFsm.Event(aniEvRxDot1pmapSresp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000660 }
661 }
662 }
663 } //SetResponseType
664 default:
665 {
666 logger.Errorw("UniPonAniConfigFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType})
667 return
668 }
669 }
670}
671
672func (oFsm *UniPonAniConfigFsm) performCreatingGemNCTPs() {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000673 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
674 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
675 logger.Debugw("UniPonAniConfigFsm Tx Create::GemNWCtp", log.Fields{
676 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
677 "TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
678 "device-id": oFsm.pAdaptFsm.deviceID})
679 meParams := me.ParamData{
680 EntityID: gemPortAttribs.gemPortID, //unique, same as PortId
681 Attributes: me.AttributeValueMap{
682 "PortId": gemPortAttribs.gemPortID,
683 "TContPointer": oFsm.tcont0ID,
684 "Direction": gemPortAttribs.direction,
685 //ONU-G.TrafficManagementOption dependency ->PrioQueue or TCont
686 // TODO!! verify dependency and QueueId in case of Multi-GemPort setup!
687 "TrafficManagementPointerForUpstream": gemPortAttribs.upQueueID, //might be different in wrr-only Setup - tcont0ID
688 "PriorityQueuePointerForDownStream": gemPortAttribs.downQueueID,
689 },
690 }
691 meInstance := oFsm.pOmciCC.sendCreateGemNCTPVar(context.TODO(), ConstDefaultOmciTimeout, true,
692 oFsm.pAdaptFsm.commChan, meParams)
693 //accept also nil as (error) return value for writing to LastTx
694 // - this avoids misinterpretation of new received OMCI messages
695 oFsm.pOmciCC.pLastTxMeInstance = meInstance
mpagenko3dbcdd22020-07-22 07:38:45 +0000696
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000697 //verify response
698 err := oFsm.waitforOmciResponse()
699 if err != nil {
700 logger.Errorw("GemNWCtp create failed, aborting AniConfig FSM!",
701 log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID, "GemIndex": gemIndex})
702 oFsm.pAdaptFsm.pFsm.Event(aniEvReset)
703 return
704 }
705 } //for all GemPorts of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +0000706
707 // if Config has been done for all GemPort instances let the FSM proceed
708 logger.Debugw("GemNWCtp create loop finished", log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID})
mpagenko1cc3cb42020-07-27 15:24:38 +0000709 oFsm.pAdaptFsm.pFsm.Event(aniEvRxGemntcpsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000710 return
711}
712
713func (oFsm *UniPonAniConfigFsm) performCreatingGemIWs() {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000714 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
715 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
716 logger.Debugw("UniPonAniConfigFsm Tx Create::GemIwTp", log.Fields{
717 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
718 "SPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
719 "device-id": oFsm.pAdaptFsm.deviceID})
720 meParams := me.ParamData{
721 EntityID: gemPortAttribs.gemPortID,
722 Attributes: me.AttributeValueMap{
723 "GemPortNetworkCtpConnectivityPointer": gemPortAttribs.gemPortID, //same as EntityID, see above
724 "InterworkingOption": 5, //fixed model:: G.998 .1pMapper
725 "ServiceProfilePointer": oFsm.mapperSP0ID,
726 "InterworkingTerminationPointPointer": 0, //not used with .1PMapper Mac bridge
727 "GalProfilePointer": galEthernetEID,
728 },
729 }
730 meInstance := oFsm.pOmciCC.sendCreateGemIWTPVar(context.TODO(), ConstDefaultOmciTimeout, true,
731 oFsm.pAdaptFsm.commChan, meParams)
732 //accept also nil as (error) return value for writing to LastTx
733 // - this avoids misinterpretation of new received OMCI messages
734 oFsm.pOmciCC.pLastTxMeInstance = meInstance
mpagenko3dbcdd22020-07-22 07:38:45 +0000735
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000736 //verify response
737 err := oFsm.waitforOmciResponse()
738 if err != nil {
739 logger.Errorw("GemIwTp create failed, aborting AniConfig FSM!",
740 log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID, "GemIndex": gemIndex})
741 oFsm.pAdaptFsm.pFsm.Event(aniEvReset)
742 return
743 }
744 } //for all GemPort's of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +0000745
746 // if Config has been done for all GemPort instances let the FSM proceed
747 logger.Debugw("GemIwTp create loop finished", log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID})
mpagenko1cc3cb42020-07-27 15:24:38 +0000748 oFsm.pAdaptFsm.pFsm.Event(aniEvRxGemiwsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000749 return
750}
751
752func (oFsm *UniPonAniConfigFsm) performSettingPQs() {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000753 const cu16StrictPrioWeight uint16 = 0xFFFF
754 //find all upstream PrioQueues related to this T-Cont
755 loQueueMap := ordered_map.NewOrderedMap()
756 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
757 if gemPortAttribs.qosPolicy == "WRR" {
758 if _, ok := loQueueMap.Get(gemPortAttribs.upQueueID); ok == false {
759 //key does not yet exist
760 loQueueMap.Set(gemPortAttribs.upQueueID, uint16(gemPortAttribs.weight))
761 }
762 } else {
763 loQueueMap.Set(gemPortAttribs.upQueueID, cu16StrictPrioWeight) //use invalid weight value to indicate SP
764 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000765 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000766
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000767 //TODO: assumption here is that ONU data uses SP setting in the T-Cont and WRR in the TrafficScheduler
768 // if that is not the case, the reverse case could be checked and reacted accordingly or if the
769 // complete chain is not valid, then some error should be thrown and configuration can be aborted
770 // or even be finished without correct SP/WRR setting
771
772 //TODO: search for the (WRR)trafficScheduler related to the T-Cont of this queue
773 //By now assume fixed value 0x8000, which is the only announce BBSIM TrafficScheduler,
774 // even though its T-Cont seems to be wrong ...
775 loTrafficSchedulerEID := 0x8000
776 //for all found queues
777 iter := loQueueMap.IterFunc()
778 for kv, ok := iter(); ok; kv, ok = iter() {
779 queueIndex := (kv.Key).(uint16)
780 meParams := me.ParamData{
781 EntityID: queueIndex,
782 Attributes: make(me.AttributeValueMap, 0),
783 }
784 if (kv.Value).(uint16) == cu16StrictPrioWeight {
785 //StrictPrio indication
786 logger.Debugw("UniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio", log.Fields{
787 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
788 "device-id": oFsm.pAdaptFsm.deviceID})
789 meParams.Attributes["TrafficSchedulerPointer"] = 0 //ensure T-Cont defined StrictPrio scheduling
790 } else {
791 //WRR indication
792 logger.Debugw("UniPonAniConfigFsm Tx Set::PrioQueue to WRR", log.Fields{
793 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
794 "Weight": kv.Value,
795 "device-id": oFsm.pAdaptFsm.deviceID})
796 meParams.Attributes["TrafficSchedulerPointer"] = loTrafficSchedulerEID //ensure assignment of the relevant trafficScheduler
797 meParams.Attributes["Weight"] = uint8(kv.Value.(uint16))
798 }
799 meInstance := oFsm.pOmciCC.sendSetPrioQueueVar(context.TODO(), ConstDefaultOmciTimeout, true,
800 oFsm.pAdaptFsm.commChan, meParams)
801 //accept also nil as (error) return value for writing to LastTx
802 // - this avoids misinterpretation of new received OMCI messages
803 oFsm.pOmciCC.pLastTxMeInstance = meInstance
804
805 //verify response
806 err := oFsm.waitforOmciResponse()
807 if err != nil {
808 logger.Errorw("PrioQueue set failed, aborting AniConfig FSM!",
809 log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID, "QueueId": strconv.FormatInt(int64(queueIndex), 16)})
810 oFsm.pAdaptFsm.pFsm.Event(aniEvReset)
811 return
812 }
813
814 //TODO: In case of WRR setting of the GemPort/PrioQueue it might further be necessary to
815 // write the assigned trafficScheduler with the requested Prio to be considered in the StrictPrio scheduling
816 // of the (next upstream) assigned T-Cont, which is f(prioQueue[priority]) - in relation to other SP prioQueues
817 // not yet done because of BBSIM TrafficScheduler issues (and not done in py code as well)
818
819 } //for all upstream prioQueues
mpagenko3dbcdd22020-07-22 07:38:45 +0000820
821 // if Config has been done for all PrioQueue instances let the FSM proceed
822 logger.Debugw("PrioQueue set loop finished", log.Fields{"deviceId": oFsm.pAdaptFsm.deviceID})
mpagenko1cc3cb42020-07-27 15:24:38 +0000823 oFsm.pAdaptFsm.pFsm.Event(aniEvRxPrioqsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000824 return
825}
826
827func (oFsm *UniPonAniConfigFsm) waitforOmciResponse() error {
828 select {
829 // maybe be also some outside cancel (but no context modelled for the moment ...)
830 // case <-ctx.Done():
831 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
832 case <-time.After(30 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
833 logger.Warnw("UniPonAniConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
834 return errors.New("UniPonAniConfigFsm multi entity timeout")
835 case success := <-oFsm.omciMIdsResponseReceived:
836 if success == true {
837 logger.Debug("UniPonAniConfigFsm multi entity response received")
838 return nil
839 }
840 // should not happen so far
841 logger.Warnw("UniPonAniConfigFsm multi entity response error", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
842 return errors.New("UniPonAniConfigFsm multi entity responseError")
843 }
844}