blob: f724e0fac9ac9f50a7518e516a4606999b78fe33 [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 {
divyadesai4d299552020-08-18 07:13:49 +0000227 logger.Warnw("No TCont instances found", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000228 }
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 {
Holger Hildebrandt2ff21f12020-08-13 14:38:02 +0000256 if relatedPort, err := oFsm.pOnuDB.GetUint32Attrib(returnVal); err == nil {
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), "device-id": 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), "device-id": oFsm.pAdaptFsm.deviceID})
266 dsQueueFound = true
267 }
268 if usQueueFound && dsQueueFound {
269 break
270 }
271 } else {
272 logger.Warnw("Could not convert attribute value", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000273 }
274 } else {
divyadesai4d299552020-08-18 07:13:49 +0000275 logger.Warnw("'relatedPort' not found in meAttributes:", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000276 }
277 } else {
278 logger.Warnw("No attributes available in DB:", log.Fields{"meClassID": me.PriorityQueueClassID,
divyadesai4d299552020-08-18 07:13:49 +0000279 "mgmtEntityId": mgmtEntityId, "device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000280 }
281 }
282 } else {
divyadesai4d299552020-08-18 07:13:49 +0000283 logger.Warnw("No PriorityQueue instances found", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000284 }
285 loGemPortAttribs.direction = gemEntry.direction
286 loGemPortAttribs.qosPolicy = gemEntry.queueSchedPolicy
287 loGemPortAttribs.weight = gemEntry.queueWeight
288 loGemPortAttribs.pbitString = gemEntry.pbitString
289
Holger Hildebrandt2ff21f12020-08-13 14:38:02 +0000290 logger.Debugw("prio-related GemPort attributes:", log.Fields{
291 "gemPortID": loGemPortAttribs.gemPortID,
292 "upQueueID": loGemPortAttribs.upQueueID,
293 "downQueueID": loGemPortAttribs.downQueueID,
294 "pbitString": loGemPortAttribs.pbitString,
295 "prioQueueIndex": gemEntry.prioQueueIndex,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000296 })
297
298 oFsm.gemPortAttribsSlice = append(oFsm.gemPortAttribsSlice, loGemPortAttribs)
299 }
mpagenko1cc3cb42020-07-27 15:24:38 +0000300 a_pAFsm.pFsm.Event(aniEvStartConfig)
mpagenko3dbcdd22020-07-22 07:38:45 +0000301 }
302 }(pConfigAniStateAFsm)
303 }
304}
305
306func (oFsm *UniPonAniConfigFsm) enterCreatingDot1PMapper(e *fsm.Event) {
307 logger.Debugw("UniPonAniConfigFsm Tx Create::Dot1PMapper", log.Fields{
308 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
309 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
310 meInstance := oFsm.pOmciCC.sendCreateDot1PMapper(context.TODO(), ConstDefaultOmciTimeout, true,
311 oFsm.mapperSP0ID, oFsm.pAdaptFsm.commChan)
312 //accept also nil as (error) return value for writing to LastTx
313 // - this avoids misinterpretation of new received OMCI messages
314 oFsm.pOmciCC.pLastTxMeInstance = meInstance
315}
316
317func (oFsm *UniPonAniConfigFsm) enterCreatingMBPCD(e *fsm.Event) {
318 logger.Debugw("UniPonAniConfigFsm Tx Create::MBPCD", log.Fields{
319 "EntitytId": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16),
320 "TPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
321 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
322 bridgePtr := macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo) //cmp also omci_cc.go::sendCreateMBServiceProfile
323 meParams := me.ParamData{
324 EntityID: oFsm.macBPCD0ID,
325 Attributes: me.AttributeValueMap{
326 "BridgeIdPointer": bridgePtr,
327 "PortNum": 0xFF, //fixed unique ANI side indication
328 "TpType": 3, //for .1PMapper
329 "TpPointer": oFsm.mapperSP0ID,
330 },
331 }
332 meInstance := oFsm.pOmciCC.sendCreateMBPConfigDataVar(context.TODO(), ConstDefaultOmciTimeout, true,
333 oFsm.pAdaptFsm.commChan, meParams)
334 //accept also nil as (error) return value for writing to LastTx
335 // - this avoids misinterpretation of new received OMCI messages
336 oFsm.pOmciCC.pLastTxMeInstance = meInstance
337
338}
339
340func (oFsm *UniPonAniConfigFsm) enterSettingTconts(e *fsm.Event) {
341 logger.Debugw("UniPonAniConfigFsm Tx Set::Tcont", log.Fields{
342 "EntitytId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
343 "AllocId": strconv.FormatInt(int64(oFsm.alloc0ID), 16),
344 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
345 meParams := me.ParamData{
346 EntityID: oFsm.tcont0ID,
347 Attributes: me.AttributeValueMap{
348 "AllocId": oFsm.alloc0ID,
349 },
350 }
351 meInstance := oFsm.pOmciCC.sendSetTcontVar(context.TODO(), ConstDefaultOmciTimeout, true,
352 oFsm.pAdaptFsm.commChan, meParams)
353 //accept also nil as (error) return value for writing to LastTx
354 // - this avoids misinterpretation of new received OMCI messages
355 oFsm.pOmciCC.pLastTxMeInstance = meInstance
356}
357
358func (oFsm *UniPonAniConfigFsm) enterCreatingGemNCTPs(e *fsm.Event) {
359 //TODO!! this is just for the first GemPort right now - needs update
360 logger.Debugw("UniPonAniConfigFsm - start creating GemNWCtp loop", log.Fields{
361 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
362 go oFsm.performCreatingGemNCTPs()
363}
364
365func (oFsm *UniPonAniConfigFsm) enterCreatingGemIWs(e *fsm.Event) {
366 logger.Debugw("UniPonAniConfigFsm - start creating GemIwTP loop", log.Fields{
367 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
368 go oFsm.performCreatingGemIWs()
369}
370
371func (oFsm *UniPonAniConfigFsm) enterSettingPQs(e *fsm.Event) {
372 logger.Debugw("UniPonAniConfigFsm - start setting PrioQueue loop", log.Fields{
373 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
374 go oFsm.performSettingPQs()
375}
376
377func (oFsm *UniPonAniConfigFsm) enterSettingDot1PMapper(e *fsm.Event) {
378 logger.Debugw("UniPonAniConfigFsm Tx Set::.1pMapper with all PBits set", log.Fields{"EntitytId": 0x8042, /*cmp above*/
379 "toGemIw": 1024 /* cmp above */, "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
380
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000381 logger.Debugw("UniPonAniConfigFsm Tx Set::1pMapper", log.Fields{
382 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
383 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
384
mpagenko3dbcdd22020-07-22 07:38:45 +0000385 meParams := me.ParamData{
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000386 EntityID: oFsm.mapperSP0ID,
387 Attributes: make(me.AttributeValueMap, 0),
mpagenko3dbcdd22020-07-22 07:38:45 +0000388 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000389
390 //assign the GemPorts according to the configured Prio
391 var loPrioGemPortArray [8]uint16
392 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
393 for i := 0; i < 8; i++ {
394 // "lenOfPbitMap(8) - i + 1" will give i-th pbit value from LSB position in the pbit map string
395 if prio, err := strconv.Atoi(string(gemPortAttribs.pbitString[7-i])); err == nil {
396 if prio == 1 { // Check this p-bit is set
397 if loPrioGemPortArray[i] == 0 {
398 loPrioGemPortArray[i] = gemPortAttribs.gemPortID //gemPortId=EntityID and unique
399 } else {
400 logger.Warnw("UniPonAniConfigFsm PrioString not unique", log.Fields{
401 "device-id": oFsm.pAdaptFsm.deviceID, "IgnoredGemPort": gemPortAttribs.gemPortID,
402 "SetGemPort": loPrioGemPortArray[i]})
403 }
404 }
405 } else {
406 logger.Warnw("UniPonAniConfigFsm PrioString evaluation error", log.Fields{
407 "device-id": oFsm.pAdaptFsm.deviceID, "GemPort": gemPortAttribs.gemPortID,
408 "prioString": gemPortAttribs.pbitString, "position": i})
409 }
410
411 }
412 }
413 var foundIwPtr bool = false
414 if loPrioGemPortArray[0] != 0 {
415 foundIwPtr = true
416 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
417 "IwPtr for Prio0": strconv.FormatInt(int64(loPrioGemPortArray[0]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
418 meParams.Attributes["InterworkTpPointerForPBitPriority0"] = loPrioGemPortArray[0]
419 }
420 if loPrioGemPortArray[1] != 0 {
421 foundIwPtr = true
422 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
423 "IwPtr for Prio1": strconv.FormatInt(int64(loPrioGemPortArray[1]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
424 meParams.Attributes["InterworkTpPointerForPBitPriority1"] = loPrioGemPortArray[1]
425 }
426 if loPrioGemPortArray[2] != 0 {
427 foundIwPtr = true
428 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
429 "IwPtr for Prio2": strconv.FormatInt(int64(loPrioGemPortArray[2]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
430 meParams.Attributes["InterworkTpPointerForPBitPriority2"] = loPrioGemPortArray[2]
431 }
432 if loPrioGemPortArray[3] != 0 {
433 foundIwPtr = true
434 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
435 "IwPtr for Prio3": strconv.FormatInt(int64(loPrioGemPortArray[3]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
436 meParams.Attributes["InterworkTpPointerForPBitPriority3"] = loPrioGemPortArray[3]
437 }
438 if loPrioGemPortArray[4] != 0 {
439 foundIwPtr = true
440 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
441 "IwPtr for Prio4": strconv.FormatInt(int64(loPrioGemPortArray[4]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
442 meParams.Attributes["InterworkTpPointerForPBitPriority4"] = loPrioGemPortArray[4]
443 }
444 if loPrioGemPortArray[5] != 0 {
445 foundIwPtr = true
446 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
447 "IwPtr for Prio5": strconv.FormatInt(int64(loPrioGemPortArray[5]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
448 meParams.Attributes["InterworkTpPointerForPBitPriority5"] = loPrioGemPortArray[5]
449 }
450 if loPrioGemPortArray[6] != 0 {
451 foundIwPtr = true
452 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
453 "IwPtr for Prio6": strconv.FormatInt(int64(loPrioGemPortArray[6]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
454 meParams.Attributes["InterworkTpPointerForPBitPriority6"] = loPrioGemPortArray[6]
455 }
456 if loPrioGemPortArray[7] != 0 {
457 foundIwPtr = true
458 logger.Debugw("UniPonAniConfigFsm Set::1pMapper", log.Fields{
459 "IwPtr for Prio7": strconv.FormatInt(int64(loPrioGemPortArray[7]), 16), "device-id": oFsm.pAdaptFsm.deviceID})
460 meParams.Attributes["InterworkTpPointerForPBitPriority7"] = loPrioGemPortArray[7]
461 }
462 if foundIwPtr == false {
463 logger.Errorw("UniPonAniConfigFsm no GemIwPtr found for .1pMapper - abort", log.Fields{
464 "device-id": oFsm.pAdaptFsm.deviceID})
465 //let's reset the state machine in order to release all resources now
466 pConfigAniStateAFsm := oFsm.pAdaptFsm
467 if pConfigAniStateAFsm != nil {
468 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
469 go func(a_pAFsm *AdapterFsm) {
470 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
471 a_pAFsm.pFsm.Event(aniEvReset)
472 }
473 }(pConfigAniStateAFsm)
474 }
475 }
476
mpagenko3dbcdd22020-07-22 07:38:45 +0000477 meInstance := oFsm.pOmciCC.sendSetDot1PMapperVar(context.TODO(), ConstDefaultOmciTimeout, true,
478 oFsm.pAdaptFsm.commChan, meParams)
479 //accept also nil as (error) return value for writing to LastTx
480 // - this avoids misinterpretation of new received OMCI messages
481 oFsm.pOmciCC.pLastTxMeInstance = meInstance
482}
483
484func (oFsm *UniPonAniConfigFsm) enterAniConfigDone(e *fsm.Event) {
485
mpagenko1cc3cb42020-07-27 15:24:38 +0000486 oFsm.aniConfigCompleted = true
mpagenko3dbcdd22020-07-22 07:38:45 +0000487
488 //let's reset the state machine in order to release all resources now
489 pConfigAniStateAFsm := oFsm.pAdaptFsm
490 if pConfigAniStateAFsm != nil {
491 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
492 go func(a_pAFsm *AdapterFsm) {
493 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000494 a_pAFsm.pFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +0000495 }
496 }(pConfigAniStateAFsm)
497 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000498}
499
500func (oFsm *UniPonAniConfigFsm) enterResettingState(e *fsm.Event) {
501 logger.Debugw("UniPonAniConfigFsm resetting", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000502
mpagenko3dbcdd22020-07-22 07:38:45 +0000503 pConfigAniStateAFsm := oFsm.pAdaptFsm
504 if pConfigAniStateAFsm != nil {
505 // abort running message processing
506 fsmAbortMsg := Message{
507 Type: TestMsg,
508 Data: TestMessage{
509 TestMessageVal: AbortMessageProcessing,
510 },
511 }
512 pConfigAniStateAFsm.commChan <- fsmAbortMsg
513
514 //try to restart the FSM to 'disabled', decouple event transfer
515 go func(a_pAFsm *AdapterFsm) {
516 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000517 a_pAFsm.pFsm.Event(aniEvRestart)
mpagenko3dbcdd22020-07-22 07:38:45 +0000518 }
519 }(pConfigAniStateAFsm)
520 }
521}
522
mpagenko1cc3cb42020-07-27 15:24:38 +0000523func (oFsm *UniPonAniConfigFsm) enterDisabledState(e *fsm.Event) {
524 logger.Debugw("UniPonAniConfigFsm enters disabled state", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
525
526 if oFsm.aniConfigCompleted {
527 logger.Debugw("UniPonAniConfigFsm send dh event notification", log.Fields{
528 "from_State": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
529 //use DeviceHandler event notification directly
530 oFsm.pOmciCC.pBaseDeviceHandler.DeviceProcStatusUpdate(oFsm.requestEvent)
531 oFsm.aniConfigCompleted = false
532 }
533
534 if oFsm.chanSet {
535 // indicate processing done to the caller
536 logger.Debugw("UniPonAniConfigFsm processingDone on channel", log.Fields{
537 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
538 oFsm.chSuccess <- oFsm.procStep
539 oFsm.chanSet = false //reset the internal channel state
540 }
541
542}
543
mpagenko3dbcdd22020-07-22 07:38:45 +0000544func (oFsm *UniPonAniConfigFsm) ProcessOmciAniMessages( /*ctx context.Context*/ ) {
545 logger.Debugw("Start UniPonAniConfigFsm Msg processing", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
546loop:
547 for {
548 select {
549 // case <-ctx.Done():
550 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.pAdaptFsm.deviceID})
551 // break loop
552 case message, ok := <-oFsm.pAdaptFsm.commChan:
553 if !ok {
554 logger.Info("UniPonAniConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
555 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
mpagenko1cc3cb42020-07-27 15:24:38 +0000556 oFsm.pAdaptFsm.pFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +0000557 break loop
558 }
559 logger.Debugw("UniPonAniConfigFsm Rx Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
560
561 switch message.Type {
562 case TestMsg:
563 msg, _ := message.Data.(TestMessage)
564 if msg.TestMessageVal == AbortMessageProcessing {
565 logger.Infow("UniPonAniConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
566 break loop
567 }
568 logger.Warnw("UniPonAniConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "MessageVal": msg.TestMessageVal})
569 case OMCI:
570 msg, _ := message.Data.(OmciMessage)
571 oFsm.handleOmciAniConfigMessage(msg)
572 default:
573 logger.Warn("UniPonAniConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID,
574 "message.Type": message.Type})
575 }
576 }
577 }
578 logger.Infow("End UniPonAniConfigFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
579}
580
581func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigMessage(msg OmciMessage) {
582 logger.Debugw("Rx OMCI UniPonAniConfigFsm Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID,
583 "msgType": msg.OmciMsg.MessageType})
584
585 switch msg.OmciMsg.MessageType {
586 case omci.CreateResponseType:
587 {
588 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse)
589 if msgLayer == nil {
590 logger.Error("Omci Msg layer could not be detected for CreateResponse")
591 return
592 }
593 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
594 if !msgOk {
595 logger.Error("Omci Msg layer could not be assigned for CreateResponse")
596 return
597 }
divyadesai4d299552020-08-18 07:13:49 +0000598 logger.Debugw("CreateResponse Data", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj})
mpagenko3dbcdd22020-07-22 07:38:45 +0000599 if msgObj.Result != me.Success {
600 logger.Errorw("Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result})
601 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
602 return
603 }
604 if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() &&
605 msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() {
606 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
607 // if, then something like:
608 //oFsm.pOnuDB.StoreMe(msgObj)
609
610 // maybe we can use just the same eventName for different state transitions like "forward"
611 // - might be checked, but so far I go for sure and have to inspect the concrete state events ...
612 switch oFsm.pOmciCC.pLastTxMeInstance.GetName() {
613 case "Ieee8021PMapperServiceProfile":
614 { // let the FSM proceed ...
mpagenko1cc3cb42020-07-27 15:24:38 +0000615 oFsm.pAdaptFsm.pFsm.Event(aniEvRxDot1pmapCresp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000616 }
617 case "MacBridgePortConfigurationData":
618 { // let the FSM proceed ...
mpagenko1cc3cb42020-07-27 15:24:38 +0000619 oFsm.pAdaptFsm.pFsm.Event(aniEvRxMbpcdResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000620 }
621 case "GemPortNetworkCtp", "GemInterworkingTerminationPoint":
622 { // let aniConfig Multi-Id processing proceed by stopping the wait function
623 oFsm.omciMIdsResponseReceived <- true
624 }
625 }
626 }
627 } //CreateResponseType
628 case omci.SetResponseType:
629 {
630 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
631 if msgLayer == nil {
632 logger.Error("UniPonAniConfigFsm - Omci Msg layer could not be detected for SetResponse")
633 return
634 }
635 msgObj, msgOk := msgLayer.(*omci.SetResponse)
636 if !msgOk {
637 logger.Error("UniPonAniConfigFsm - Omci Msg layer could not be assigned for SetResponse")
638 return
639 }
divyadesai4d299552020-08-18 07:13:49 +0000640 logger.Debugw("UniPonAniConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj})
mpagenko3dbcdd22020-07-22 07:38:45 +0000641 if msgObj.Result != me.Success {
642 logger.Errorw("UniPonAniConfigFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result})
643 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
644 return
645 }
646 if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() &&
647 msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() {
648 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
649 // if, then something like:
650 //oFsm.pOnuDB.StoreMe(msgObj)
651
652 switch oFsm.pOmciCC.pLastTxMeInstance.GetName() {
653 case "TCont":
654 { // let the FSM proceed ...
mpagenko1cc3cb42020-07-27 15:24:38 +0000655 oFsm.pAdaptFsm.pFsm.Event(aniEvRxTcontsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000656 }
657 case "PriorityQueue":
658 { // let the PrioQueue init proceed by stopping the wait function
659 oFsm.omciMIdsResponseReceived <- true
660 }
661 case "Ieee8021PMapperServiceProfile":
662 { // let the FSM proceed ...
mpagenko1cc3cb42020-07-27 15:24:38 +0000663 oFsm.pAdaptFsm.pFsm.Event(aniEvRxDot1pmapSresp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000664 }
665 }
666 }
667 } //SetResponseType
668 default:
669 {
670 logger.Errorw("UniPonAniConfigFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType})
671 return
672 }
673 }
674}
675
676func (oFsm *UniPonAniConfigFsm) performCreatingGemNCTPs() {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000677 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
678 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
679 logger.Debugw("UniPonAniConfigFsm Tx Create::GemNWCtp", log.Fields{
680 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
681 "TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
682 "device-id": oFsm.pAdaptFsm.deviceID})
683 meParams := me.ParamData{
684 EntityID: gemPortAttribs.gemPortID, //unique, same as PortId
685 Attributes: me.AttributeValueMap{
686 "PortId": gemPortAttribs.gemPortID,
687 "TContPointer": oFsm.tcont0ID,
688 "Direction": gemPortAttribs.direction,
689 //ONU-G.TrafficManagementOption dependency ->PrioQueue or TCont
690 // TODO!! verify dependency and QueueId in case of Multi-GemPort setup!
691 "TrafficManagementPointerForUpstream": gemPortAttribs.upQueueID, //might be different in wrr-only Setup - tcont0ID
692 "PriorityQueuePointerForDownStream": gemPortAttribs.downQueueID,
693 },
694 }
695 meInstance := oFsm.pOmciCC.sendCreateGemNCTPVar(context.TODO(), ConstDefaultOmciTimeout, true,
696 oFsm.pAdaptFsm.commChan, meParams)
697 //accept also nil as (error) return value for writing to LastTx
698 // - this avoids misinterpretation of new received OMCI messages
699 oFsm.pOmciCC.pLastTxMeInstance = meInstance
mpagenko3dbcdd22020-07-22 07:38:45 +0000700
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000701 //verify response
702 err := oFsm.waitforOmciResponse()
703 if err != nil {
704 logger.Errorw("GemNWCtp create failed, aborting AniConfig FSM!",
divyadesai4d299552020-08-18 07:13:49 +0000705 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000706 oFsm.pAdaptFsm.pFsm.Event(aniEvReset)
707 return
708 }
709 } //for all GemPorts of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +0000710
711 // if Config has been done for all GemPort instances let the FSM proceed
divyadesai4d299552020-08-18 07:13:49 +0000712 logger.Debugw("GemNWCtp create loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
mpagenko1cc3cb42020-07-27 15:24:38 +0000713 oFsm.pAdaptFsm.pFsm.Event(aniEvRxGemntcpsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000714 return
715}
716
717func (oFsm *UniPonAniConfigFsm) performCreatingGemIWs() {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000718 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
719 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
720 logger.Debugw("UniPonAniConfigFsm Tx Create::GemIwTp", log.Fields{
721 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
722 "SPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
723 "device-id": oFsm.pAdaptFsm.deviceID})
724 meParams := me.ParamData{
725 EntityID: gemPortAttribs.gemPortID,
726 Attributes: me.AttributeValueMap{
727 "GemPortNetworkCtpConnectivityPointer": gemPortAttribs.gemPortID, //same as EntityID, see above
728 "InterworkingOption": 5, //fixed model:: G.998 .1pMapper
729 "ServiceProfilePointer": oFsm.mapperSP0ID,
730 "InterworkingTerminationPointPointer": 0, //not used with .1PMapper Mac bridge
731 "GalProfilePointer": galEthernetEID,
732 },
733 }
734 meInstance := oFsm.pOmciCC.sendCreateGemIWTPVar(context.TODO(), ConstDefaultOmciTimeout, true,
735 oFsm.pAdaptFsm.commChan, meParams)
736 //accept also nil as (error) return value for writing to LastTx
737 // - this avoids misinterpretation of new received OMCI messages
738 oFsm.pOmciCC.pLastTxMeInstance = meInstance
mpagenko3dbcdd22020-07-22 07:38:45 +0000739
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000740 //verify response
741 err := oFsm.waitforOmciResponse()
742 if err != nil {
743 logger.Errorw("GemIwTp create failed, aborting AniConfig FSM!",
divyadesai4d299552020-08-18 07:13:49 +0000744 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "GemIndex": gemIndex})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000745 oFsm.pAdaptFsm.pFsm.Event(aniEvReset)
746 return
747 }
748 } //for all GemPort's of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +0000749
750 // if Config has been done for all GemPort instances let the FSM proceed
divyadesai4d299552020-08-18 07:13:49 +0000751 logger.Debugw("GemIwTp create loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
mpagenko1cc3cb42020-07-27 15:24:38 +0000752 oFsm.pAdaptFsm.pFsm.Event(aniEvRxGemiwsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000753 return
754}
755
756func (oFsm *UniPonAniConfigFsm) performSettingPQs() {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000757 const cu16StrictPrioWeight uint16 = 0xFFFF
758 //find all upstream PrioQueues related to this T-Cont
759 loQueueMap := ordered_map.NewOrderedMap()
760 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
761 if gemPortAttribs.qosPolicy == "WRR" {
762 if _, ok := loQueueMap.Get(gemPortAttribs.upQueueID); ok == false {
763 //key does not yet exist
764 loQueueMap.Set(gemPortAttribs.upQueueID, uint16(gemPortAttribs.weight))
765 }
766 } else {
767 loQueueMap.Set(gemPortAttribs.upQueueID, cu16StrictPrioWeight) //use invalid weight value to indicate SP
768 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000769 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000770
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000771 //TODO: assumption here is that ONU data uses SP setting in the T-Cont and WRR in the TrafficScheduler
772 // if that is not the case, the reverse case could be checked and reacted accordingly or if the
773 // complete chain is not valid, then some error should be thrown and configuration can be aborted
774 // or even be finished without correct SP/WRR setting
775
776 //TODO: search for the (WRR)trafficScheduler related to the T-Cont of this queue
777 //By now assume fixed value 0x8000, which is the only announce BBSIM TrafficScheduler,
778 // even though its T-Cont seems to be wrong ...
779 loTrafficSchedulerEID := 0x8000
780 //for all found queues
781 iter := loQueueMap.IterFunc()
782 for kv, ok := iter(); ok; kv, ok = iter() {
783 queueIndex := (kv.Key).(uint16)
784 meParams := me.ParamData{
785 EntityID: queueIndex,
786 Attributes: make(me.AttributeValueMap, 0),
787 }
788 if (kv.Value).(uint16) == cu16StrictPrioWeight {
789 //StrictPrio indication
790 logger.Debugw("UniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio", log.Fields{
791 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
792 "device-id": oFsm.pAdaptFsm.deviceID})
793 meParams.Attributes["TrafficSchedulerPointer"] = 0 //ensure T-Cont defined StrictPrio scheduling
794 } else {
795 //WRR indication
796 logger.Debugw("UniPonAniConfigFsm Tx Set::PrioQueue to WRR", log.Fields{
797 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
798 "Weight": kv.Value,
799 "device-id": oFsm.pAdaptFsm.deviceID})
800 meParams.Attributes["TrafficSchedulerPointer"] = loTrafficSchedulerEID //ensure assignment of the relevant trafficScheduler
801 meParams.Attributes["Weight"] = uint8(kv.Value.(uint16))
802 }
803 meInstance := oFsm.pOmciCC.sendSetPrioQueueVar(context.TODO(), ConstDefaultOmciTimeout, true,
804 oFsm.pAdaptFsm.commChan, meParams)
805 //accept also nil as (error) return value for writing to LastTx
806 // - this avoids misinterpretation of new received OMCI messages
807 oFsm.pOmciCC.pLastTxMeInstance = meInstance
808
809 //verify response
810 err := oFsm.waitforOmciResponse()
811 if err != nil {
812 logger.Errorw("PrioQueue set failed, aborting AniConfig FSM!",
divyadesai4d299552020-08-18 07:13:49 +0000813 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "QueueId": strconv.FormatInt(int64(queueIndex), 16)})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000814 oFsm.pAdaptFsm.pFsm.Event(aniEvReset)
815 return
816 }
817
818 //TODO: In case of WRR setting of the GemPort/PrioQueue it might further be necessary to
819 // write the assigned trafficScheduler with the requested Prio to be considered in the StrictPrio scheduling
820 // of the (next upstream) assigned T-Cont, which is f(prioQueue[priority]) - in relation to other SP prioQueues
821 // not yet done because of BBSIM TrafficScheduler issues (and not done in py code as well)
822
823 } //for all upstream prioQueues
mpagenko3dbcdd22020-07-22 07:38:45 +0000824
825 // if Config has been done for all PrioQueue instances let the FSM proceed
divyadesai4d299552020-08-18 07:13:49 +0000826 logger.Debugw("PrioQueue set loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
mpagenko1cc3cb42020-07-27 15:24:38 +0000827 oFsm.pAdaptFsm.pFsm.Event(aniEvRxPrioqsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000828 return
829}
830
831func (oFsm *UniPonAniConfigFsm) waitforOmciResponse() error {
832 select {
833 // maybe be also some outside cancel (but no context modelled for the moment ...)
834 // case <-ctx.Done():
835 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
836 case <-time.After(30 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
837 logger.Warnw("UniPonAniConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
838 return errors.New("UniPonAniConfigFsm multi entity timeout")
839 case success := <-oFsm.omciMIdsResponseReceived:
840 if success == true {
841 logger.Debug("UniPonAniConfigFsm multi entity response received")
842 return nil
843 }
844 // should not happen so far
845 logger.Warnw("UniPonAniConfigFsm multi entity response error", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
846 return errors.New("UniPonAniConfigFsm multi entity responseError")
847 }
848}