blob: 45aa197f08642cb4e78f21a7a9bd828af2a04163 [file] [log] [blame]
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +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"
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000022 "encoding/hex"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000023 "encoding/json"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000024 "errors"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000025 "fmt"
26 "strconv"
mpagenko3af1f032020-06-10 08:53:41 +000027 "strings"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000028
29 "github.com/looplab/fsm"
30
31 //"sync"
divyadesaibbed37c2020-08-28 13:35:20 +053032 "time"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000033
34 //"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
35 "github.com/opencord/omci-lib-go"
36 me "github.com/opencord/omci-lib-go/generated"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000037 "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000038 "github.com/opencord/voltha-lib-go/v3/pkg/log"
39 //ic "github.com/opencord/voltha-protos/v3/go/inter_container"
40 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
41 //"github.com/opencord/voltha-protos/v3/go/voltha"
42)
43
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000044var supportedClassIds = []me.ClassID{
45 me.CardholderClassID, // 5
46 me.CircuitPackClassID, // 6
47 me.SoftwareImageClassID, // 7
48 me.PhysicalPathTerminationPointEthernetUniClassID, // 11
49 me.OltGClassID, // 131
50 me.OnuPowerSheddingClassID, // 133
51 me.IpHostConfigDataClassID, // 134
52 me.OnuGClassID, // 256
53 me.Onu2GClassID, // 257
54 me.TContClassID, // 262
55 me.AniGClassID, // 263
56 me.UniGClassID, // 264
57 me.PriorityQueueClassID, // 277
58 me.TrafficSchedulerClassID, // 278
59 me.VirtualEthernetInterfacePointClassID, // 329
60 me.EnhancedSecurityControlClassID, // 332
61 me.OnuDynamicPowerManagementControlClassID, // 336
62 // 347 // definitions for ME "IPv6 host config data" are currently missing in omci-lib-go!
63}
64
65var fsmMsg TestMessageType
66
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000067func (onuDeviceEntry *OnuDeviceEntry) enterStartingState(e *fsm.Event) {
68 logger.Debugw("MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt24d51952020-05-04 14:03:42 +000069 onuDeviceEntry.pOnuDB = NewOnuDeviceDB(context.TODO(), onuDeviceEntry)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000070 go onuDeviceEntry.ProcessMibSyncMessages()
71}
72
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000073func (onuDeviceEntry *OnuDeviceEntry) enterResettingMibState(e *fsm.Event) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000074 logger.Debugw("MibSync FSM", log.Fields{"Start MibTemplate processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000075
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000076 logger.Debugw("MibSync FSM", log.Fields{"send mibReset in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +053077 _ = onuDeviceEntry.PDevOmciCC.sendMibReset(context.TODO(), ConstDefaultOmciTimeout, true)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000078
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000079 //TODO: needs to handle timeouts
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000080}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000081
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000082func (onuDeviceEntry *OnuDeviceEntry) enterGettingVendorAndSerialState(e *fsm.Event) {
83 logger.Debugw("MibSync FSM", log.Fields{"Start getting VendorId and SerialNumber in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
84 requestedAttributes := me.AttributeValueMap{"VendorId": "", "SerialNumber": 0}
Himani Chawla4d908332020-08-31 12:30:20 +053085 meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.OnuGClassID, OnugMeID, requestedAttributes, ConstDefaultOmciTimeout, true)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000086 //accept also nil as (error) return value for writing to LastTx
87 // - this avoids misinterpretation of new received OMCI messages
88 onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance
89}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000090
Himani Chawla4d908332020-08-31 12:30:20 +053091func (onuDeviceEntry *OnuDeviceEntry) enterGettingEquipmentIDState(e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000092 logger.Debugw("MibSync FSM", log.Fields{"Start getting EquipmentId in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
93 requestedAttributes := me.AttributeValueMap{"EquipmentId": ""}
Himani Chawla4d908332020-08-31 12:30:20 +053094 meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.Onu2GClassID, Onu2gMeID, requestedAttributes, ConstDefaultOmciTimeout, true)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000095 //accept also nil as (error) return value for writing to LastTx
96 // - this avoids misinterpretation of new received OMCI messages
97 onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance
98}
99
100func (onuDeviceEntry *OnuDeviceEntry) enterGettingFirstSwVersionState(e *fsm.Event) {
101 logger.Debugw("MibSync FSM", log.Fields{"Start getting IsActive and Version of first SW-image in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
102 requestedAttributes := me.AttributeValueMap{"IsActive": 0, "Version": ""}
Himani Chawla4d908332020-08-31 12:30:20 +0530103 meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.SoftwareImageClassID, FirstSwImageMeID, requestedAttributes, ConstDefaultOmciTimeout, true)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000104 //accept also nil as (error) return value for writing to LastTx
105 // - this avoids misinterpretation of new received OMCI messages
106 onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance
107}
108
109func (onuDeviceEntry *OnuDeviceEntry) enterGettingSecondSwVersionState(e *fsm.Event) {
110 logger.Debugw("MibSync FSM", log.Fields{"Start getting IsActive and Version of second SW-image in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
111 requestedAttributes := me.AttributeValueMap{"IsActive": 0, "Version": ""}
Himani Chawla4d908332020-08-31 12:30:20 +0530112 meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.SoftwareImageClassID, SecondSwImageMeID, requestedAttributes, ConstDefaultOmciTimeout, true)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000113 //accept also nil as (error) return value for writing to LastTx
114 // - this avoids misinterpretation of new received OMCI messages
115 onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance
116}
117
118func (onuDeviceEntry *OnuDeviceEntry) enterGettingMacAddressState(e *fsm.Event) {
119 logger.Debugw("MibSync FSM", log.Fields{"Start getting MacAddress in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
120 requestedAttributes := me.AttributeValueMap{"MacAddress": ""}
Himani Chawla4d908332020-08-31 12:30:20 +0530121 meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.IpHostConfigDataClassID, IPHostConfigDataMeID, requestedAttributes, ConstDefaultOmciTimeout, true)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000122 //accept also nil as (error) return value for writing to LastTx
123 // - this avoids misinterpretation of new received OMCI messages
124 onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance
125}
126
127func (onuDeviceEntry *OnuDeviceEntry) enterGettingMibTemplate(e *fsm.Event) {
128
Himani Chawla4d908332020-08-31 12:30:20 +0530129 for i := FirstSwImageMeID; i <= SecondSwImageMeID; i++ {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000130 if onuDeviceEntry.swImages[i].isActive > 0 {
131 onuDeviceEntry.activeSwVersion = onuDeviceEntry.swImages[i].version
132 }
133 }
134
135 meStoredFromTemplate := false
mpagenkoaf801632020-07-03 10:00:42 +0000136 path := fmt.Sprintf(cSuffixMibTemplateKvStore, onuDeviceEntry.vendorID, onuDeviceEntry.equipmentID, onuDeviceEntry.activeSwVersion)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000137 logger.Debugw("MibSync FSM - MibTemplate - etcd search string", log.Fields{"path": path})
138 Value, err := onuDeviceEntry.mibTemplateKVStore.Get(context.TODO(), path)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000139 if err == nil {
140 if Value != nil {
141 logger.Debugf("MibSync FSM - MibTemplate read: Key: %s, Value: %s %s", Value.Key, Value.Value)
mpagenko3af1f032020-06-10 08:53:41 +0000142
143 // swap out tokens with specific data
144 mibTmpString, _ := kvstore.ToString(Value.Value)
145 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", onuDeviceEntry.serialNumber, -1)
146 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", onuDeviceEntry.macAddress, -1)
147 mibTmpBytes := []byte(mibTmpString)
148 logger.Debugf("MibSync FSM - MibTemplate tokens swapped out: %s", mibTmpBytes)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000149
150 var fistLevelMap map[string]interface{}
151 if err = json.Unmarshal(mibTmpBytes, &fistLevelMap); err != nil {
152 logger.Error("MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": onuDeviceEntry.deviceID})
153 } else {
154 for fistLevelKey, firstLevelValue := range fistLevelMap {
155 logger.Debugw("MibSync FSM - fistLevelKey", log.Fields{"fistLevelKey": fistLevelKey})
156 if uint16ValidNumber, err := strconv.ParseUint(fistLevelKey, 10, 16); err == nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530157 meClassID := me.ClassID(uint16ValidNumber)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000158 logger.Debugw("MibSync FSM - fistLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
Himani Chawla4d908332020-08-31 12:30:20 +0530159 if IsSupportedClassId(meClassID) {
160 logger.Debugw("MibSync FSM - fistLevelKey is a supported classId", log.Fields{"meClassID": meClassID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000161 secondLevelMap := firstLevelValue.(map[string]interface{})
162 for secondLevelKey, secondLevelValue := range secondLevelMap {
163 logger.Debugw("MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
164 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530165 meEntityID := uint16(uint16ValidNumber)
166 logger.Debugw("MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000167 thirdLevelMap := secondLevelValue.(map[string]interface{})
168 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
Himani Chawla4d908332020-08-31 12:30:20 +0530169 if thirdLevelKey == "attributes" {
170 logger.Debugw("MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000171 attributesMap := thirdLevelValue.(map[string]interface{})
172 logger.Debugw("MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
Himani Chawla4d908332020-08-31 12:30:20 +0530173 onuDeviceEntry.pOnuDB.PutMe(meClassID, meEntityID, attributesMap)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000174 meStoredFromTemplate = true
175 }
176 }
177 }
178 }
179 }
180 }
181 }
182 }
183 } else {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000184 logger.Debugw("No MIB template found", log.Fields{"path": path, "device-id": onuDeviceEntry.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000185 }
186 } else {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000187 logger.Errorf("Get from kvstore operation failed for path %s", path)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000188 }
189 if meStoredFromTemplate {
190 logger.Debug("MibSync FSM - valid MEs stored from template")
191 onuDeviceEntry.pOnuDB.LogMeDb()
192 fsmMsg = LoadMibTemplateOk
193 } else {
194 logger.Debug("MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
195 fsmMsg = LoadMibTemplateFailed
196 }
197
198 mibSyncMsg := Message{
199 Type: TestMsg,
200 Data: TestMessage{
201 TestMessageVal: fsmMsg,
202 },
203 }
204 onuDeviceEntry.pMibUploadFsm.commChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000205}
206
207func (onuDeviceEntry *OnuDeviceEntry) enterUploadingState(e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000208 logger.Debugw("MibSync FSM", log.Fields{"send MibUpload in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530209 _ = onuDeviceEntry.PDevOmciCC.sendMibUpload(context.TODO(), ConstDefaultOmciTimeout, true)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000210}
211
212func (onuDeviceEntry *OnuDeviceEntry) enterInSyncState(e *fsm.Event) {
213 logger.Debugw("MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
214 onuDeviceEntry.transferSystemEvent(MibDatabaseSync)
215}
216
217func (onuDeviceEntry *OnuDeviceEntry) enterExaminingMdsState(e *fsm.Event) {
218 logger.Debugw("MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
219 logger.Debug("function not implemented yet")
220}
221
222func (onuDeviceEntry *OnuDeviceEntry) enterResynchronizingState(e *fsm.Event) {
223 logger.Debugw("MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
224 logger.Debug("function not implemented yet")
225}
226
227func (onuDeviceEntry *OnuDeviceEntry) enterAuditingState(e *fsm.Event) {
228 logger.Debugw("MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
229 logger.Debug("function not implemented yet")
230}
231
232func (onuDeviceEntry *OnuDeviceEntry) enterOutOfSyncState(e *fsm.Event) {
233 logger.Debugw("MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
234 logger.Debug("function not implemented yet")
235}
236
237func (onuDeviceEntry *OnuDeviceEntry) ProcessMibSyncMessages( /*ctx context.Context*/ ) {
238 logger.Debugw("MibSync Msg", log.Fields{"Start routine to process OMCI-messages for device-id": onuDeviceEntry.deviceID})
239loop:
240 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000241 // case <-ctx.Done():
242 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
243 // break loop
Himani Chawla4d908332020-08-31 12:30:20 +0530244 message, ok := <-onuDeviceEntry.pMibUploadFsm.commChan
245 if !ok {
246 logger.Info("MibSync Msg", log.Fields{"Message couldn't be read from channel for device-id": onuDeviceEntry.deviceID})
247 break loop
248 }
249 logger.Debugw("MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000250
Himani Chawla4d908332020-08-31 12:30:20 +0530251 switch message.Type {
252 case TestMsg:
253 msg, _ := message.Data.(TestMessage)
254 onuDeviceEntry.handleTestMsg(msg)
255 case OMCI:
256 msg, _ := message.Data.(OmciMessage)
257 onuDeviceEntry.handleOmciMessage(msg)
258 default:
259 logger.Warn("MibSync Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID, "message.Type": message.Type})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000260 }
261 }
262 logger.Info("MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": onuDeviceEntry.deviceID})
263 // TODO: only this action?
Himani Chawla4d908332020-08-31 12:30:20 +0530264 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000265}
266
267func (onuDeviceEntry *OnuDeviceEntry) handleTestMsg(msg TestMessage) {
268
269 logger.Debugw("MibSync Msg", log.Fields{"TestMessage received for device-id": onuDeviceEntry.deviceID, "msg.TestMessageVal": msg.TestMessageVal})
270
271 switch msg.TestMessageVal {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000272 case LoadMibTemplateFailed:
Himani Chawla4d908332020-08-31 12:30:20 +0530273 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvUploadMib)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000274 logger.Debugw("MibSync Msg", log.Fields{"state": string(onuDeviceEntry.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000275 case LoadMibTemplateOk:
Himani Chawla4d908332020-08-31 12:30:20 +0530276 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000277 logger.Debugw("MibSync Msg", log.Fields{"state": string(onuDeviceEntry.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000278 default:
279 logger.Warn("MibSync Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID, "msg.TestMessageVal": msg.TestMessageVal})
280 }
281}
282
Himani Chawla4d908332020-08-31 12:30:20 +0530283func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibResetResponseMessage(msg OmciMessage) {
284 if onuDeviceEntry.pMibUploadFsm.pFsm.Is(ulStResettingMib) {
285 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
286 if msgLayer != nil {
287 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
288 if msgOk {
289 logger.Debugw("MibResetResponse Data", log.Fields{"data-fields": msgObj})
290 if msgObj.Result == me.Success {
291 // trigger retrieval of VendorId and SerialNumber
292 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial)
293 return
294 }
295 logger.Errorw("Omci MibResetResponse Error", log.Fields{"Error": msgObj.Result})
296 } else {
297 logger.Error("Omci Msg layer could not be assigned")
298 }
299 } else {
300 logger.Error("Omci Msg layer could not be detected")
301 }
302 } else {
303 logger.Errorw("Omci MibResetResponse received", log.Fields{"in state ": onuDeviceEntry.pMibUploadFsm.pFsm.Current})
304 }
305 logger.Info("MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": onuDeviceEntry.deviceID})
306 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvStop)
307
308}
309
310func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibUploadResponseMessage(msg OmciMessage) {
311 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
312 if msgLayer == nil {
313 logger.Error("Omci Msg layer could not be detected")
314 return
315 }
316 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
317 if !msgOk {
318 logger.Error("Omci Msg layer could not be assigned")
319 return
320 }
321 logger.Debugw("MibUploadResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj})
322 /* to be verified / reworked !!! */
323 onuDeviceEntry.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
324 if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds {
325 _ = onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true)
326 } else {
327 logger.Error("Invalid number of commands received for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "uploadNoOfCmds": onuDeviceEntry.PDevOmciCC.uploadNoOfCmds})
328 //TODO right action?
329 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvTimeout)
330 }
331}
332
333func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(msg OmciMessage) {
334 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
335 if msgLayer == nil {
336 logger.Error("Omci Msg layer could not be detected")
337 return
338 }
339 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
340 if !msgOk {
341 logger.Error("Omci Msg layer could not be assigned")
342 return
343 }
344 if onuDeviceEntry.mibDebugLevel == "VERBOSE" {
345 logger.Debugw("MibUploadNextResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj})
346 }
347 meClassID := msgObj.ReportedME.GetClassID()
348 meEntityID := msgObj.ReportedME.GetEntityID()
349 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
350
351 onuDeviceEntry.pOnuDB.PutMe(meClassID, meEntityID, meAttributes)
352
353 if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds {
354 _ = onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true)
355 } else {
356 onuDeviceEntry.pOnuDB.LogMeDb()
357 err := onuDeviceEntry.CreateAndPersistMibTemplate()
358 if err != nil {
359 logger.Errorw("MibSync - MibTemplate - Failed to create and persist the mib template", log.Fields{"error": err, "device-id": onuDeviceEntry.deviceID})
360 }
361
362 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvSuccess)
363 }
364}
365
366func (onuDeviceEntry *OnuDeviceEntry) handleOmciGetResponseMessage(msg OmciMessage) {
367 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
368 if msgLayer != nil {
369 msgObj, msgOk := msgLayer.(*omci.GetResponse)
370 if msgOk {
371 logger.Debugw("MibSync FSM - GetResponse Data", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj})
372 if msgObj.Result == me.Success {
373 entityID := onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetEntityID()
374 if msgObj.EntityClass == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
375 meAttributes := msgObj.Attributes
376 meInstance := onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName()
377 if onuDeviceEntry.mibDebugLevel == "VERBOSE" {
378 logger.Debugf("MibSync FSM - GetResponse Data for %s", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}, meInstance)
379 }
380 switch meInstance {
381 case "OnuG":
382 onuDeviceEntry.vendorID = fmt.Sprintf("%s", meAttributes["VendorId"])
383 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
384 if OnugSerialNumberLen == len(snBytes) {
385 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
386 snNumberPart := hex.EncodeToString(snBytes[4:])
387 onuDeviceEntry.serialNumber = snVendorPart + snNumberPart
388 logger.Debugw("MibSync FSM - GetResponse Data for Onu-G - VendorId/SerialNumber", log.Fields{"deviceId": onuDeviceEntry.deviceID,
389 "onuDeviceEntry.vendorID": onuDeviceEntry.vendorID, "onuDeviceEntry.serialNumber": onuDeviceEntry.serialNumber})
390 } else {
391 logger.Errorw("MibSync FSM - SerialNumber has wrong length", log.Fields{"deviceId": onuDeviceEntry.deviceID, "length": len(snBytes)})
392 }
393 // trigger retrieval of EquipmentId
394 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID)
395 return
396 case "Onu2G":
397 onuDeviceEntry.equipmentID = fmt.Sprintf("%s", meAttributes["EquipmentId"])
398 logger.Debugw("MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"deviceId": onuDeviceEntry.deviceID,
399 "onuDeviceEntry.equipmentID": onuDeviceEntry.equipmentID})
400 // trigger retrieval of 1st SW-image info
401 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion)
402 return
403 case "SoftwareImage":
404 if entityID <= SecondSwImageMeID {
405 onuDeviceEntry.swImages[entityID].version = fmt.Sprintf("%s", meAttributes["Version"])
406 onuDeviceEntry.swImages[entityID].isActive = meAttributes["IsActive"].(uint8)
407 logger.Debugw("MibSync FSM - GetResponse Data for SoftwareImage - Version/IsActive",
408 log.Fields{"deviceId": onuDeviceEntry.deviceID, "entityID": entityID,
409 "version": onuDeviceEntry.swImages[entityID].version, "isActive": onuDeviceEntry.swImages[entityID].isActive})
410 } else {
411 //TODO: error handling
412 logger.Errorw("MibSync FSM - Failed to GetResponse Data for SoftwareImage", log.Fields{"deviceId": onuDeviceEntry.deviceID})
413
414 }
415 if FirstSwImageMeID == entityID {
416 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion)
417 return
418 } else if SecondSwImageMeID == entityID {
419 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress)
420 return
421 }
422 case "IpHostConfigData":
423 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
424 if OmciMacAddressLen == len(macBytes) {
425 onuDeviceEntry.macAddress = hex.EncodeToString(macBytes[:])
426 logger.Debugw("MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"deviceId": onuDeviceEntry.deviceID,
427 "onuDeviceEntry.macAddress": onuDeviceEntry.macAddress})
428 } else {
429 logger.Errorw("MibSync FSM - MacAddress wrong length", log.Fields{"deviceId": onuDeviceEntry.deviceID, "length": len(macBytes)})
430 }
431 // trigger retrieval of mib template
432 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
433 return
434 }
435 }
436 } else {
437 logger.Errorw("Omci GetResponse Error", log.Fields{"Error": msgObj.Result})
438 }
439 } else {
440 logger.Error("Omci Msg layer could not be assigned for GetResponse")
441 }
442 } else {
443 logger.Error("Omci Msg layer could not be detected for GetResponse")
444 }
445 logger.Info("MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": onuDeviceEntry.deviceID})
446 _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvStop)
447}
448
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000449func (onuDeviceEntry *OnuDeviceEntry) handleOmciMessage(msg OmciMessage) {
mpagenko1cc3cb42020-07-27 15:24:38 +0000450 if onuDeviceEntry.mibDebugLevel == "VERBOSE" {
451 logger.Debugw("MibSync Msg", log.Fields{"OmciMessage received for device-id": onuDeviceEntry.deviceID,
452 "msgType": msg.OmciMsg.MessageType})
453 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000454 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
455 switch msg.OmciMsg.MessageType {
456 case omci.MibResetResponseType:
Himani Chawla4d908332020-08-31 12:30:20 +0530457 onuDeviceEntry.handleOmciMibResetResponseMessage(msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000458
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000459 case omci.MibUploadResponseType:
Himani Chawla4d908332020-08-31 12:30:20 +0530460 onuDeviceEntry.handleOmciMibUploadResponseMessage(msg)
461
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000462 case omci.MibUploadNextResponseType:
Himani Chawla4d908332020-08-31 12:30:20 +0530463 onuDeviceEntry.handleOmciMibUploadNextResponseMessage(msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000464
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000465 case omci.GetResponseType:
Himani Chawla4d908332020-08-31 12:30:20 +0530466 onuDeviceEntry.handleOmciGetResponseMessage(msg)
467
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000468 }
469}
470
Himani Chawla4d908332020-08-31 12:30:20 +0530471func IsSupportedClassId(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000472 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530473 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000474 return true
475 }
476 }
477 return false
478}
479
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000480func (onuDeviceEntry *OnuDeviceEntry) MibDbVolatileDict() error {
481 logger.Debug("MibVolatileDict- running from default Entry code")
482 return errors.New("not_implemented")
483}
484
divyadesaibbed37c2020-08-28 13:35:20 +0530485// CreateAndPersistMibTemplate method creates a mib template for the device id when operator enables the ONU device for the first time.
486// We are creating a placeholder for "SerialNumber" for ME Class ID 6 and 256 and "MacAddress" for ME Class ID 134 in the template
487// and then storing the template into etcd "service/voltha/omci_mibs/templates/verdor_id/equipment_id/software_version" path.
488func (onuDeviceEntry *OnuDeviceEntry) CreateAndPersistMibTemplate() error {
489 path := fmt.Sprintf(cSuffixMibTemplateKvStore, onuDeviceEntry.vendorID, onuDeviceEntry.equipmentID, onuDeviceEntry.activeSwVersion)
490 logger.Debugw("MibSync - MibTemplate - key name", log.Fields{"path": path})
491 currentTime := time.Now()
492
493 templateMap := make(map[string]interface{})
494 templateMap["TemplateName"] = path
495 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
496
497 firstLevelMap := onuDeviceEntry.pOnuDB.meDb
498 for firstLevelKey, firstLevelValue := range firstLevelMap {
499 logger.Debugw("MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
500 classId := strconv.Itoa(int(firstLevelKey))
501
502 secondLevelMap := make(map[string]interface{})
503 for secondLevelKey, secondLevelValue := range firstLevelValue {
504 thirdLevelMap := make(map[string]interface{})
505 entityId := strconv.Itoa(int(secondLevelKey))
506 thirdLevelMap["Attributes"] = secondLevelValue
507 thirdLevelMap["InstanceId"] = entityId
508 secondLevelMap[entityId] = thirdLevelMap
509 if classId == "6" || classId == "256" {
510 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
511 delete(forthLevelMap, "SerialNumber")
512 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
513
514 }
515 if classId == "134" {
516 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
517 delete(forthLevelMap, "MacAddress")
518 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
519 }
520 }
521 secondLevelMap["ClassId"] = classId
522 templateMap[classId] = secondLevelMap
523 }
524 mibTemplate, err := json.Marshal(&templateMap)
525 if err != nil {
526 logger.Errorw("MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": onuDeviceEntry.deviceID})
527 return err
528 }
529 err = onuDeviceEntry.mibTemplateKVStore.Put(context.TODO(), path, string(mibTemplate))
530 if err != nil {
531 logger.Errorw("MibSync - MibTemplate - Failed to store template in etcd", log.Fields{"error": err, "device-id": onuDeviceEntry.deviceID})
532 return err
533 }
534 logger.Debugw("MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": onuDeviceEntry.deviceID})
535 return nil
536}
537
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000538// func (onuDeviceEntry *OnuDeviceEntry) MibTemplateTask() error {
539// return errors.New("not_implemented")
540// }
541// func (onuDeviceEntry *OnuDeviceEntry) MibUploadTask() error {
542// return errors.New("not_implemented")
543// }
544// func (onuDeviceEntry *OnuDeviceEntry) GetMdsTask() error {
545// return errors.New("not_implemented")
546// }
547// func (onuDeviceEntry *OnuDeviceEntry) MibResyncTask() error {
548// return errors.New("not_implemented")
549// }
550// func (onuDeviceEntry *OnuDeviceEntry) MibReconcileTask() error {
551// return errors.New("not_implemented")
552// }