blob: 1d5e5d433eae2bb11ae0e3055f049362001f9ab1 [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"
Himani Chawla4d908332020-08-31 12:30:20 +053023 "fmt"
mpagenko3dbcdd22020-07-22 07:38:45 +000024 "strconv"
25 "time"
26
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000027 "github.com/cevaris/ordered_map"
mpagenko3dbcdd22020-07-22 07:38:45 +000028 "github.com/looplab/fsm"
mpagenko3dbcdd22020-07-22 07:38:45 +000029 "github.com/opencord/omci-lib-go"
30 me "github.com/opencord/omci-lib-go/generated"
31 "github.com/opencord/voltha-lib-go/v3/pkg/log"
32 //ic "github.com/opencord/voltha-protos/v3/go/inter_container"
33 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
34 //"github.com/opencord/voltha-protos/v3/go/voltha"
35)
36
mpagenko1cc3cb42020-07-27 15:24:38 +000037const (
38 // events of config PON ANI port FSM
39 aniEvStart = "uniEvStart"
40 aniEvStartConfig = "aniEvStartConfig"
mpagenkodff5dda2020-08-28 11:52:01 +000041 aniEvRxDot1pmapCResp = "aniEvRxDot1pmapCResp"
mpagenko1cc3cb42020-07-27 15:24:38 +000042 aniEvRxMbpcdResp = "aniEvRxMbpcdResp"
43 aniEvRxTcontsResp = "aniEvRxTcontsResp"
44 aniEvRxGemntcpsResp = "aniEvRxGemntcpsResp"
45 aniEvRxGemiwsResp = "aniEvRxGemiwsResp"
46 aniEvRxPrioqsResp = "aniEvRxPrioqsResp"
mpagenkodff5dda2020-08-28 11:52:01 +000047 aniEvRxDot1pmapSResp = "aniEvRxDot1pmapSResp"
mpagenko1cc3cb42020-07-27 15:24:38 +000048 aniEvTimeoutSimple = "aniEvTimeoutSimple"
49 aniEvTimeoutMids = "aniEvTimeoutMids"
50 aniEvReset = "aniEvReset"
51 aniEvRestart = "aniEvRestart"
52)
53const (
54 // states of config PON ANI port FSM
55 aniStDisabled = "aniStDisabled"
56 aniStStarting = "aniStStarting"
57 aniStCreatingDot1PMapper = "aniStCreatingDot1PMapper"
58 aniStCreatingMBPCD = "aniStCreatingMBPCD"
59 aniStSettingTconts = "aniStSettingTconts"
60 aniStCreatingGemNCTPs = "aniStCreatingGemNCTPs"
61 aniStCreatingGemIWs = "aniStCreatingGemIWs"
62 aniStSettingPQs = "aniStSettingPQs"
63 aniStSettingDot1PMapper = "aniStSettingDot1PMapper"
64 aniStConfigDone = "aniStConfigDone"
65 aniStResetting = "aniStResetting"
66)
67
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000068type ponAniGemPortAttribs struct {
69 gemPortID uint16
70 upQueueID uint16
71 downQueueID uint16
72 direction uint8
73 qosPolicy string
74 weight uint8
75 pbitString string
76}
77
mpagenko1cc3cb42020-07-27 15:24:38 +000078//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 +000079type UniPonAniConfigFsm struct {
80 pOmciCC *OmciCC
81 pOnuUniPort *OnuUniPort
82 pUniTechProf *OnuUniTechProf
83 pOnuDB *OnuDeviceDB
84 techProfileID uint16
85 requestEvent OnuDeviceEvent
Himani Chawla4d908332020-08-31 12:30:20 +053086 omciMIdsResponseReceived chan bool //separate channel needed for checking multiInstance OMCI message responses
mpagenko3dbcdd22020-07-22 07:38:45 +000087 pAdaptFsm *AdapterFsm
mpagenko1cc3cb42020-07-27 15:24:38 +000088 aniConfigCompleted bool
mpagenko3dbcdd22020-07-22 07:38:45 +000089 chSuccess chan<- uint8
90 procStep uint8
91 chanSet bool
92 mapperSP0ID uint16
93 macBPCD0ID uint16
94 tcont0ID uint16
95 alloc0ID uint16
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +000096 gemPortAttribsSlice []ponAniGemPortAttribs
mpagenko3dbcdd22020-07-22 07:38:45 +000097}
98
mpagenko1cc3cb42020-07-27 15:24:38 +000099//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 +0000100func NewUniPonAniConfigFsm(apDevOmciCC *OmciCC, apUniPort *OnuUniPort, apUniTechProf *OnuUniTechProf,
101 apOnuDB *OnuDeviceDB, aTechProfileID uint16, aRequestEvent OnuDeviceEvent, aName string,
102 aDeviceID string, aCommChannel chan Message) *UniPonAniConfigFsm {
103 instFsm := &UniPonAniConfigFsm{
mpagenko1cc3cb42020-07-27 15:24:38 +0000104 pOmciCC: apDevOmciCC,
105 pOnuUniPort: apUniPort,
106 pUniTechProf: apUniTechProf,
107 pOnuDB: apOnuDB,
108 techProfileID: aTechProfileID,
109 requestEvent: aRequestEvent,
110 aniConfigCompleted: false,
111 chanSet: false,
mpagenko3dbcdd22020-07-22 07:38:45 +0000112 }
113 instFsm.pAdaptFsm = NewAdapterFsm(aName, aDeviceID, aCommChannel)
114 if instFsm.pAdaptFsm == nil {
115 logger.Errorw("UniPonAniConfigFsm's AdapterFsm could not be instantiated!!", log.Fields{
116 "device-id": aDeviceID})
117 return nil
118 }
119
120 instFsm.pAdaptFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000121 aniStDisabled,
mpagenko3dbcdd22020-07-22 07:38:45 +0000122 fsm.Events{
123
mpagenko1cc3cb42020-07-27 15:24:38 +0000124 {Name: aniEvStart, Src: []string{aniStDisabled}, Dst: aniStStarting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000125
126 //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 +0000127 {Name: aniEvStartConfig, Src: []string{aniStStarting}, Dst: aniStCreatingDot1PMapper},
mpagenkodff5dda2020-08-28 11:52:01 +0000128 {Name: aniEvRxDot1pmapCResp, Src: []string{aniStCreatingDot1PMapper}, Dst: aniStCreatingMBPCD},
mpagenko1cc3cb42020-07-27 15:24:38 +0000129 {Name: aniEvRxMbpcdResp, Src: []string{aniStCreatingMBPCD}, Dst: aniStSettingTconts},
130 {Name: aniEvRxTcontsResp, Src: []string{aniStSettingTconts}, Dst: aniStCreatingGemNCTPs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000131 // the creatingGemNCTPs state is used for multi ME config if required for all configured/available GemPorts
mpagenko1cc3cb42020-07-27 15:24:38 +0000132 {Name: aniEvRxGemntcpsResp, Src: []string{aniStCreatingGemNCTPs}, Dst: aniStCreatingGemIWs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000133 // the creatingGemIWs state is used for multi ME config if required for all configured/available GemPorts
mpagenko1cc3cb42020-07-27 15:24:38 +0000134 {Name: aniEvRxGemiwsResp, Src: []string{aniStCreatingGemIWs}, Dst: aniStSettingPQs},
mpagenko3dbcdd22020-07-22 07:38:45 +0000135 // the settingPQs state is used for multi ME config if required for all configured/available upstream PriorityQueues
mpagenko1cc3cb42020-07-27 15:24:38 +0000136 {Name: aniEvRxPrioqsResp, Src: []string{aniStSettingPQs}, Dst: aniStSettingDot1PMapper},
mpagenkodff5dda2020-08-28 11:52:01 +0000137 {Name: aniEvRxDot1pmapSResp, Src: []string{aniStSettingDot1PMapper}, Dst: aniStConfigDone},
mpagenko3dbcdd22020-07-22 07:38:45 +0000138
mpagenko1cc3cb42020-07-27 15:24:38 +0000139 {Name: aniEvTimeoutSimple, Src: []string{
140 aniStCreatingDot1PMapper, aniStCreatingMBPCD, aniStSettingTconts, aniStSettingDot1PMapper}, Dst: aniStStarting},
141 {Name: aniEvTimeoutMids, Src: []string{
142 aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs}, Dst: aniStStarting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000143
mpagenko1cc3cb42020-07-27 15:24:38 +0000144 // exceptional treatment for all states except aniStResetting
145 {Name: aniEvReset, Src: []string{aniStStarting, aniStCreatingDot1PMapper, aniStCreatingMBPCD,
146 aniStSettingTconts, aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs, aniStSettingDot1PMapper,
147 aniStConfigDone}, Dst: aniStResetting},
mpagenko3dbcdd22020-07-22 07:38:45 +0000148 // the only way to get to resource-cleared disabled state again is via "resseting"
mpagenko1cc3cb42020-07-27 15:24:38 +0000149 {Name: aniEvRestart, Src: []string{aniStResetting}, Dst: aniStDisabled},
mpagenko3dbcdd22020-07-22 07:38:45 +0000150 },
151
152 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000153 "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) },
154 ("enter_" + aniStStarting): func(e *fsm.Event) { instFsm.enterConfigStartingState(e) },
155 ("enter_" + aniStCreatingDot1PMapper): func(e *fsm.Event) { instFsm.enterCreatingDot1PMapper(e) },
156 ("enter_" + aniStCreatingMBPCD): func(e *fsm.Event) { instFsm.enterCreatingMBPCD(e) },
157 ("enter_" + aniStSettingTconts): func(e *fsm.Event) { instFsm.enterSettingTconts(e) },
158 ("enter_" + aniStCreatingGemNCTPs): func(e *fsm.Event) { instFsm.enterCreatingGemNCTPs(e) },
159 ("enter_" + aniStCreatingGemIWs): func(e *fsm.Event) { instFsm.enterCreatingGemIWs(e) },
160 ("enter_" + aniStSettingPQs): func(e *fsm.Event) { instFsm.enterSettingPQs(e) },
161 ("enter_" + aniStSettingDot1PMapper): func(e *fsm.Event) { instFsm.enterSettingDot1PMapper(e) },
162 ("enter_" + aniStConfigDone): func(e *fsm.Event) { instFsm.enterAniConfigDone(e) },
163 ("enter_" + aniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(e) },
164 ("enter_" + aniStDisabled): func(e *fsm.Event) { instFsm.enterDisabledState(e) },
mpagenko3dbcdd22020-07-22 07:38:45 +0000165 },
166 )
167 if instFsm.pAdaptFsm.pFsm == nil {
168 logger.Errorw("UniPonAniConfigFsm's Base FSM could not be instantiated!!", log.Fields{
169 "device-id": aDeviceID})
170 return nil
171 }
172
173 logger.Infow("UniPonAniConfigFsm created", log.Fields{"device-id": aDeviceID})
174 return instFsm
175}
176
177//SetFsmCompleteChannel sets the requested channel and channel result for transfer on success
178func (oFsm *UniPonAniConfigFsm) SetFsmCompleteChannel(aChSuccess chan<- uint8, aProcStep uint8) {
179 oFsm.chSuccess = aChSuccess
180 oFsm.procStep = aProcStep
181 oFsm.chanSet = true
182}
183
184func (oFsm *UniPonAniConfigFsm) enterConfigStartingState(e *fsm.Event) {
185 logger.Debugw("UniPonAniConfigFsm start", log.Fields{"in state": e.FSM.Current(),
186 "device-id": oFsm.pAdaptFsm.deviceID})
187 // in case the used channel is not yet defined (can be re-used after restarts)
188 if oFsm.omciMIdsResponseReceived == nil {
189 oFsm.omciMIdsResponseReceived = make(chan bool)
190 logger.Debug("UniPonAniConfigFsm - OMCI multiInstance RxChannel defined")
191 } else {
192 // as we may 're-use' this instance of FSM and the connected channel
193 // make sure there is no 'lingering' request in the already existing channel:
194 // (simple loop sufficient as we are the only receiver)
195 for len(oFsm.omciMIdsResponseReceived) > 0 {
196 <-oFsm.omciMIdsResponseReceived
197 }
198 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000199 //ensure internal slices are empty (which might be set from previous run) - release memory
200 oFsm.gemPortAttribsSlice = nil
201
mpagenko3dbcdd22020-07-22 07:38:45 +0000202 // start go routine for processing of LockState messages
mpagenkodff5dda2020-08-28 11:52:01 +0000203 go oFsm.processOmciAniMessages()
mpagenko3dbcdd22020-07-22 07:38:45 +0000204
205 //let the state machine run forward from here directly
206 pConfigAniStateAFsm := oFsm.pAdaptFsm
207 if pConfigAniStateAFsm != nil {
208 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
209 go func(a_pAFsm *AdapterFsm) {
210 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
211 //stick to pythonAdapter numbering scheme
212 //index 0 in naming refers to possible usage of multiple instances (later)
213 oFsm.mapperSP0ID = ieeeMapperServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo) + oFsm.techProfileID
214 oFsm.macBPCD0ID = macBridgePortAniEID + uint16(oFsm.pOnuUniPort.entityId) + oFsm.techProfileID
mpagenko3dbcdd22020-07-22 07:38:45 +0000215
Himani Chawla4d908332020-08-31 12:30:20 +0530216 // For the time being: if there are multiple T-Conts on the ONU the first one from the entityID-ordered list is used
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000217 // TODO!: if more T-Conts have to be supported (tcontXID!), then use the first instances of the entity-ordered list
218 // or use the py code approach, which might be a bit more complicated, but also more secure, as it
219 // ensures that the selected T-Cont also has queues (which I would assume per definition from ONU, but who knows ...)
220 // so this approach would search the (sorted) upstream PrioQueue list and use the T-Cont (if available) from highest Bytes
221 // or sndHighByte of relatedPort Attribute (T-Cont Reference) and in case of multiple TConts find the next free TContIndex
222 // that way from PrioQueue.relatedPort list
223 if tcontInstKeys := oFsm.pOnuDB.GetSortedInstKeys(me.TContClassID); len(tcontInstKeys) > 0 {
224 oFsm.tcont0ID = tcontInstKeys[0]
225 logger.Debugw("Used TcontId:", log.Fields{"TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
226 "device-id": oFsm.pAdaptFsm.deviceID})
227 } else {
divyadesai4d299552020-08-18 07:13:49 +0000228 logger.Warnw("No TCont instances found", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000229 }
mpagenkodff5dda2020-08-28 11:52:01 +0000230 oFsm.alloc0ID = (*(oFsm.pUniTechProf.mapPonAniConfig[oFsm.pOnuUniPort.uniId]))[0].tcontParams.allocID
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000231 loGemPortAttribs := ponAniGemPortAttribs{}
232 //for all TechProfile set GemIndices
mpagenkodff5dda2020-08-28 11:52:01 +0000233 for _, gemEntry := range (*(oFsm.pUniTechProf.mapPonAniConfig[oFsm.pOnuUniPort.uniId]))[0].mapGemPortParams {
Himani Chawla4d908332020-08-31 12:30:20 +0530234 //collect all GemConfigData in a separate Fsm related slice (needed also to avoid mix-up with unsorted mapPonAniConfig)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000235
236 if queueInstKeys := oFsm.pOnuDB.GetSortedInstKeys(me.PriorityQueueClassID); len(queueInstKeys) > 0 {
237
238 loGemPortAttribs.gemPortID = gemEntry.gemPortID
239 // MibDb usage: upstream PrioQueue.RelatedPort = xxxxyyyy with xxxx=TCont.Entity(incl. slot) and yyyy=prio
240 // i.e.: search PrioQueue list with xxxx=actual T-Cont.Entity,
241 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == yyyy (expect 0..7)
242 usQrelPortMask := uint32((((uint32)(oFsm.tcont0ID)) << 16) + uint32(gemEntry.prioQueueIndex))
243
244 // MibDb usage: downstream PrioQueue.RelatedPort = xxyyzzzz with xx=slot, yy=UniPort and zzzz=prio
245 // i.e.: search PrioQueue list with yy=actual pOnuUniPort.uniId,
246 // from that list use the PrioQueue.Entity with gemEntry.prioQueueIndex == zzzz (expect 0..7)
247 // Note: As we do not maintain any slot numbering, slot number will be excluded from seatch pattern.
248 // Furthermore OMCI Onu port-Id is expected to start with 1 (not 0).
249 dsQrelPortMask := uint32((((uint32)(oFsm.pOnuUniPort.uniId + 1)) << 16) + uint32(gemEntry.prioQueueIndex))
250
251 usQueueFound := false
252 dsQueueFound := false
Himani Chawla4d908332020-08-31 12:30:20 +0530253 for _, mgmtEntityID := range queueInstKeys {
254 if meAttributes := oFsm.pOnuDB.GetMe(me.PriorityQueueClassID, mgmtEntityID); meAttributes != nil {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000255 returnVal := meAttributes["RelatedPort"]
256 if returnVal != nil {
Holger Hildebrandt2ff21f12020-08-13 14:38:02 +0000257 if relatedPort, err := oFsm.pOnuDB.GetUint32Attrib(returnVal); err == nil {
258 if relatedPort == usQrelPortMask {
Himani Chawla4d908332020-08-31 12:30:20 +0530259 loGemPortAttribs.upQueueID = mgmtEntityID
Holger Hildebrandt2ff21f12020-08-13 14:38:02 +0000260 logger.Debugw("UpQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
261 "upQueueID": strconv.FormatInt(int64(loGemPortAttribs.upQueueID), 16), "device-id": oFsm.pAdaptFsm.deviceID})
262 usQueueFound = true
Himani Chawla4d908332020-08-31 12:30:20 +0530263 } else if (relatedPort&0xFFFFFF) == dsQrelPortMask && mgmtEntityID < 0x8000 {
264 loGemPortAttribs.downQueueID = mgmtEntityID
Holger Hildebrandt2ff21f12020-08-13 14:38:02 +0000265 logger.Debugw("DownQueue for GemPort found:", log.Fields{"gemPortID": loGemPortAttribs.gemPortID,
266 "downQueueID": strconv.FormatInt(int64(loGemPortAttribs.downQueueID), 16), "device-id": oFsm.pAdaptFsm.deviceID})
267 dsQueueFound = true
268 }
269 if usQueueFound && dsQueueFound {
270 break
271 }
272 } else {
273 logger.Warnw("Could not convert attribute value", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000274 }
275 } else {
mpagenkodff5dda2020-08-28 11:52:01 +0000276 logger.Warnw("'RelatedPort' not found in meAttributes:", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000277 }
278 } else {
279 logger.Warnw("No attributes available in DB:", log.Fields{"meClassID": me.PriorityQueueClassID,
Himani Chawla4d908332020-08-31 12:30:20 +0530280 "mgmtEntityID": mgmtEntityID, "device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000281 }
282 }
283 } else {
divyadesai4d299552020-08-18 07:13:49 +0000284 logger.Warnw("No PriorityQueue instances found", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000285 }
286 loGemPortAttribs.direction = gemEntry.direction
287 loGemPortAttribs.qosPolicy = gemEntry.queueSchedPolicy
288 loGemPortAttribs.weight = gemEntry.queueWeight
289 loGemPortAttribs.pbitString = gemEntry.pbitString
290
Holger Hildebrandt2ff21f12020-08-13 14:38:02 +0000291 logger.Debugw("prio-related GemPort attributes:", log.Fields{
292 "gemPortID": loGemPortAttribs.gemPortID,
293 "upQueueID": loGemPortAttribs.upQueueID,
294 "downQueueID": loGemPortAttribs.downQueueID,
295 "pbitString": loGemPortAttribs.pbitString,
296 "prioQueueIndex": gemEntry.prioQueueIndex,
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000297 })
298
299 oFsm.gemPortAttribsSlice = append(oFsm.gemPortAttribsSlice, loGemPortAttribs)
300 }
Himani Chawla4d908332020-08-31 12:30:20 +0530301 _ = a_pAFsm.pFsm.Event(aniEvStartConfig)
mpagenko3dbcdd22020-07-22 07:38:45 +0000302 }
303 }(pConfigAniStateAFsm)
304 }
305}
306
307func (oFsm *UniPonAniConfigFsm) enterCreatingDot1PMapper(e *fsm.Event) {
308 logger.Debugw("UniPonAniConfigFsm Tx Create::Dot1PMapper", log.Fields{
309 "EntitytId": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
310 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
311 meInstance := oFsm.pOmciCC.sendCreateDot1PMapper(context.TODO(), ConstDefaultOmciTimeout, true,
312 oFsm.mapperSP0ID, oFsm.pAdaptFsm.commChan)
313 //accept also nil as (error) return value for writing to LastTx
314 // - this avoids misinterpretation of new received OMCI messages
315 oFsm.pOmciCC.pLastTxMeInstance = meInstance
316}
317
318func (oFsm *UniPonAniConfigFsm) enterCreatingMBPCD(e *fsm.Event) {
319 logger.Debugw("UniPonAniConfigFsm Tx Create::MBPCD", log.Fields{
320 "EntitytId": strconv.FormatInt(int64(oFsm.macBPCD0ID), 16),
321 "TPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
322 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
323 bridgePtr := macBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.macBpNo) //cmp also omci_cc.go::sendCreateMBServiceProfile
324 meParams := me.ParamData{
325 EntityID: oFsm.macBPCD0ID,
326 Attributes: me.AttributeValueMap{
327 "BridgeIdPointer": bridgePtr,
328 "PortNum": 0xFF, //fixed unique ANI side indication
329 "TpType": 3, //for .1PMapper
330 "TpPointer": oFsm.mapperSP0ID,
331 },
332 }
333 meInstance := oFsm.pOmciCC.sendCreateMBPConfigDataVar(context.TODO(), ConstDefaultOmciTimeout, true,
334 oFsm.pAdaptFsm.commChan, meParams)
335 //accept also nil as (error) return value for writing to LastTx
336 // - this avoids misinterpretation of new received OMCI messages
337 oFsm.pOmciCC.pLastTxMeInstance = meInstance
338
339}
340
341func (oFsm *UniPonAniConfigFsm) enterSettingTconts(e *fsm.Event) {
342 logger.Debugw("UniPonAniConfigFsm Tx Set::Tcont", log.Fields{
343 "EntitytId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
344 "AllocId": strconv.FormatInt(int64(oFsm.alloc0ID), 16),
345 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
346 meParams := me.ParamData{
347 EntityID: oFsm.tcont0ID,
348 Attributes: me.AttributeValueMap{
349 "AllocId": oFsm.alloc0ID,
350 },
351 }
352 meInstance := oFsm.pOmciCC.sendSetTcontVar(context.TODO(), ConstDefaultOmciTimeout, true,
353 oFsm.pAdaptFsm.commChan, meParams)
354 //accept also nil as (error) return value for writing to LastTx
355 // - this avoids misinterpretation of new received OMCI messages
356 oFsm.pOmciCC.pLastTxMeInstance = meInstance
357}
358
359func (oFsm *UniPonAniConfigFsm) enterCreatingGemNCTPs(e *fsm.Event) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000360 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,
Himani Chawla4d908332020-08-31 12:30:20 +0530387 Attributes: make(me.AttributeValueMap),
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
Himani Chawla4d908332020-08-31 12:30:20 +0530414 for index, value := range loPrioGemPortArray {
415 if value != 0 {
416 foundIwPtr = true
417 meAttribute := fmt.Sprintf("InterworkTpPointerForPBitPriority%d", index)
418 logger.Debugf("UniPonAniConfigFsm Set::1pMapper", log.Fields{
419 "IwPtr for Prio%d": strconv.FormatInt(int64(value), 16), "device-id": oFsm.pAdaptFsm.deviceID}, index)
420 meParams.Attributes[meAttribute] = value
421
422 }
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000423 }
Himani Chawla4d908332020-08-31 12:30:20 +0530424
425 if !foundIwPtr {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000426 logger.Errorw("UniPonAniConfigFsm no GemIwPtr found for .1pMapper - abort", log.Fields{
427 "device-id": oFsm.pAdaptFsm.deviceID})
428 //let's reset the state machine in order to release all resources now
429 pConfigAniStateAFsm := oFsm.pAdaptFsm
430 if pConfigAniStateAFsm != nil {
431 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
432 go func(a_pAFsm *AdapterFsm) {
433 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530434 _ = a_pAFsm.pFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000435 }
436 }(pConfigAniStateAFsm)
437 }
438 }
439
mpagenko3dbcdd22020-07-22 07:38:45 +0000440 meInstance := oFsm.pOmciCC.sendSetDot1PMapperVar(context.TODO(), ConstDefaultOmciTimeout, true,
441 oFsm.pAdaptFsm.commChan, meParams)
442 //accept also nil as (error) return value for writing to LastTx
443 // - this avoids misinterpretation of new received OMCI messages
444 oFsm.pOmciCC.pLastTxMeInstance = meInstance
445}
446
447func (oFsm *UniPonAniConfigFsm) enterAniConfigDone(e *fsm.Event) {
448
mpagenko1cc3cb42020-07-27 15:24:38 +0000449 oFsm.aniConfigCompleted = true
mpagenko3dbcdd22020-07-22 07:38:45 +0000450
451 //let's reset the state machine in order to release all resources now
452 pConfigAniStateAFsm := oFsm.pAdaptFsm
453 if pConfigAniStateAFsm != nil {
454 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
455 go func(a_pAFsm *AdapterFsm) {
456 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530457 _ = a_pAFsm.pFsm.Event(aniEvReset)
mpagenko3dbcdd22020-07-22 07:38:45 +0000458 }
459 }(pConfigAniStateAFsm)
460 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000461}
462
463func (oFsm *UniPonAniConfigFsm) enterResettingState(e *fsm.Event) {
464 logger.Debugw("UniPonAniConfigFsm resetting", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000465
mpagenko3dbcdd22020-07-22 07:38:45 +0000466 pConfigAniStateAFsm := oFsm.pAdaptFsm
467 if pConfigAniStateAFsm != nil {
468 // abort running message processing
469 fsmAbortMsg := Message{
470 Type: TestMsg,
471 Data: TestMessage{
472 TestMessageVal: AbortMessageProcessing,
473 },
474 }
475 pConfigAniStateAFsm.commChan <- fsmAbortMsg
476
477 //try to restart the FSM to 'disabled', decouple event transfer
478 go func(a_pAFsm *AdapterFsm) {
479 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530480 _ = a_pAFsm.pFsm.Event(aniEvRestart)
mpagenko3dbcdd22020-07-22 07:38:45 +0000481 }
482 }(pConfigAniStateAFsm)
483 }
484}
485
mpagenko1cc3cb42020-07-27 15:24:38 +0000486func (oFsm *UniPonAniConfigFsm) enterDisabledState(e *fsm.Event) {
487 logger.Debugw("UniPonAniConfigFsm enters disabled state", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
488
489 if oFsm.aniConfigCompleted {
490 logger.Debugw("UniPonAniConfigFsm send dh event notification", log.Fields{
491 "from_State": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
492 //use DeviceHandler event notification directly
493 oFsm.pOmciCC.pBaseDeviceHandler.DeviceProcStatusUpdate(oFsm.requestEvent)
494 oFsm.aniConfigCompleted = false
495 }
mpagenkodff5dda2020-08-28 11:52:01 +0000496 //store that the UNI related techProfile processing is done for the given Profile and Uni
497 oFsm.pUniTechProf.setConfigDone(oFsm.pOnuUniPort.uniId, true)
498 //if techProfile processing is done it must be checked, if some prior/parallel flow configuration is pending
499 go oFsm.pOmciCC.pBaseDeviceHandler.verifyUniVlanConfigRequest(oFsm.pOnuUniPort)
mpagenko1cc3cb42020-07-27 15:24:38 +0000500
501 if oFsm.chanSet {
502 // indicate processing done to the caller
503 logger.Debugw("UniPonAniConfigFsm processingDone on channel", log.Fields{
504 "ProcessingStep": oFsm.procStep, "from_State": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
505 oFsm.chSuccess <- oFsm.procStep
506 oFsm.chanSet = false //reset the internal channel state
507 }
508
509}
510
mpagenkodff5dda2020-08-28 11:52:01 +0000511func (oFsm *UniPonAniConfigFsm) processOmciAniMessages( /*ctx context.Context*/ ) {
mpagenko3dbcdd22020-07-22 07:38:45 +0000512 logger.Debugw("Start UniPonAniConfigFsm Msg processing", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
513loop:
514 for {
mpagenko3dbcdd22020-07-22 07:38:45 +0000515 // case <-ctx.Done():
516 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.pAdaptFsm.deviceID})
517 // break loop
Himani Chawla4d908332020-08-31 12:30:20 +0530518 message, ok := <-oFsm.pAdaptFsm.commChan
519 if !ok {
520 logger.Info("UniPonAniConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
521 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
522 _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset)
523 break loop
524 }
525 logger.Debugw("UniPonAniConfigFsm Rx Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
526
527 switch message.Type {
528 case TestMsg:
529 msg, _ := message.Data.(TestMessage)
530 if msg.TestMessageVal == AbortMessageProcessing {
531 logger.Infow("UniPonAniConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000532 break loop
533 }
Himani Chawla4d908332020-08-31 12:30:20 +0530534 logger.Warnw("UniPonAniConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "MessageVal": msg.TestMessageVal})
535 case OMCI:
536 msg, _ := message.Data.(OmciMessage)
537 oFsm.handleOmciAniConfigMessage(msg)
538 default:
539 logger.Warn("UniPonAniConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID,
540 "message.Type": message.Type})
541 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000542
Himani Chawla4d908332020-08-31 12:30:20 +0530543 }
544 logger.Infow("End UniPonAniConfigFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
545}
546
547func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigCreateResponseMessage(msg OmciMessage) {
548 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse)
549 if msgLayer == nil {
550 logger.Error("Omci Msg layer could not be detected for CreateResponse")
551 return
552 }
553 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
554 if !msgOk {
555 logger.Error("Omci Msg layer could not be assigned for CreateResponse")
556 return
557 }
558 logger.Debugw("CreateResponse Data", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj})
559 if msgObj.Result != me.Success {
560 logger.Errorw("Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result})
561 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
562 return
563 }
564 if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() &&
565 msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() {
566 // maybe we can use just the same eventName for different state transitions like "forward"
567 // - might be checked, but so far I go for sure and have to inspect the concrete state events ...
568 switch oFsm.pOmciCC.pLastTxMeInstance.GetName() {
569 case "Ieee8021PMapperServiceProfile":
570 { // let the FSM proceed ...
571 _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxDot1pmapCResp)
572 }
573 case "MacBridgePortConfigurationData":
574 { // let the FSM proceed ...
575 _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxMbpcdResp)
576 }
577 case "GemPortNetworkCtp", "GemInterworkingTerminationPoint":
578 { // let aniConfig Multi-Id processing proceed by stopping the wait function
579 oFsm.omciMIdsResponseReceived <- true
mpagenko3dbcdd22020-07-22 07:38:45 +0000580 }
581 }
582 }
Himani Chawla4d908332020-08-31 12:30:20 +0530583}
584
585func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigSetResponseMessage(msg OmciMessage) {
586 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
587 if msgLayer == nil {
588 logger.Error("UniPonAniConfigFsm - Omci Msg layer could not be detected for SetResponse")
589 return
590 }
591 msgObj, msgOk := msgLayer.(*omci.SetResponse)
592 if !msgOk {
593 logger.Error("UniPonAniConfigFsm - Omci Msg layer could not be assigned for SetResponse")
594 return
595 }
596 logger.Debugw("UniPonAniConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj})
597 if msgObj.Result != me.Success {
598 logger.Errorw("UniPonAniConfigFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result})
599 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
600 return
601 }
602 if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() &&
603 msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() {
604 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
605 // if, then something like:
606 //oFsm.pOnuDB.StoreMe(msgObj)
607
608 switch oFsm.pOmciCC.pLastTxMeInstance.GetName() {
609 case "TCont":
610 { // let the FSM proceed ...
611 _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxTcontsResp)
612 }
613 case "PriorityQueue":
614 { // let the PrioQueue init proceed by stopping the wait function
615 oFsm.omciMIdsResponseReceived <- true
616 }
617 case "Ieee8021PMapperServiceProfile":
618 { // let the FSM proceed ...
619 _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxDot1pmapSResp)
620 }
621 }
622 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000623}
624
625func (oFsm *UniPonAniConfigFsm) handleOmciAniConfigMessage(msg OmciMessage) {
626 logger.Debugw("Rx OMCI UniPonAniConfigFsm Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID,
627 "msgType": msg.OmciMsg.MessageType})
628
629 switch msg.OmciMsg.MessageType {
630 case omci.CreateResponseType:
631 {
Himani Chawla4d908332020-08-31 12:30:20 +0530632 oFsm.handleOmciAniConfigCreateResponseMessage(msg)
633
mpagenko3dbcdd22020-07-22 07:38:45 +0000634 } //CreateResponseType
635 case omci.SetResponseType:
636 {
Himani Chawla4d908332020-08-31 12:30:20 +0530637 oFsm.handleOmciAniConfigSetResponseMessage(msg)
mpagenko3dbcdd22020-07-22 07:38:45 +0000638
mpagenko3dbcdd22020-07-22 07:38:45 +0000639 } //SetResponseType
640 default:
641 {
642 logger.Errorw("UniPonAniConfigFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType})
643 return
644 }
645 }
646}
647
648func (oFsm *UniPonAniConfigFsm) performCreatingGemNCTPs() {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000649 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
650 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
651 logger.Debugw("UniPonAniConfigFsm Tx Create::GemNWCtp", log.Fields{
652 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
653 "TcontId": strconv.FormatInt(int64(oFsm.tcont0ID), 16),
654 "device-id": oFsm.pAdaptFsm.deviceID})
655 meParams := me.ParamData{
656 EntityID: gemPortAttribs.gemPortID, //unique, same as PortId
657 Attributes: me.AttributeValueMap{
658 "PortId": gemPortAttribs.gemPortID,
659 "TContPointer": oFsm.tcont0ID,
660 "Direction": gemPortAttribs.direction,
661 //ONU-G.TrafficManagementOption dependency ->PrioQueue or TCont
662 // TODO!! verify dependency and QueueId in case of Multi-GemPort setup!
663 "TrafficManagementPointerForUpstream": gemPortAttribs.upQueueID, //might be different in wrr-only Setup - tcont0ID
664 "PriorityQueuePointerForDownStream": gemPortAttribs.downQueueID,
665 },
666 }
667 meInstance := oFsm.pOmciCC.sendCreateGemNCTPVar(context.TODO(), ConstDefaultOmciTimeout, true,
668 oFsm.pAdaptFsm.commChan, meParams)
669 //accept also nil as (error) return value for writing to LastTx
670 // - this avoids misinterpretation of new received OMCI messages
671 oFsm.pOmciCC.pLastTxMeInstance = meInstance
mpagenko3dbcdd22020-07-22 07:38:45 +0000672
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000673 //verify response
674 err := oFsm.waitforOmciResponse()
675 if err != nil {
676 logger.Errorw("GemNWCtp create failed, aborting AniConfig FSM!",
divyadesai4d299552020-08-18 07:13:49 +0000677 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "GemIndex": gemIndex})
Himani Chawla4d908332020-08-31 12:30:20 +0530678 _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000679 return
680 }
681 } //for all GemPorts of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +0000682
683 // if Config has been done for all GemPort instances let the FSM proceed
divyadesai4d299552020-08-18 07:13:49 +0000684 logger.Debugw("GemNWCtp create loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530685 _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxGemntcpsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000686}
687
688func (oFsm *UniPonAniConfigFsm) performCreatingGemIWs() {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000689 // for all GemPorts of this T-Cont as given by the size of set gemPortAttribsSlice
690 for gemIndex, gemPortAttribs := range oFsm.gemPortAttribsSlice {
691 logger.Debugw("UniPonAniConfigFsm Tx Create::GemIwTp", log.Fields{
692 "EntitytId": strconv.FormatInt(int64(gemPortAttribs.gemPortID), 16),
693 "SPPtr": strconv.FormatInt(int64(oFsm.mapperSP0ID), 16),
694 "device-id": oFsm.pAdaptFsm.deviceID})
695 meParams := me.ParamData{
696 EntityID: gemPortAttribs.gemPortID,
697 Attributes: me.AttributeValueMap{
698 "GemPortNetworkCtpConnectivityPointer": gemPortAttribs.gemPortID, //same as EntityID, see above
699 "InterworkingOption": 5, //fixed model:: G.998 .1pMapper
700 "ServiceProfilePointer": oFsm.mapperSP0ID,
701 "InterworkingTerminationPointPointer": 0, //not used with .1PMapper Mac bridge
702 "GalProfilePointer": galEthernetEID,
703 },
704 }
705 meInstance := oFsm.pOmciCC.sendCreateGemIWTPVar(context.TODO(), ConstDefaultOmciTimeout, true,
706 oFsm.pAdaptFsm.commChan, meParams)
707 //accept also nil as (error) return value for writing to LastTx
708 // - this avoids misinterpretation of new received OMCI messages
709 oFsm.pOmciCC.pLastTxMeInstance = meInstance
mpagenko3dbcdd22020-07-22 07:38:45 +0000710
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000711 //verify response
712 err := oFsm.waitforOmciResponse()
713 if err != nil {
714 logger.Errorw("GemIwTp create failed, aborting AniConfig FSM!",
divyadesai4d299552020-08-18 07:13:49 +0000715 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "GemIndex": gemIndex})
Himani Chawla4d908332020-08-31 12:30:20 +0530716 _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000717 return
718 }
719 } //for all GemPort's of this T-Cont
mpagenko3dbcdd22020-07-22 07:38:45 +0000720
721 // if Config has been done for all GemPort instances let the FSM proceed
divyadesai4d299552020-08-18 07:13:49 +0000722 logger.Debugw("GemIwTp create loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530723 _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxGemiwsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000724}
725
726func (oFsm *UniPonAniConfigFsm) performSettingPQs() {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000727 const cu16StrictPrioWeight uint16 = 0xFFFF
728 //find all upstream PrioQueues related to this T-Cont
729 loQueueMap := ordered_map.NewOrderedMap()
730 for _, gemPortAttribs := range oFsm.gemPortAttribsSlice {
731 if gemPortAttribs.qosPolicy == "WRR" {
Himani Chawla4d908332020-08-31 12:30:20 +0530732 if _, ok := loQueueMap.Get(gemPortAttribs.upQueueID); !ok {
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000733 //key does not yet exist
734 loQueueMap.Set(gemPortAttribs.upQueueID, uint16(gemPortAttribs.weight))
735 }
736 } else {
737 loQueueMap.Set(gemPortAttribs.upQueueID, cu16StrictPrioWeight) //use invalid weight value to indicate SP
738 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000739 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000740
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000741 //TODO: assumption here is that ONU data uses SP setting in the T-Cont and WRR in the TrafficScheduler
742 // if that is not the case, the reverse case could be checked and reacted accordingly or if the
743 // complete chain is not valid, then some error should be thrown and configuration can be aborted
744 // or even be finished without correct SP/WRR setting
745
746 //TODO: search for the (WRR)trafficScheduler related to the T-Cont of this queue
747 //By now assume fixed value 0x8000, which is the only announce BBSIM TrafficScheduler,
748 // even though its T-Cont seems to be wrong ...
749 loTrafficSchedulerEID := 0x8000
750 //for all found queues
751 iter := loQueueMap.IterFunc()
752 for kv, ok := iter(); ok; kv, ok = iter() {
753 queueIndex := (kv.Key).(uint16)
754 meParams := me.ParamData{
755 EntityID: queueIndex,
Himani Chawla4d908332020-08-31 12:30:20 +0530756 Attributes: make(me.AttributeValueMap),
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000757 }
758 if (kv.Value).(uint16) == cu16StrictPrioWeight {
759 //StrictPrio indication
760 logger.Debugw("UniPonAniConfigFsm Tx Set::PrioQueue to StrictPrio", log.Fields{
761 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
762 "device-id": oFsm.pAdaptFsm.deviceID})
763 meParams.Attributes["TrafficSchedulerPointer"] = 0 //ensure T-Cont defined StrictPrio scheduling
764 } else {
765 //WRR indication
766 logger.Debugw("UniPonAniConfigFsm Tx Set::PrioQueue to WRR", log.Fields{
767 "EntitytId": strconv.FormatInt(int64(queueIndex), 16),
768 "Weight": kv.Value,
769 "device-id": oFsm.pAdaptFsm.deviceID})
770 meParams.Attributes["TrafficSchedulerPointer"] = loTrafficSchedulerEID //ensure assignment of the relevant trafficScheduler
771 meParams.Attributes["Weight"] = uint8(kv.Value.(uint16))
772 }
773 meInstance := oFsm.pOmciCC.sendSetPrioQueueVar(context.TODO(), ConstDefaultOmciTimeout, true,
774 oFsm.pAdaptFsm.commChan, meParams)
775 //accept also nil as (error) return value for writing to LastTx
776 // - this avoids misinterpretation of new received OMCI messages
777 oFsm.pOmciCC.pLastTxMeInstance = meInstance
778
779 //verify response
780 err := oFsm.waitforOmciResponse()
781 if err != nil {
782 logger.Errorw("PrioQueue set failed, aborting AniConfig FSM!",
divyadesai4d299552020-08-18 07:13:49 +0000783 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "QueueId": strconv.FormatInt(int64(queueIndex), 16)})
Himani Chawla4d908332020-08-31 12:30:20 +0530784 _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000785 return
786 }
787
788 //TODO: In case of WRR setting of the GemPort/PrioQueue it might further be necessary to
789 // write the assigned trafficScheduler with the requested Prio to be considered in the StrictPrio scheduling
790 // of the (next upstream) assigned T-Cont, which is f(prioQueue[priority]) - in relation to other SP prioQueues
791 // not yet done because of BBSIM TrafficScheduler issues (and not done in py code as well)
792
793 } //for all upstream prioQueues
mpagenko3dbcdd22020-07-22 07:38:45 +0000794
795 // if Config has been done for all PrioQueue instances let the FSM proceed
divyadesai4d299552020-08-18 07:13:49 +0000796 logger.Debugw("PrioQueue set loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530797 _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxPrioqsResp)
mpagenko3dbcdd22020-07-22 07:38:45 +0000798}
799
800func (oFsm *UniPonAniConfigFsm) waitforOmciResponse() error {
801 select {
Himani Chawla4d908332020-08-31 12:30:20 +0530802 // maybe be also some outside cancel (but no context modeled for the moment ...)
mpagenko3dbcdd22020-07-22 07:38:45 +0000803 // case <-ctx.Done():
804 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
805 case <-time.After(30 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
806 logger.Warnw("UniPonAniConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530807 return errors.New("uniPonAniConfigFsm multi entity timeout")
mpagenko3dbcdd22020-07-22 07:38:45 +0000808 case success := <-oFsm.omciMIdsResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +0530809 if success {
mpagenko3dbcdd22020-07-22 07:38:45 +0000810 logger.Debug("UniPonAniConfigFsm multi entity response received")
811 return nil
812 }
813 // should not happen so far
814 logger.Warnw("UniPonAniConfigFsm multi entity response error", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530815 return errors.New("uniPonAniConfigFsm multi entity responseError")
mpagenko3dbcdd22020-07-22 07:38:45 +0000816 }
817}