mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 1 | /* |
| 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 |
| 18 | package adaptercoreonu |
| 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "errors" |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 23 | "fmt" |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 24 | "strconv" |
| 25 | "time" |
| 26 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 27 | "github.com/cevaris/ordered_map" |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 28 | "github.com/looplab/fsm" |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 29 | "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 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 37 | const ( |
| 38 | // events of config PON ANI port FSM |
| 39 | aniEvStart = "uniEvStart" |
| 40 | aniEvStartConfig = "aniEvStartConfig" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 41 | aniEvRxDot1pmapCResp = "aniEvRxDot1pmapCResp" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 42 | aniEvRxMbpcdResp = "aniEvRxMbpcdResp" |
| 43 | aniEvRxTcontsResp = "aniEvRxTcontsResp" |
| 44 | aniEvRxGemntcpsResp = "aniEvRxGemntcpsResp" |
| 45 | aniEvRxGemiwsResp = "aniEvRxGemiwsResp" |
| 46 | aniEvRxPrioqsResp = "aniEvRxPrioqsResp" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 47 | aniEvRxDot1pmapSResp = "aniEvRxDot1pmapSResp" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 48 | aniEvTimeoutSimple = "aniEvTimeoutSimple" |
| 49 | aniEvTimeoutMids = "aniEvTimeoutMids" |
| 50 | aniEvReset = "aniEvReset" |
| 51 | aniEvRestart = "aniEvRestart" |
| 52 | ) |
| 53 | const ( |
| 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 Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 68 | type 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 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 78 | //UniPonAniConfigFsm defines the structure for the state machine to config the PON ANI ports of ONU UNI ports via OMCI |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 79 | type UniPonAniConfigFsm struct { |
| 80 | pOmciCC *OmciCC |
| 81 | pOnuUniPort *OnuUniPort |
| 82 | pUniTechProf *OnuUniTechProf |
| 83 | pOnuDB *OnuDeviceDB |
| 84 | techProfileID uint16 |
| 85 | requestEvent OnuDeviceEvent |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 86 | omciMIdsResponseReceived chan bool //separate channel needed for checking multiInstance OMCI message responses |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 87 | pAdaptFsm *AdapterFsm |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 88 | aniConfigCompleted bool |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 89 | chSuccess chan<- uint8 |
| 90 | procStep uint8 |
| 91 | chanSet bool |
| 92 | mapperSP0ID uint16 |
| 93 | macBPCD0ID uint16 |
| 94 | tcont0ID uint16 |
| 95 | alloc0ID uint16 |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 96 | gemPortAttribsSlice []ponAniGemPortAttribs |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 97 | } |
| 98 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 99 | //NewUniPonAniConfigFsm is the 'constructor' for the state machine to config the PON ANI ports of ONU UNI ports via OMCI |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 100 | func 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{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 104 | pOmciCC: apDevOmciCC, |
| 105 | pOnuUniPort: apUniPort, |
| 106 | pUniTechProf: apUniTechProf, |
| 107 | pOnuDB: apOnuDB, |
| 108 | techProfileID: aTechProfileID, |
| 109 | requestEvent: aRequestEvent, |
| 110 | aniConfigCompleted: false, |
| 111 | chanSet: false, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 112 | } |
| 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( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 121 | aniStDisabled, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 122 | fsm.Events{ |
| 123 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 124 | {Name: aniEvStart, Src: []string{aniStDisabled}, Dst: aniStStarting}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 125 | |
| 126 | //Note: .1p-Mapper and MBPCD might also have multi instances (per T-Cont) - by now only one 1 T-Cont considered! |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 127 | {Name: aniEvStartConfig, Src: []string{aniStStarting}, Dst: aniStCreatingDot1PMapper}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 128 | {Name: aniEvRxDot1pmapCResp, Src: []string{aniStCreatingDot1PMapper}, Dst: aniStCreatingMBPCD}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 129 | {Name: aniEvRxMbpcdResp, Src: []string{aniStCreatingMBPCD}, Dst: aniStSettingTconts}, |
| 130 | {Name: aniEvRxTcontsResp, Src: []string{aniStSettingTconts}, Dst: aniStCreatingGemNCTPs}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 131 | // the creatingGemNCTPs state is used for multi ME config if required for all configured/available GemPorts |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 132 | {Name: aniEvRxGemntcpsResp, Src: []string{aniStCreatingGemNCTPs}, Dst: aniStCreatingGemIWs}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 133 | // the creatingGemIWs state is used for multi ME config if required for all configured/available GemPorts |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 134 | {Name: aniEvRxGemiwsResp, Src: []string{aniStCreatingGemIWs}, Dst: aniStSettingPQs}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 135 | // the settingPQs state is used for multi ME config if required for all configured/available upstream PriorityQueues |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 136 | {Name: aniEvRxPrioqsResp, Src: []string{aniStSettingPQs}, Dst: aniStSettingDot1PMapper}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 137 | {Name: aniEvRxDot1pmapSResp, Src: []string{aniStSettingDot1PMapper}, Dst: aniStConfigDone}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 138 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 139 | {Name: aniEvTimeoutSimple, Src: []string{ |
| 140 | aniStCreatingDot1PMapper, aniStCreatingMBPCD, aniStSettingTconts, aniStSettingDot1PMapper}, Dst: aniStStarting}, |
| 141 | {Name: aniEvTimeoutMids, Src: []string{ |
| 142 | aniStCreatingGemNCTPs, aniStCreatingGemIWs, aniStSettingPQs}, Dst: aniStStarting}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 143 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 144 | // 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}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 148 | // the only way to get to resource-cleared disabled state again is via "resseting" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 149 | {Name: aniEvRestart, Src: []string{aniStResetting}, Dst: aniStDisabled}, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 150 | }, |
| 151 | |
| 152 | fsm.Callbacks{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 153 | "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) }, |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 165 | }, |
| 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 |
| 178 | func (oFsm *UniPonAniConfigFsm) SetFsmCompleteChannel(aChSuccess chan<- uint8, aProcStep uint8) { |
| 179 | oFsm.chSuccess = aChSuccess |
| 180 | oFsm.procStep = aProcStep |
| 181 | oFsm.chanSet = true |
| 182 | } |
| 183 | |
| 184 | func (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 Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 199 | //ensure internal slices are empty (which might be set from previous run) - release memory |
| 200 | oFsm.gemPortAttribsSlice = nil |
| 201 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 202 | // start go routine for processing of LockState messages |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 203 | go oFsm.processOmciAniMessages() |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 204 | |
| 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 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 215 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 216 | // For the time being: if there are multiple T-Conts on the ONU the first one from the entityID-ordered list is used |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 217 | // 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 { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 228 | logger.Warnw("No TCont instances found", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 229 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 230 | oFsm.alloc0ID = (*(oFsm.pUniTechProf.mapPonAniConfig[oFsm.pOnuUniPort.uniId]))[0].tcontParams.allocID |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 231 | loGemPortAttribs := ponAniGemPortAttribs{} |
| 232 | //for all TechProfile set GemIndices |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 233 | for _, gemEntry := range (*(oFsm.pUniTechProf.mapPonAniConfig[oFsm.pOnuUniPort.uniId]))[0].mapGemPortParams { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 234 | //collect all GemConfigData in a separate Fsm related slice (needed also to avoid mix-up with unsorted mapPonAniConfig) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 235 | |
| 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 Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 253 | for _, mgmtEntityID := range queueInstKeys { |
| 254 | if meAttributes := oFsm.pOnuDB.GetMe(me.PriorityQueueClassID, mgmtEntityID); meAttributes != nil { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 255 | returnVal := meAttributes["RelatedPort"] |
| 256 | if returnVal != nil { |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 257 | if relatedPort, err := oFsm.pOnuDB.GetUint32Attrib(returnVal); err == nil { |
| 258 | if relatedPort == usQrelPortMask { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 259 | loGemPortAttribs.upQueueID = mgmtEntityID |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 260 | 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 Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 263 | } else if (relatedPort&0xFFFFFF) == dsQrelPortMask && mgmtEntityID < 0x8000 { |
| 264 | loGemPortAttribs.downQueueID = mgmtEntityID |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 265 | 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 Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 274 | } |
| 275 | } else { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 276 | logger.Warnw("'RelatedPort' not found in meAttributes:", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 277 | } |
| 278 | } else { |
| 279 | logger.Warnw("No attributes available in DB:", log.Fields{"meClassID": me.PriorityQueueClassID, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 280 | "mgmtEntityID": mgmtEntityID, "device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | } else { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 284 | logger.Warnw("No PriorityQueue instances found", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 285 | } |
| 286 | loGemPortAttribs.direction = gemEntry.direction |
| 287 | loGemPortAttribs.qosPolicy = gemEntry.queueSchedPolicy |
| 288 | loGemPortAttribs.weight = gemEntry.queueWeight |
| 289 | loGemPortAttribs.pbitString = gemEntry.pbitString |
| 290 | |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 291 | 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 Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 297 | }) |
| 298 | |
| 299 | oFsm.gemPortAttribsSlice = append(oFsm.gemPortAttribsSlice, loGemPortAttribs) |
| 300 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 301 | _ = a_pAFsm.pFsm.Event(aniEvStartConfig) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 302 | } |
| 303 | }(pConfigAniStateAFsm) |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | func (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 | |
| 318 | func (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 | |
| 341 | func (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 | |
| 359 | func (oFsm *UniPonAniConfigFsm) enterCreatingGemNCTPs(e *fsm.Event) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 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 | |
| 365 | func (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 | |
| 371 | func (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 | |
| 377 | func (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 Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 381 | 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 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 385 | meParams := me.ParamData{ |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 386 | EntityID: oFsm.mapperSP0ID, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 387 | Attributes: make(me.AttributeValueMap), |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 388 | } |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 389 | |
| 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 Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 414 | 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 Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 423 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 424 | |
| 425 | if !foundIwPtr { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 426 | 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 Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 434 | _ = a_pAFsm.pFsm.Event(aniEvReset) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 435 | } |
| 436 | }(pConfigAniStateAFsm) |
| 437 | } |
| 438 | } |
| 439 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 440 | 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 | |
| 447 | func (oFsm *UniPonAniConfigFsm) enterAniConfigDone(e *fsm.Event) { |
| 448 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 449 | oFsm.aniConfigCompleted = true |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 450 | |
| 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 Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 457 | _ = a_pAFsm.pFsm.Event(aniEvReset) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 458 | } |
| 459 | }(pConfigAniStateAFsm) |
| 460 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | func (oFsm *UniPonAniConfigFsm) enterResettingState(e *fsm.Event) { |
| 464 | logger.Debugw("UniPonAniConfigFsm resetting", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 465 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 466 | 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 Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 480 | _ = a_pAFsm.pFsm.Event(aniEvRestart) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 481 | } |
| 482 | }(pConfigAniStateAFsm) |
| 483 | } |
| 484 | } |
| 485 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 486 | func (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 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 496 | //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) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 500 | |
| 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 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 511 | func (oFsm *UniPonAniConfigFsm) processOmciAniMessages( /*ctx context.Context*/ ) { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 512 | logger.Debugw("Start UniPonAniConfigFsm Msg processing", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
| 513 | loop: |
| 514 | for { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 515 | // 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 Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 518 | 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}) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 532 | break loop |
| 533 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 534 | 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 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 542 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 543 | } |
| 544 | logger.Infow("End UniPonAniConfigFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 545 | } |
| 546 | |
| 547 | func (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 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 583 | } |
| 584 | |
| 585 | func (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 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | func (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 Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 632 | oFsm.handleOmciAniConfigCreateResponseMessage(msg) |
| 633 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 634 | } //CreateResponseType |
| 635 | case omci.SetResponseType: |
| 636 | { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 637 | oFsm.handleOmciAniConfigSetResponseMessage(msg) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 638 | |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 639 | } //SetResponseType |
| 640 | default: |
| 641 | { |
| 642 | logger.Errorw("UniPonAniConfigFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType}) |
| 643 | return |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | func (oFsm *UniPonAniConfigFsm) performCreatingGemNCTPs() { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 649 | // 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 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 672 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 673 | //verify response |
| 674 | err := oFsm.waitforOmciResponse() |
| 675 | if err != nil { |
| 676 | logger.Errorw("GemNWCtp create failed, aborting AniConfig FSM!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 677 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "GemIndex": gemIndex}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 678 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 679 | return |
| 680 | } |
| 681 | } //for all GemPorts of this T-Cont |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 682 | |
| 683 | // if Config has been done for all GemPort instances let the FSM proceed |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 684 | logger.Debugw("GemNWCtp create loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 685 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxGemntcpsResp) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | func (oFsm *UniPonAniConfigFsm) performCreatingGemIWs() { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 689 | // 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 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 710 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 711 | //verify response |
| 712 | err := oFsm.waitforOmciResponse() |
| 713 | if err != nil { |
| 714 | logger.Errorw("GemIwTp create failed, aborting AniConfig FSM!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 715 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "GemIndex": gemIndex}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 716 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 717 | return |
| 718 | } |
| 719 | } //for all GemPort's of this T-Cont |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 720 | |
| 721 | // if Config has been done for all GemPort instances let the FSM proceed |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 722 | logger.Debugw("GemIwTp create loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 723 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxGemiwsResp) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | func (oFsm *UniPonAniConfigFsm) performSettingPQs() { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 727 | 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 Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 732 | if _, ok := loQueueMap.Get(gemPortAttribs.upQueueID); !ok { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 733 | //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 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 739 | } |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 740 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 741 | //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 Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 756 | Attributes: make(me.AttributeValueMap), |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 757 | } |
| 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!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 783 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "QueueId": strconv.FormatInt(int64(queueIndex), 16)}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 784 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvReset) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 785 | 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 |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 794 | |
| 795 | // if Config has been done for all PrioQueue instances let the FSM proceed |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 796 | logger.Debugw("PrioQueue set loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 797 | _ = oFsm.pAdaptFsm.pFsm.Event(aniEvRxPrioqsResp) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | func (oFsm *UniPonAniConfigFsm) waitforOmciResponse() error { |
| 801 | select { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 802 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 803 | // 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 Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 807 | return errors.New("uniPonAniConfigFsm multi entity timeout") |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 808 | case success := <-oFsm.omciMIdsResponseReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 809 | if success { |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 810 | 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 Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame^] | 815 | return errors.New("uniPonAniConfigFsm multi entity responseError") |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 816 | } |
| 817 | } |